Skip to content

Commit 2d352c5

Browse files
committed
additionalData for interactions, returnAbGroup for recommendation endpoints
1 parent 1843fec commit 2d352c5

15 files changed

+121
-17
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or
1717
```
1818
{
1919
"require": {
20-
"recombee/php-api-client": "^2.2.0"
20+
"recombee/php-api-client": "^2.3.0"
2121
}
2222
}
2323
```
@@ -30,7 +30,7 @@ use Recombee\RecommApi\Client;
3030
use Recombee\RecommApi\Requests as Reqs;
3131
use Recombee\RecommApi\Exceptions as Ex;
3232

33-
$client = new Client('--my-database-id--', '--my-secret-token--');
33+
$client = new Client('--my-database-id--', '--db-private-token--');
3434

3535
const NUM = 100;
3636
const PROBABILITY_PURCHASED = 0.1;
@@ -74,7 +74,7 @@ use Recombee\RecommApi\Exceptions as Ex;
7474
const NUM = 100;
7575
const PROBABILITY_PURCHASED = 0.1;
7676

77-
$client = new Client('--my-database-id--', '--my-secret-token--');
77+
$client = new Client('--my-database-id--', '--db-private-token--');
7878
$client->send(new Reqs\ResetDatabase()); //Clear everything from the database
7979

8080
/*

src/RecommApi/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct($account, $token, $protocol = 'http', $options= arra
5252
}
5353

5454
protected function getUserAgent() {
55-
$user_agent = 'recombee-php-api-client/2.2.0';
55+
$user_agent = 'recombee-php-api-client/2.3.0';
5656
if (isset($this->options['serviceName']))
5757
$user_agent .= ' '.($this->options['serviceName']);
5858
return $user_agent;

src/RecommApi/Requests/AddBookmark.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class AddBookmark extends Request {
3434
* @var string $recomm_id If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
3535
*/
3636
protected $recomm_id;
37+
/**
38+
* @var $additional_data A dictionary of additional data for the interaction.
39+
*/
40+
protected $additional_data;
3741
/**
3842
* @var array Array containing values of optional parameters
3943
*/
@@ -54,6 +58,9 @@ class AddBookmark extends Request {
5458
* - *recommId*
5559
* - Type: string
5660
* - Description: If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
61+
* - *additionalData*
62+
* - Type:
63+
* - Description: A dictionary of additional data for the interaction.
5764
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
5865
*/
5966
public function __construct($user_id, $item_id, $optional = array()) {
@@ -62,9 +69,10 @@ public function __construct($user_id, $item_id, $optional = array()) {
6269
$this->timestamp = isset($optional['timestamp']) ? $optional['timestamp'] : null;
6370
$this->cascade_create = isset($optional['cascadeCreate']) ? $optional['cascadeCreate'] : null;
6471
$this->recomm_id = isset($optional['recommId']) ? $optional['recommId'] : null;
72+
$this->additional_data = isset($optional['additionalData']) ? $optional['additionalData'] : null;
6573
$this->optional = $optional;
6674

67-
$existing_optional = array('timestamp','cascadeCreate','recommId');
75+
$existing_optional = array('timestamp','cascadeCreate','recommId','additionalData');
6876
foreach ($this->optional as $key => $value) {
6977
if (!in_array($key, $existing_optional))
7078
throw new UnknownOptionalParameterException($key);
@@ -112,6 +120,8 @@ public function getBodyParameters() {
112120
$p['cascadeCreate'] = $this-> optional['cascadeCreate'];
113121
if (isset($this->optional['recommId']))
114122
$p['recommId'] = $this-> optional['recommId'];
123+
if (isset($this->optional['additionalData']))
124+
$p['additionalData'] = $this-> optional['additionalData'];
115125
return $p;
116126
}
117127

src/RecommApi/Requests/AddCartAddition.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class AddCartAddition extends Request {
4242
* @var string $recomm_id If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
4343
*/
4444
protected $recomm_id;
45+
/**
46+
* @var $additional_data A dictionary of additional data for the interaction.
47+
*/
48+
protected $additional_data;
4549
/**
4650
* @var array Array containing values of optional parameters
4751
*/
@@ -68,6 +72,9 @@ class AddCartAddition extends Request {
6872
* - *recommId*
6973
* - Type: string
7074
* - Description: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
75+
* - *additionalData*
76+
* - Type:
77+
* - Description: A dictionary of additional data for the interaction.
7178
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
7279
*/
7380
public function __construct($user_id, $item_id, $optional = array()) {
@@ -78,9 +85,10 @@ public function __construct($user_id, $item_id, $optional = array()) {
7885
$this->amount = isset($optional['amount']) ? $optional['amount'] : null;
7986
$this->price = isset($optional['price']) ? $optional['price'] : null;
8087
$this->recomm_id = isset($optional['recommId']) ? $optional['recommId'] : null;
88+
$this->additional_data = isset($optional['additionalData']) ? $optional['additionalData'] : null;
8189
$this->optional = $optional;
8290

83-
$existing_optional = array('timestamp','cascadeCreate','amount','price','recommId');
91+
$existing_optional = array('timestamp','cascadeCreate','amount','price','recommId','additionalData');
8492
foreach ($this->optional as $key => $value) {
8593
if (!in_array($key, $existing_optional))
8694
throw new UnknownOptionalParameterException($key);
@@ -132,6 +140,8 @@ public function getBodyParameters() {
132140
$p['price'] = $this-> optional['price'];
133141
if (isset($this->optional['recommId']))
134142
$p['recommId'] = $this-> optional['recommId'];
143+
if (isset($this->optional['additionalData']))
144+
$p['additionalData'] = $this-> optional['additionalData'];
135145
return $p;
136146
}
137147

src/RecommApi/Requests/AddDetailView.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class AddDetailView extends Request {
3838
* @var string $recomm_id If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
3939
*/
4040
protected $recomm_id;
41+
/**
42+
* @var $additional_data A dictionary of additional data for the interaction.
43+
*/
44+
protected $additional_data;
4145
/**
4246
* @var array Array containing values of optional parameters
4347
*/
@@ -61,6 +65,9 @@ class AddDetailView extends Request {
6165
* - *recommId*
6266
* - Type: string
6367
* - Description: If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
68+
* - *additionalData*
69+
* - Type:
70+
* - Description: A dictionary of additional data for the interaction.
6471
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
6572
*/
6673
public function __construct($user_id, $item_id, $optional = array()) {
@@ -70,9 +77,10 @@ public function __construct($user_id, $item_id, $optional = array()) {
7077
$this->duration = isset($optional['duration']) ? $optional['duration'] : null;
7178
$this->cascade_create = isset($optional['cascadeCreate']) ? $optional['cascadeCreate'] : null;
7279
$this->recomm_id = isset($optional['recommId']) ? $optional['recommId'] : null;
80+
$this->additional_data = isset($optional['additionalData']) ? $optional['additionalData'] : null;
7381
$this->optional = $optional;
7482

75-
$existing_optional = array('timestamp','duration','cascadeCreate','recommId');
83+
$existing_optional = array('timestamp','duration','cascadeCreate','recommId','additionalData');
7684
foreach ($this->optional as $key => $value) {
7785
if (!in_array($key, $existing_optional))
7886
throw new UnknownOptionalParameterException($key);
@@ -122,6 +130,8 @@ public function getBodyParameters() {
122130
$p['cascadeCreate'] = $this-> optional['cascadeCreate'];
123131
if (isset($this->optional['recommId']))
124132
$p['recommId'] = $this-> optional['recommId'];
133+
if (isset($this->optional['additionalData']))
134+
$p['additionalData'] = $this-> optional['additionalData'];
125135
return $p;
126136
}
127137

src/RecommApi/Requests/AddPurchase.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class AddPurchase extends Request {
4646
* @var string $recomm_id If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
4747
*/
4848
protected $recomm_id;
49+
/**
50+
* @var $additional_data A dictionary of additional data for the interaction.
51+
*/
52+
protected $additional_data;
4953
/**
5054
* @var array Array containing values of optional parameters
5155
*/
@@ -75,6 +79,9 @@ class AddPurchase extends Request {
7579
* - *recommId*
7680
* - Type: string
7781
* - Description: If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
82+
* - *additionalData*
83+
* - Type:
84+
* - Description: A dictionary of additional data for the interaction.
7885
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
7986
*/
8087
public function __construct($user_id, $item_id, $optional = array()) {
@@ -86,9 +93,10 @@ public function __construct($user_id, $item_id, $optional = array()) {
8693
$this->price = isset($optional['price']) ? $optional['price'] : null;
8794
$this->profit = isset($optional['profit']) ? $optional['profit'] : null;
8895
$this->recomm_id = isset($optional['recommId']) ? $optional['recommId'] : null;
96+
$this->additional_data = isset($optional['additionalData']) ? $optional['additionalData'] : null;
8997
$this->optional = $optional;
9098

91-
$existing_optional = array('timestamp','cascadeCreate','amount','price','profit','recommId');
99+
$existing_optional = array('timestamp','cascadeCreate','amount','price','profit','recommId','additionalData');
92100
foreach ($this->optional as $key => $value) {
93101
if (!in_array($key, $existing_optional))
94102
throw new UnknownOptionalParameterException($key);
@@ -142,6 +150,8 @@ public function getBodyParameters() {
142150
$p['profit'] = $this-> optional['profit'];
143151
if (isset($this->optional['recommId']))
144152
$p['recommId'] = $this-> optional['recommId'];
153+
if (isset($this->optional['additionalData']))
154+
$p['additionalData'] = $this-> optional['additionalData'];
145155
return $p;
146156
}
147157

src/RecommApi/Requests/AddRating.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class AddRating extends Request {
3838
* @var string $recomm_id If this rating is based on a recommendation request, `recommId` is the id of the clicked recommendation.
3939
*/
4040
protected $recomm_id;
41+
/**
42+
* @var $additional_data A dictionary of additional data for the interaction.
43+
*/
44+
protected $additional_data;
4145
/**
4246
* @var array Array containing values of optional parameters
4347
*/
@@ -59,6 +63,9 @@ class AddRating extends Request {
5963
* - *recommId*
6064
* - Type: string
6165
* - Description: If this rating is based on a recommendation request, `recommId` is the id of the clicked recommendation.
66+
* - *additionalData*
67+
* - Type:
68+
* - Description: A dictionary of additional data for the interaction.
6269
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
6370
*/
6471
public function __construct($user_id, $item_id, $rating, $optional = array()) {
@@ -68,9 +75,10 @@ public function __construct($user_id, $item_id, $rating, $optional = array()) {
6875
$this->timestamp = isset($optional['timestamp']) ? $optional['timestamp'] : null;
6976
$this->cascade_create = isset($optional['cascadeCreate']) ? $optional['cascadeCreate'] : null;
7077
$this->recomm_id = isset($optional['recommId']) ? $optional['recommId'] : null;
78+
$this->additional_data = isset($optional['additionalData']) ? $optional['additionalData'] : null;
7179
$this->optional = $optional;
7280

73-
$existing_optional = array('timestamp','cascadeCreate','recommId');
81+
$existing_optional = array('timestamp','cascadeCreate','recommId','additionalData');
7482
foreach ($this->optional as $key => $value) {
7583
if (!in_array($key, $existing_optional))
7684
throw new UnknownOptionalParameterException($key);
@@ -119,6 +127,8 @@ public function getBodyParameters() {
119127
$p['cascadeCreate'] = $this-> optional['cascadeCreate'];
120128
if (isset($this->optional['recommId']))
121129
$p['recommId'] = $this-> optional['recommId'];
130+
if (isset($this->optional['additionalData']))
131+
$p['additionalData'] = $this-> optional['additionalData'];
122132
return $p;
123133
}
124134

src/RecommApi/Requests/RecommendItemsToItem.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* 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.
1414
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
15+
* The returned items are sorted by relevancy (first item being the most relevant).
1516
*/
1617
class RecommendItemsToItem extends Request {
1718

@@ -137,6 +138,10 @@ class RecommendItemsToItem extends Request {
137138
* @var $expert_settings Dictionary of custom options.
138139
*/
139140
protected $expert_settings;
141+
/**
142+
* @var bool $return_ab_group If there is a custom AB-testing running, return name of group to which the request belongs.
143+
*/
144+
protected $return_ab_group;
140145
/**
141146
* @var array Array containing values of optional parameters
142147
*/
@@ -247,6 +252,9 @@ class RecommendItemsToItem extends Request {
247252
* - *expertSettings*
248253
* - Type:
249254
* - Description: Dictionary of custom options.
255+
* - *returnAbGroup*
256+
* - Type: bool
257+
* - Description: If there is a custom AB-testing running, return name of group to which the request belongs.
250258
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
251259
*/
252260
public function __construct($item_id, $target_user_id, $count, $optional = array()) {
@@ -265,9 +273,10 @@ public function __construct($item_id, $target_user_id, $count, $optional = array
265273
$this->rotation_rate = isset($optional['rotationRate']) ? $optional['rotationRate'] : null;
266274
$this->rotation_time = isset($optional['rotationTime']) ? $optional['rotationTime'] : null;
267275
$this->expert_settings = isset($optional['expertSettings']) ? $optional['expertSettings'] : null;
276+
$this->return_ab_group = isset($optional['returnAbGroup']) ? $optional['returnAbGroup'] : null;
268277
$this->optional = $optional;
269278

270-
$existing_optional = array('userImpact','filter','booster','cascadeCreate','scenario','returnProperties','includedProperties','diversity','minRelevance','rotationRate','rotationTime','expertSettings');
279+
$existing_optional = array('userImpact','filter','booster','cascadeCreate','scenario','returnProperties','includedProperties','diversity','minRelevance','rotationRate','rotationTime','expertSettings','returnAbGroup');
271280
foreach ($this->optional as $key => $value) {
272281
if (!in_array($key, $existing_optional))
273282
throw new UnknownOptionalParameterException($key);
@@ -333,6 +342,8 @@ public function getBodyParameters() {
333342
$p['rotationTime'] = $this-> optional['rotationTime'];
334343
if (isset($this->optional['expertSettings']))
335344
$p['expertSettings'] = $this-> optional['expertSettings'];
345+
if (isset($this->optional['returnAbGroup']))
346+
$p['returnAbGroup'] = $this-> optional['returnAbGroup'];
336347
return $p;
337348
}
338349

src/RecommApi/Requests/RecommendItemsToUser.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* 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.
1414
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
15+
* The returned items are sorted by relevancy (first item being the most relevant).
1516
*/
1617
class RecommendItemsToUser extends Request {
1718

@@ -117,6 +118,10 @@ class RecommendItemsToUser extends Request {
117118
* @var $expert_settings Dictionary of custom options.
118119
*/
119120
protected $expert_settings;
121+
/**
122+
* @var bool $return_ab_group If there is a custom AB-testing running, return name of group to which the request belongs.
123+
*/
124+
protected $return_ab_group;
120125
/**
121126
* @var array Array containing values of optional parameters
122127
*/
@@ -211,6 +216,9 @@ class RecommendItemsToUser extends Request {
211216
* - *expertSettings*
212217
* - Type:
213218
* - Description: Dictionary of custom options.
219+
* - *returnAbGroup*
220+
* - Type: bool
221+
* - Description: If there is a custom AB-testing running, return name of group to which the request belongs.
214222
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
215223
*/
216224
public function __construct($user_id, $count, $optional = array()) {
@@ -227,9 +235,10 @@ public function __construct($user_id, $count, $optional = array()) {
227235
$this->rotation_rate = isset($optional['rotationRate']) ? $optional['rotationRate'] : null;
228236
$this->rotation_time = isset($optional['rotationTime']) ? $optional['rotationTime'] : null;
229237
$this->expert_settings = isset($optional['expertSettings']) ? $optional['expertSettings'] : null;
238+
$this->return_ab_group = isset($optional['returnAbGroup']) ? $optional['returnAbGroup'] : null;
230239
$this->optional = $optional;
231240

232-
$existing_optional = array('filter','booster','cascadeCreate','scenario','returnProperties','includedProperties','diversity','minRelevance','rotationRate','rotationTime','expertSettings');
241+
$existing_optional = array('filter','booster','cascadeCreate','scenario','returnProperties','includedProperties','diversity','minRelevance','rotationRate','rotationTime','expertSettings','returnAbGroup');
233242
foreach ($this->optional as $key => $value) {
234243
if (!in_array($key, $existing_optional))
235244
throw new UnknownOptionalParameterException($key);
@@ -292,6 +301,8 @@ public function getBodyParameters() {
292301
$p['rotationTime'] = $this-> optional['rotationTime'];
293302
if (isset($this->optional['expertSettings']))
294303
$p['expertSettings'] = $this-> optional['expertSettings'];
304+
if (isset($this->optional['returnAbGroup']))
305+
$p['returnAbGroup'] = $this-> optional['returnAbGroup'];
295306
return $p;
296307
}
297308

0 commit comments

Comments
 (0)