Java API Client
Example
Java
RecombeeClient client = new RecombeeClient("--my-database-id--", "--db-private-token--").setRegion(Region.US_WEST);
try {
final int NUM = 100;
// Generate some random purchases of items by users
final double PROBABILITY_PURCHASED = 0.1;
Random r = new Random();
ArrayList<Request> addPurchaseRequests = new ArrayList<Request>();
for (int i = 0; i < NUM; i++)
for (int j = 0; j < NUM; j++)
if (r.nextDouble() < PROBABILITY_PURCHASED) {
AddPurchase request = new AddPurchase(String.format("user-%s", i),String.format("item-%s", j))
.setCascadeCreate(true); // Use cascadeCreate parameter to create
// the yet non-existing users and items
addPurchaseRequests.add(request);
}
System.out.println("Send purchases");
client.send(new Batch(addPurchaseRequests)); //Use Batch for faster processing of larger data
// Get 5 recommendations for user 'user-25'
RecommendationResponse recommendationResponse = client.send(new RecommendItemsToUser("user-25", 5));
System.out.println("Recommended items:");
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
// User scrolled down - get next 3 recommended items
recommendationResponse = client.send(new RecommendNextItems(recommendationResponse.getRecommId(), 3));
System.out.println("Next recommended items:");
for(Recommendation rec: recommendationResponse) System.out.println(rec.getId());
} catch (ApiException e) {
e.printStackTrace();
//use fallback
}