Skip to content

Commit a3df12b

Browse files
committed
Added parameters amount,price,profit to AddPurchase and amount,price to AddCartAddition
1 parent 7609085 commit a3df12b

39 files changed

+2182
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The client is available in the [Maven Central Repository](https://mvnrepository.
1313
<dependency>
1414
<groupId>com.recombee</groupId>
1515
<artifactId>api-client</artifactId>
16-
<version>1.5.0</version>
16+
<version>1.6.0</version>
1717
</dependency>
1818
```
1919

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.recombee</groupId>
88
<artifactId>api-client</artifactId>
9-
<version>1.5.0</version>
9+
<version>1.6.0</version>
1010
<name>Recombee API Client</name>
1111
<description>A client library for easy use of the Recombee recommendation API</description>
1212
<url>http://recombee.com</url>

src/main/java/com/recombee/api_client/RecombeeClient.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
import com.recombee.api_client.api_requests.ListUserBookmarks;
6262
import com.recombee.api_client.api_requests.ListItemViewPortions;
6363
import com.recombee.api_client.api_requests.ListUserViewPortions;
64+
import com.recombee.api_client.api_requests.RecommendItemsToUser;
65+
import com.recombee.api_client.api_requests.RecommendUsersToUser;
66+
import com.recombee.api_client.api_requests.RecommendItemsToItem;
67+
import com.recombee.api_client.api_requests.RecommendUsersToItem;
6468
import com.recombee.api_client.api_requests.UserBasedRecommendation;
6569
import com.recombee.api_client.api_requests.ItemBasedRecommendation;
6670

@@ -79,7 +83,7 @@ public class RecombeeClient {
7983

8084
final int BATCH_MAX_SIZE = 10000; //Maximal number of requests within one batch request
8185

82-
final String USER_AGENT = "recombee-java-api-client/1.5.0";
86+
final String USER_AGENT = "recombee-java-api-client/1.6.0";
8387

8488
public RecombeeClient(String databaseId, String token) {
8589
this.databaseId = databaseId;
@@ -300,6 +304,46 @@ public ViewPortion[] send(ListUserViewPortions request) throws ApiException {
300304
return null;
301305
}
302306

307+
public RecommendationResponse send(RecommendItemsToUser request) throws ApiException {
308+
String responseStr = sendRequest(request);
309+
try {
310+
return this.mapper.readValue(responseStr, RecommendationResponse.class);
311+
} catch (IOException e) {
312+
e.printStackTrace();
313+
}
314+
return null;
315+
}
316+
317+
public RecommendationResponse send(RecommendUsersToUser request) throws ApiException {
318+
String responseStr = sendRequest(request);
319+
try {
320+
return this.mapper.readValue(responseStr, RecommendationResponse.class);
321+
} catch (IOException e) {
322+
e.printStackTrace();
323+
}
324+
return null;
325+
}
326+
327+
public RecommendationResponse send(RecommendItemsToItem request) throws ApiException {
328+
String responseStr = sendRequest(request);
329+
try {
330+
return this.mapper.readValue(responseStr, RecommendationResponse.class);
331+
} catch (IOException e) {
332+
e.printStackTrace();
333+
}
334+
return null;
335+
}
336+
337+
public RecommendationResponse send(RecommendUsersToItem request) throws ApiException {
338+
String responseStr = sendRequest(request);
339+
try {
340+
return this.mapper.readValue(responseStr, RecommendationResponse.class);
341+
} catch (IOException e) {
342+
e.printStackTrace();
343+
}
344+
return null;
345+
}
346+
303347
/* End of the generated code */
304348

305349
public BatchResponse[] send(Batch batchRequest) throws ApiException {
@@ -384,6 +428,13 @@ else if (request instanceof ListUsers)
384428
parsedResponse = ar;
385429
}
386430
}
431+
else if ((request instanceof RecommendItemsToUser) ||
432+
(request instanceof RecommendUsersToUser) ||
433+
(request instanceof RecommendItemsToItem) ||
434+
(request instanceof RecommendUsersToItem))
435+
{
436+
parsedResponse = mapper.convertValue(parsedResponse, RecommendationResponse.class);
437+
}
387438
/* Start of the generated code */
388439
else if (request instanceof GetItemPropertyInfo)
389440
{
@@ -627,14 +678,14 @@ public Map<String, Object> send(GetUserValues request) throws ApiException {
627678

628679

629680
public Recommendation[] send(UserBasedRecommendation request) throws ApiException {
630-
return sendRecomm(request);
681+
return sendDeprecatedRecomm(request);
631682
}
632683

633684
public Recommendation[] send(ItemBasedRecommendation request) throws ApiException {
634-
return sendRecomm(request);
685+
return sendDeprecatedRecomm(request);
635686
}
636687

637-
protected Recommendation[] sendRecomm(Request request) throws ApiException {
688+
protected Recommendation[] sendDeprecatedRecomm(Request request) throws ApiException {
638689
String responseStr = sendRequest(request);
639690

640691
try {

src/main/java/com/recombee/api_client/api_requests/AddCartAddition.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public class AddCartAddition extends Request {
3131
* Sets whether the given user/item should be created if not present in the database.
3232
*/
3333
protected Boolean cascadeCreate;
34+
/**
35+
* Amount (number) added to cart. The default is 1. For example if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal to 2.
36+
*/
37+
protected Double amount;
38+
/**
39+
* Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
40+
*/
41+
protected Double price;
3442

3543
/**
3644
* Construct the request
@@ -59,6 +67,22 @@ public AddCartAddition setCascadeCreate(boolean cascadeCreate) {
5967
return this;
6068
}
6169

70+
/**
71+
* @param amount Amount (number) added to cart. The default is 1. For example if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal to 2.
72+
*/
73+
public AddCartAddition setAmount(double amount) {
74+
this.amount = amount;
75+
return this;
76+
}
77+
78+
/**
79+
* @param price Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
80+
*/
81+
public AddCartAddition setPrice(double price) {
82+
this.price = price;
83+
return this;
84+
}
85+
6286
public String getUserId() {
6387
return this.userId;
6488
}
@@ -76,6 +100,14 @@ public boolean getCascadeCreate() {
76100
return this.cascadeCreate;
77101
}
78102

103+
public double getAmount() {
104+
return this.amount;
105+
}
106+
107+
public double getPrice() {
108+
return this.price;
109+
}
110+
79111
/**
80112
* @return Used HTTP method
81113
*/
@@ -117,6 +149,12 @@ public Map<String, Object> getBodyParameters() {
117149
if (this.cascadeCreate!=null) {
118150
params.put("cascadeCreate", this.cascadeCreate);
119151
}
152+
if (this.amount!=null) {
153+
params.put("amount", this.amount);
154+
}
155+
if (this.price!=null) {
156+
params.put("price", this.price);
157+
}
120158
return params;
121159
}
122160

src/main/java/com/recombee/api_client/api_requests/AddItemProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AddItemProperty extends Request {
3232
public AddItemProperty (String propertyName,String type) {
3333
this.propertyName = propertyName;
3434
this.type = type;
35-
this.timeout = 1000;
35+
this.timeout = 100000;
3636
}
3737

3838

src/main/java/com/recombee/api_client/api_requests/AddPurchase.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public class AddPurchase extends Request {
3131
* Sets whether the given user/item should be created if not present in the database.
3232
*/
3333
protected Boolean cascadeCreate;
34+
/**
35+
* Amount (number) of purchased items. The default is 1. For example if `user-x` purchases two `item-y` during a single order (session...), the `amount` should equal to 2.
36+
*/
37+
protected Double amount;
38+
/**
39+
* Price paid by the user for the item. If `amount` is greater than 1, sum of prices of all the items should be given.
40+
*/
41+
protected Double price;
42+
/**
43+
* Your profit from the purchased item. The profit is natural in e-commerce domain (for example if `user-x` purchases `item-y` for $100 and the gross margin is 30 %, then the profit is $30), but is applicable also in other domains (for example at a news company it may be income from displayed advertisement on article page). If `amount` is greater than 1, sum of profit of all the items should be given.
44+
*/
45+
protected Double profit;
3446

3547
/**
3648
* Construct the request
@@ -59,6 +71,30 @@ public AddPurchase setCascadeCreate(boolean cascadeCreate) {
5971
return this;
6072
}
6173

74+
/**
75+
* @param amount Amount (number) of purchased items. The default is 1. For example if `user-x` purchases two `item-y` during a single order (session...), the `amount` should equal to 2.
76+
*/
77+
public AddPurchase setAmount(double amount) {
78+
this.amount = amount;
79+
return this;
80+
}
81+
82+
/**
83+
* @param price Price paid by the user for the item. If `amount` is greater than 1, sum of prices of all the items should be given.
84+
*/
85+
public AddPurchase setPrice(double price) {
86+
this.price = price;
87+
return this;
88+
}
89+
90+
/**
91+
* @param profit Your profit from the purchased item. The profit is natural in e-commerce domain (for example if `user-x` purchases `item-y` for $100 and the gross margin is 30 %, then the profit is $30), but is applicable also in other domains (for example at a news company it may be income from displayed advertisement on article page). If `amount` is greater than 1, sum of profit of all the items should be given.
92+
*/
93+
public AddPurchase setProfit(double profit) {
94+
this.profit = profit;
95+
return this;
96+
}
97+
6298
public String getUserId() {
6399
return this.userId;
64100
}
@@ -76,6 +112,18 @@ public boolean getCascadeCreate() {
76112
return this.cascadeCreate;
77113
}
78114

115+
public double getAmount() {
116+
return this.amount;
117+
}
118+
119+
public double getPrice() {
120+
return this.price;
121+
}
122+
123+
public double getProfit() {
124+
return this.profit;
125+
}
126+
79127
/**
80128
* @return Used HTTP method
81129
*/
@@ -117,6 +165,15 @@ public Map<String, Object> getBodyParameters() {
117165
if (this.cascadeCreate!=null) {
118166
params.put("cascadeCreate", this.cascadeCreate);
119167
}
168+
if (this.amount!=null) {
169+
params.put("amount", this.amount);
170+
}
171+
if (this.price!=null) {
172+
params.put("price", this.price);
173+
}
174+
if (this.profit!=null) {
175+
params.put("profit", this.profit);
176+
}
120177
return params;
121178
}
122179

src/main/java/com/recombee/api_client/api_requests/AddUserProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AddUserProperty extends Request {
3232
public AddUserProperty (String propertyName,String type) {
3333
this.propertyName = propertyName;
3434
this.type = type;
35-
this.timeout = 1000;
35+
this.timeout = 100000;
3636
}
3737

3838

src/main/java/com/recombee/api_client/api_requests/Batch.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ public HTTPMethod getHTTPMethod() {
7575
return HTTPMethod.POST;
7676
}
7777

78+
/**
79+
* Returns true if HTTPS must be chosen over HTTP for this request
80+
* @return True if HTTPS must be chosen
81+
*/
82+
@Override
83+
public boolean getEnsureHttps() {
84+
return true;
85+
}
86+
7887
/**
7988
* @return URI to the endpoint
8089
*/

src/main/java/com/recombee/api_client/api_requests/DeleteItemProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class DeleteItemProperty extends Request {
2626
*/
2727
public DeleteItemProperty (String propertyName) {
2828
this.propertyName = propertyName;
29-
this.timeout = 1000;
29+
this.timeout = 100000;
3030
}
3131

3232

src/main/java/com/recombee/api_client/api_requests/DeleteUserProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class DeleteUserProperty extends Request {
2626
*/
2727
public DeleteUserProperty (String propertyName) {
2828
this.propertyName = propertyName;
29-
this.timeout = 1000;
29+
this.timeout = 100000;
3030
}
3131

3232

0 commit comments

Comments
 (0)