.NET API ClientΒΆ

using System;
using System.Collections.Generic;
using System.Linq;
using Recombee.ApiClient;
using Recombee.ApiClient.ApiRequests;
using Recombee.ApiClient.Bindings;

public class BasicExample
{
    static int Main(string[] args)
    {
         RecombeeClient client = new RecombeeClient("--my-database-id--", "--my-secret-token--");
         try
         {
            const int NUM = 100;
            var userIds = Enumerable.Range(0, NUM).Select(i => String.Format("user-{0}", i));
            var itemIds = Enumerable.Range(0, NUM).Select(i => String.Format("item-{0}", i));
            // Generate some random purchases of items by users
            const double PROBABILITY_PURCHASED = 0.1;
            Random r = new Random();
            var purchases = new List<Request>();

            foreach(var userId in userIds) {
                purchases.AddRange(
                    itemIds.Where(_ => r.NextDouble() < PROBABILITY_PURCHASED)
                           .Select(itemId =>
                                    new AddPurchase(userId, itemId, cascadeCreate: true) // Use cascadeCreate parameter to create
                           )                                                             // the yet non-existing users and items
                );
            }

            Console.WriteLine("Send purchases");
            client.Send(new Batch(purchases)); //Use Batch for faster processing of larger data

            // Get 5 recommendations for user 'user-25'
            IEnumerable<Recommendation> recommended = client.Send(new UserBasedRecommendation("user-25", 5));
            Console.WriteLine("Recommended items:");
            foreach(Recommendation rec in recommended) Console.WriteLine(rec.Id);

         }
         catch(ApiException e)
         {
             Console.WriteLine(e.ToString());
             // Use fallback
         }

        return 0;
    }
}