Skip to content

Commit

Permalink
additionalData for interactions, returnAbGroup for recommendation end…
Browse files Browse the repository at this point in the history
…points
  • Loading branch information
OndraFiedler committed Feb 18, 2019
1 parent dd7d2c2 commit 904c986
Show file tree
Hide file tree
Showing 31 changed files with 98 additions and 23 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Recombee API Client

A Node.js client (SDK) for easy use of the [Recombee](https://www.recombee.com/) recommendation API.

If you don't have an account at Recombee yet, you can create a free account [here](https://www.recombee.com/).

Documentation of the API can be found at [docs.recombee.com](https://docs.recombee.com/).

For client side (browser, mobile apps ...) .js library please see [this repository](https://github.com/recombee/js-api-client).

## Installation

```
Expand Down Expand Up @@ -43,7 +44,7 @@ client.send(new AddDetailView,
var recombee = require('recombee-api-client');
var rqs = recombee.requests;

var client = new recombee.ApiClient('--my-database-id--', '--my-secret-token--');
var client = new recombee.ApiClient('--my-database-id--', '--db-private-token--');

// Prepare some userIDs and itemIDs
const NUM = 100;
Expand Down Expand Up @@ -89,7 +90,7 @@ client.send(new rqs.Batch(purchases))
var recombee = require('recombee-api-client');
var rqs = recombee.requests;

var client = new recombee.ApiClient('--my-database-id--', '--my-secret-token--');
var client = new recombee.ApiClient('--my-database-id--', '--db-private-token--');
const NUM = 100;

// We will use computers as items in this example
Expand Down
2 changes: 1 addition & 1 deletion lib/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ApiClient {
uri: url,
headers: {'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': 'recombee-node-api-client/2.2.0'},
'User-Agent': 'recombee-node-api-client/2.3.0'},
timeout: request.timeout,
resolveWithFullResponse: true,
json: true
Expand Down
7 changes: 7 additions & 0 deletions lib/requests/add-bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class AddBookmark extends rqs.Request {
* - *recommId*
* - Type: string
* - Description: If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
* - *additionalData*
* - Type:
* - Description: A dictionary of additional data for the interaction.
*/
constructor(userId, itemId, optional) {
super('POST', '/bookmarks/', 1000, false);
Expand All @@ -34,6 +37,7 @@ class AddBookmark extends rqs.Request {
this.timestamp = optional.timestamp;
this.cascadeCreate = optional.cascadeCreate;
this.recommId = optional.recommId;
this.additionalData = optional.additionalData;
}

/**
Expand All @@ -54,6 +58,9 @@ class AddBookmark extends rqs.Request {
if(this.recommId !== undefined)
params.recommId = this.recommId;

if(this.additionalData !== undefined)
params.additionalData = this.additionalData;

return params;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/requests/add-cart-addition.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class AddCartAddition extends rqs.Request {
* - *recommId*
* - Type: string
* - Description: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
* - *additionalData*
* - Type:
* - Description: A dictionary of additional data for the interaction.
*/
constructor(userId, itemId, optional) {
super('POST', '/cartadditions/', 1000, false);
Expand All @@ -42,6 +45,7 @@ class AddCartAddition extends rqs.Request {
this.amount = optional.amount;
this.price = optional.price;
this.recommId = optional.recommId;
this.additionalData = optional.additionalData;
}

/**
Expand All @@ -68,6 +72,9 @@ class AddCartAddition extends rqs.Request {
if(this.recommId !== undefined)
params.recommId = this.recommId;

if(this.additionalData !== undefined)
params.additionalData = this.additionalData;

return params;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/requests/add-detail-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class AddDetailView extends rqs.Request {
* - *recommId*
* - Type: string
* - Description: If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
* - *additionalData*
* - Type:
* - Description: A dictionary of additional data for the interaction.
*/
constructor(userId, itemId, optional) {
super('POST', '/detailviews/', 1000, false);
Expand All @@ -38,6 +41,7 @@ class AddDetailView extends rqs.Request {
this.duration = optional.duration;
this.cascadeCreate = optional.cascadeCreate;
this.recommId = optional.recommId;
this.additionalData = optional.additionalData;
}

/**
Expand All @@ -61,6 +65,9 @@ class AddDetailView extends rqs.Request {
if(this.recommId !== undefined)
params.recommId = this.recommId;

if(this.additionalData !== undefined)
params.additionalData = this.additionalData;

return params;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/requests/add-purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class AddPurchase extends rqs.Request {
* - *recommId*
* - Type: string
* - Description: If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
* - *additionalData*
* - Type:
* - Description: A dictionary of additional data for the interaction.
*/
constructor(userId, itemId, optional) {
super('POST', '/purchases/', 1000, false);
Expand All @@ -46,6 +49,7 @@ class AddPurchase extends rqs.Request {
this.price = optional.price;
this.profit = optional.profit;
this.recommId = optional.recommId;
this.additionalData = optional.additionalData;
}

/**
Expand Down Expand Up @@ -75,6 +79,9 @@ class AddPurchase extends rqs.Request {
if(this.recommId !== undefined)
params.recommId = this.recommId;

if(this.additionalData !== undefined)
params.additionalData = this.additionalData;

return params;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/requests/add-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class AddRating extends rqs.Request {
* - *recommId*
* - Type: string
* - Description: If this rating is based on a recommendation request, `recommId` is the id of the clicked recommendation.
* - *additionalData*
* - Type:
* - Description: A dictionary of additional data for the interaction.
*/
constructor(userId, itemId, rating, optional) {
super('POST', '/ratings/', 1000, false);
Expand All @@ -36,6 +39,7 @@ class AddRating extends rqs.Request {
this.timestamp = optional.timestamp;
this.cascadeCreate = optional.cascadeCreate;
this.recommId = optional.recommId;
this.additionalData = optional.additionalData;
}

/**
Expand All @@ -57,6 +61,9 @@ class AddRating extends rqs.Request {
if(this.recommId !== undefined)
params.recommId = this.recommId;

if(this.additionalData !== undefined)
params.additionalData = this.additionalData;

return params;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/requests/recommend-items-to-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const rqs = require("./request");
/**
* Recommends set of items that are somehow related to one given item, *X*. Typical scenario is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Recommend items to item request gives you Top-N such items, optionally taking the target user *A* into account.
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
* The returned items are sorted by relevancy (first item being the most relevant).
*/
class RecommendItemsToItem extends rqs.Request {

Expand Down Expand Up @@ -116,6 +117,9 @@ class RecommendItemsToItem extends rqs.Request {
* - *expertSettings*
* - Type:
* - Description: Dictionary of custom options.
* - *returnAbGroup*
* - Type: boolean
* - Description: If there is a custom AB-testing running, return name of group to which the request belongs.
*/
constructor(itemId, targetUserId, count, optional) {
super('POST', `/recomms/items/${itemId}/items/`, 3000, false);
Expand All @@ -135,6 +139,7 @@ class RecommendItemsToItem extends rqs.Request {
this.rotationRate = optional.rotationRate;
this.rotationTime = optional.rotationTime;
this.expertSettings = optional.expertSettings;
this.returnAbGroup = optional.returnAbGroup;
}

/**
Expand Down Expand Up @@ -182,6 +187,9 @@ class RecommendItemsToItem extends rqs.Request {
if(this.expertSettings !== undefined)
params.expertSettings = this.expertSettings;

if(this.returnAbGroup !== undefined)
params.returnAbGroup = this.returnAbGroup;

return params;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/requests/recommend-items-to-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const rqs = require("./request");
/**
* Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
* The returned items are sorted by relevancy (first item being the most relevant).
*/
class RecommendItemsToUser extends rqs.Request {

Expand Down Expand Up @@ -100,6 +101,9 @@ class RecommendItemsToUser extends rqs.Request {
* - *expertSettings*
* - Type:
* - Description: Dictionary of custom options.
* - *returnAbGroup*
* - Type: boolean
* - Description: If there is a custom AB-testing running, return name of group to which the request belongs.
*/
constructor(userId, count, optional) {
super('POST', `/recomms/users/${userId}/items/`, 3000, false);
Expand All @@ -117,6 +121,7 @@ class RecommendItemsToUser extends rqs.Request {
this.rotationRate = optional.rotationRate;
this.rotationTime = optional.rotationTime;
this.expertSettings = optional.expertSettings;
this.returnAbGroup = optional.returnAbGroup;
}

/**
Expand Down Expand Up @@ -160,6 +165,9 @@ class RecommendItemsToUser extends rqs.Request {
if(this.expertSettings !== undefined)
params.expertSettings = this.expertSettings;

if(this.returnAbGroup !== undefined)
params.returnAbGroup = this.returnAbGroup;

return params;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/requests/recommend-users-to-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const rqs = require("./request");
/**
* Recommend users that are likely to be interested in a given item.
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
* The returned users are sorted by predicted interest in the item (first user being the most interested).
*/
class RecommendUsersToItem extends rqs.Request {

Expand Down Expand Up @@ -85,6 +86,9 @@ class RecommendUsersToItem extends rqs.Request {
* - *expertSettings*
* - Type:
* - Description: Dictionary of custom options.
* - *returnAbGroup*
* - Type: boolean
* - Description: If there is a custom AB-testing running, return name of group to which the request belongs.
*/
constructor(itemId, count, optional) {
super('POST', `/recomms/items/${itemId}/users/`, 50000, false);
Expand All @@ -99,6 +103,7 @@ class RecommendUsersToItem extends rqs.Request {
this.includedProperties = optional.includedProperties;
this.diversity = optional.diversity;
this.expertSettings = optional.expertSettings;
this.returnAbGroup = optional.returnAbGroup;
}

/**
Expand Down Expand Up @@ -133,6 +138,9 @@ class RecommendUsersToItem extends rqs.Request {
if(this.expertSettings !== undefined)
params.expertSettings = this.expertSettings;

if(this.returnAbGroup !== undefined)
params.returnAbGroup = this.returnAbGroup;

return params;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/requests/recommend-users-to-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const rqs = require("./request");
/**
* Get similar users as some given user, based on the user's past interactions (purchases, ratings, etc.) and values of properties.
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
* The returned users are sorted by similarity (first user being the most similar).
*/
class RecommendUsersToUser extends rqs.Request {

Expand Down Expand Up @@ -94,6 +95,9 @@ class RecommendUsersToUser extends rqs.Request {
* - *expertSettings*
* - Type:
* - Description: Dictionary of custom options.
* - *returnAbGroup*
* - Type: boolean
* - Description: If there is a custom AB-testing running, return name of group to which the request belongs.
*/
constructor(userId, count, optional) {
super('POST', `/recomms/users/${userId}/users/`, 50000, false);
Expand All @@ -111,6 +115,7 @@ class RecommendUsersToUser extends rqs.Request {
this.rotationRate = optional.rotationRate;
this.rotationTime = optional.rotationTime;
this.expertSettings = optional.expertSettings;
this.returnAbGroup = optional.returnAbGroup;
}

/**
Expand Down Expand Up @@ -154,6 +159,9 @@ class RecommendUsersToUser extends rqs.Request {
if(this.expertSettings !== undefined)
params.expertSettings = this.expertSettings;

if(this.returnAbGroup !== undefined)
params.returnAbGroup = this.returnAbGroup;

return params;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/requests/set-view-portion.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class SetViewPortion extends rqs.Request {
* - *recommId*
* - Type: string
* - Description: If this view portion is based on a recommendation request, `recommId` is the id of the clicked recommendation.
* - *additionalData*
* - Type:
* - Description: A dictionary of additional data for the interaction.
*/
constructor(userId, itemId, portion, optional) {
super('POST', '/viewportions/', 1000, false);
Expand All @@ -41,6 +44,7 @@ class SetViewPortion extends rqs.Request {
this.timestamp = optional.timestamp;
this.cascadeCreate = optional.cascadeCreate;
this.recommId = optional.recommId;
this.additionalData = optional.additionalData;
}

/**
Expand All @@ -65,6 +69,9 @@ class SetViewPortion extends rqs.Request {
if(this.recommId !== undefined)
params.recommId = this.recommId;

if(this.additionalData !== undefined)
params.additionalData = this.additionalData;

return params;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recombee-api-client",
"version": "2.2.0",
"version": "2.3.0",
"description": "Node.js client (SDK) for easy use of the Recombee recommendation API",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/add-bookmark-batch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('AddBookmark', function(){
});
it ('works in batch', (done) => {
let requests = [
new rqs.AddBookmark('u_id','i_id',{'cascadeCreate': true}),
new rqs.AddBookmark('u_id','i_id',{'cascadeCreate': true,'additionalData': {'answer': 42}}),
new rqs.AddBookmark('entity_id','entity_id'),
new rqs.AddBookmark('entity_id','entity_id',{'timestamp': '2013-10-29T09:38:41.341Z'}),
new rqs.AddBookmark('entity_id','nonex_id'),
Expand Down
2 changes: 1 addition & 1 deletion test/add-bookmark-callback_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('AddBookmark', function(){

it ('does not fail with cascadeCreate', (done) => {
let req, req2, resp;
req = new rqs.AddBookmark('u_id','i_id',{'cascadeCreate': true});
req = new rqs.AddBookmark('u_id','i_id',{'cascadeCreate': true,'additionalData': {'answer': 42}});
env.client.send(req,((err,res) => {
if(err) {
chai.fail();
Expand Down
2 changes: 1 addition & 1 deletion test/add-bookmark-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('AddBookmark', function(){

it ('does not fail with cascadeCreate', (done) => {
let req, req2, resp;
req = new rqs.AddBookmark('u_id','i_id',{'cascadeCreate': true});
req = new rqs.AddBookmark('u_id','i_id',{'cascadeCreate': true,'additionalData': {'answer': 42}});
env.client.send(req)
.then((res) => {
done();
Expand Down
2 changes: 1 addition & 1 deletion test/add-cart-addition-batch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('AddCartAddition', function(){
});
it ('works in batch', (done) => {
let requests = [
new rqs.AddCartAddition('u_id','i_id',{'cascadeCreate': true}),
new rqs.AddCartAddition('u_id','i_id',{'cascadeCreate': true,'additionalData': {'answer': 42}}),
new rqs.AddCartAddition('entity_id','entity_id'),
new rqs.AddCartAddition('entity_id','entity_id',{'timestamp': '2013-10-29T09:38:41.341Z'}),
new rqs.AddCartAddition('entity_id','nonex_id'),
Expand Down
Loading

0 comments on commit 904c986

Please sign in to comment.