Skip to content

Commit 7609085

Browse files
committed
Added support for view portions
1 parent 1663be0 commit 7609085

17 files changed

+879
-4
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.4.0</version>
16+
<version>1.5.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.4.0</version>
9+
<version>1.5.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: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import com.recombee.api_client.api_requests.ListUserCartAdditions;
6060
import com.recombee.api_client.api_requests.ListItemBookmarks;
6161
import com.recombee.api_client.api_requests.ListUserBookmarks;
62+
import com.recombee.api_client.api_requests.ListItemViewPortions;
63+
import com.recombee.api_client.api_requests.ListUserViewPortions;
6264
import com.recombee.api_client.api_requests.UserBasedRecommendation;
6365
import com.recombee.api_client.api_requests.ItemBasedRecommendation;
6466

@@ -77,7 +79,7 @@ public class RecombeeClient {
7779

7880
final int BATCH_MAX_SIZE = 10000; //Maximal number of requests within one batch request
7981

80-
final String USER_AGENT = "recombee-java-api-client/1.4.0";
82+
final String USER_AGENT = "recombee-java-api-client/1.5.0";
8183

8284
public RecombeeClient(String databaseId, String token) {
8385
this.databaseId = databaseId;
@@ -278,6 +280,26 @@ public Bookmark[] send(ListUserBookmarks request) throws ApiException {
278280
return null;
279281
}
280282

283+
public ViewPortion[] send(ListItemViewPortions request) throws ApiException {
284+
String responseStr = sendRequest(request);
285+
try {
286+
return this.mapper.readValue(responseStr, ViewPortion[].class);
287+
} catch (IOException e) {
288+
e.printStackTrace();
289+
}
290+
return null;
291+
}
292+
293+
public ViewPortion[] send(ListUserViewPortions request) throws ApiException {
294+
String responseStr = sendRequest(request);
295+
try {
296+
return this.mapper.readValue(responseStr, ViewPortion[].class);
297+
} catch (IOException e) {
298+
e.printStackTrace();
299+
}
300+
return null;
301+
}
302+
281303
/* End of the generated code */
282304

283305
public BatchResponse[] send(Batch batchRequest) throws ApiException {
@@ -502,6 +524,22 @@ else if (request instanceof ListUserBookmarks)
502524
for(int j=0;j<ar.length;j++) ar[j] = new Bookmark(array.get(j));
503525
parsedResponse = ar;
504526
}
527+
528+
else if (request instanceof ListItemViewPortions)
529+
{
530+
ArrayList<Map<String, Object>> array = (ArrayList<Map<String, Object>>) parsedResponse;
531+
ViewPortion[] ar = new ViewPortion[array.size()];
532+
for(int j=0;j<ar.length;j++) ar[j] = new ViewPortion(array.get(j));
533+
parsedResponse = ar;
534+
}
535+
536+
else if (request instanceof ListUserViewPortions)
537+
{
538+
ArrayList<Map<String, Object>> array = (ArrayList<Map<String, Object>>) parsedResponse;
539+
ViewPortion[] ar = new ViewPortion[array.size()];
540+
for(int j=0;j<ar.length;j++) ar[j] = new ViewPortion(array.get(j));
541+
parsedResponse = ar;
542+
}
505543
/* End of the generated code */
506544
}
507545

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.recombee.api_client.api_requests;
2+
3+
/*
4+
This file is auto-generated, do not edit
5+
*/
6+
7+
import java.util.Date;
8+
import java.util.Map;
9+
import java.util.HashMap;
10+
11+
import com.recombee.api_client.util.HTTPMethod;
12+
13+
/**
14+
* The view portions feature is currently experimental.
15+
* Deletes an existing view portion specified by (`userId`, `itemId`, `sessionId`) from the database.
16+
*/
17+
public class DeleteViewPortion extends Request {
18+
19+
/**
20+
* ID of the user who rated the item.
21+
*/
22+
protected String userId;
23+
/**
24+
* ID of the item which was rated.
25+
*/
26+
protected String itemId;
27+
/**
28+
* Identifier of a session.
29+
*/
30+
protected String sessionId;
31+
32+
/**
33+
* Construct the request
34+
* @param userId ID of the user who rated the item.
35+
* @param itemId ID of the item which was rated.
36+
*/
37+
public DeleteViewPortion (String userId,String itemId) {
38+
this.userId = userId;
39+
this.itemId = itemId;
40+
this.timeout = 1000;
41+
}
42+
43+
/**
44+
* @param sessionId Identifier of a session.
45+
*/
46+
public DeleteViewPortion setSessionId(String sessionId) {
47+
this.sessionId = sessionId;
48+
return this;
49+
}
50+
51+
public String getUserId() {
52+
return this.userId;
53+
}
54+
55+
public String getItemId() {
56+
return this.itemId;
57+
}
58+
59+
public String getSessionId() {
60+
return this.sessionId;
61+
}
62+
63+
/**
64+
* @return Used HTTP method
65+
*/
66+
@Override
67+
public HTTPMethod getHTTPMethod() {
68+
return HTTPMethod.DELETE;
69+
}
70+
71+
/**
72+
* @return URI to the endpoint including path parameters
73+
*/
74+
@Override
75+
public String getPath() {
76+
return "/viewportions/";
77+
}
78+
79+
/**
80+
* Get query parameters
81+
* @return Values of query parameters (name of parameter: value of the parameter)
82+
*/
83+
@Override
84+
public Map<String, Object> getQueryParameters() {
85+
HashMap<String, Object> params = new HashMap<String, Object>();
86+
params.put("userId", this.userId.toString());
87+
params.put("itemId", this.itemId.toString());
88+
if (this.sessionId!=null) {
89+
params.put("sessionId", this.sessionId.toString());
90+
}
91+
return params;
92+
}
93+
94+
/**
95+
* Get body parameters
96+
* @return Values of body parameters (name of parameter: value of the parameter)
97+
*/
98+
@Override
99+
public Map<String, Object> getBodyParameters() {
100+
HashMap<String, Object> params = new HashMap<String, Object>();
101+
return params;
102+
}
103+
104+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.recombee.api_client.api_requests;
2+
3+
/*
4+
This file is auto-generated, do not edit
5+
*/
6+
7+
import java.util.Date;
8+
import java.util.Map;
9+
import java.util.HashMap;
10+
11+
import com.recombee.api_client.util.HTTPMethod;
12+
13+
/**
14+
* The view portions feature is currently experimental.
15+
* List all the view portions of an item ever submitted by different users.
16+
*/
17+
public class ListItemViewPortions extends Request {
18+
19+
/**
20+
* ID of the item of which the view portions are to be listed.
21+
*/
22+
protected String itemId;
23+
24+
/**
25+
* Construct the request
26+
* @param itemId ID of the item of which the view portions are to be listed.
27+
*/
28+
public ListItemViewPortions (String itemId) {
29+
this.itemId = itemId;
30+
this.timeout = 100000;
31+
}
32+
33+
34+
public String getItemId() {
35+
return this.itemId;
36+
}
37+
38+
/**
39+
* @return Used HTTP method
40+
*/
41+
@Override
42+
public HTTPMethod getHTTPMethod() {
43+
return HTTPMethod.GET;
44+
}
45+
46+
/**
47+
* @return URI to the endpoint including path parameters
48+
*/
49+
@Override
50+
public String getPath() {
51+
return String.format("/items/%s/viewportions/", this.itemId);
52+
}
53+
54+
/**
55+
* Get query parameters
56+
* @return Values of query parameters (name of parameter: value of the parameter)
57+
*/
58+
@Override
59+
public Map<String, Object> getQueryParameters() {
60+
HashMap<String, Object> params = new HashMap<String, Object>();
61+
return params;
62+
}
63+
64+
/**
65+
* Get body parameters
66+
* @return Values of body parameters (name of parameter: value of the parameter)
67+
*/
68+
@Override
69+
public Map<String, Object> getBodyParameters() {
70+
HashMap<String, Object> params = new HashMap<String, Object>();
71+
return params;
72+
}
73+
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.recombee.api_client.api_requests;
2+
3+
/*
4+
This file is auto-generated, do not edit
5+
*/
6+
7+
import java.util.Date;
8+
import java.util.Map;
9+
import java.util.HashMap;
10+
11+
import com.recombee.api_client.util.HTTPMethod;
12+
13+
/**
14+
* The view portions feature is currently experimental.
15+
* List all the view portions ever submitted by a given user.
16+
*/
17+
public class ListUserViewPortions extends Request {
18+
19+
/**
20+
* ID of the user whose view portions are to be listed.
21+
*/
22+
protected String userId;
23+
24+
/**
25+
* Construct the request
26+
* @param userId ID of the user whose view portions are to be listed.
27+
*/
28+
public ListUserViewPortions (String userId) {
29+
this.userId = userId;
30+
this.timeout = 100000;
31+
}
32+
33+
34+
public String getUserId() {
35+
return this.userId;
36+
}
37+
38+
/**
39+
* @return Used HTTP method
40+
*/
41+
@Override
42+
public HTTPMethod getHTTPMethod() {
43+
return HTTPMethod.GET;
44+
}
45+
46+
/**
47+
* @return URI to the endpoint including path parameters
48+
*/
49+
@Override
50+
public String getPath() {
51+
return String.format("/users/%s/viewportions/", this.userId);
52+
}
53+
54+
/**
55+
* Get query parameters
56+
* @return Values of query parameters (name of parameter: value of the parameter)
57+
*/
58+
@Override
59+
public Map<String, Object> getQueryParameters() {
60+
HashMap<String, Object> params = new HashMap<String, Object>();
61+
return params;
62+
}
63+
64+
/**
65+
* Get body parameters
66+
* @return Values of body parameters (name of parameter: value of the parameter)
67+
*/
68+
@Override
69+
public Map<String, Object> getBodyParameters() {
70+
HashMap<String, Object> params = new HashMap<String, Object>();
71+
return params;
72+
}
73+
74+
}

0 commit comments

Comments
 (0)