Skip to content

Commit

Permalink
Added support for view portions
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraFiedler committed Sep 18, 2017
1 parent 1663be0 commit 7609085
Show file tree
Hide file tree
Showing 17 changed files with 879 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The client is available in the [Maven Central Repository](https://mvnrepository.
<dependency>
<groupId>com.recombee</groupId>
<artifactId>api-client</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.recombee</groupId>
<artifactId>api-client</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<name>Recombee API Client</name>
<description>A client library for easy use of the Recombee recommendation API</description>
<url>http://recombee.com</url>
Expand Down
40 changes: 39 additions & 1 deletion src/main/java/com/recombee/api_client/RecombeeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import com.recombee.api_client.api_requests.ListUserCartAdditions;
import com.recombee.api_client.api_requests.ListItemBookmarks;
import com.recombee.api_client.api_requests.ListUserBookmarks;
import com.recombee.api_client.api_requests.ListItemViewPortions;
import com.recombee.api_client.api_requests.ListUserViewPortions;
import com.recombee.api_client.api_requests.UserBasedRecommendation;
import com.recombee.api_client.api_requests.ItemBasedRecommendation;

Expand All @@ -77,7 +79,7 @@ public class RecombeeClient {

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

final String USER_AGENT = "recombee-java-api-client/1.4.0";
final String USER_AGENT = "recombee-java-api-client/1.5.0";

public RecombeeClient(String databaseId, String token) {
this.databaseId = databaseId;
Expand Down Expand Up @@ -278,6 +280,26 @@ public Bookmark[] send(ListUserBookmarks request) throws ApiException {
return null;
}

public ViewPortion[] send(ListItemViewPortions request) throws ApiException {
String responseStr = sendRequest(request);
try {
return this.mapper.readValue(responseStr, ViewPortion[].class);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

public ViewPortion[] send(ListUserViewPortions request) throws ApiException {
String responseStr = sendRequest(request);
try {
return this.mapper.readValue(responseStr, ViewPortion[].class);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

/* End of the generated code */

public BatchResponse[] send(Batch batchRequest) throws ApiException {
Expand Down Expand Up @@ -502,6 +524,22 @@ else if (request instanceof ListUserBookmarks)
for(int j=0;j<ar.length;j++) ar[j] = new Bookmark(array.get(j));
parsedResponse = ar;
}

else if (request instanceof ListItemViewPortions)
{
ArrayList<Map<String, Object>> array = (ArrayList<Map<String, Object>>) parsedResponse;
ViewPortion[] ar = new ViewPortion[array.size()];
for(int j=0;j<ar.length;j++) ar[j] = new ViewPortion(array.get(j));
parsedResponse = ar;
}

else if (request instanceof ListUserViewPortions)
{
ArrayList<Map<String, Object>> array = (ArrayList<Map<String, Object>>) parsedResponse;
ViewPortion[] ar = new ViewPortion[array.size()];
for(int j=0;j<ar.length;j++) ar[j] = new ViewPortion(array.get(j));
parsedResponse = ar;
}
/* End of the generated code */
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.recombee.api_client.api_requests;

/*
This file is auto-generated, do not edit
*/

import java.util.Date;
import java.util.Map;
import java.util.HashMap;

import com.recombee.api_client.util.HTTPMethod;

/**
* The view portions feature is currently experimental.
* Deletes an existing view portion specified by (`userId`, `itemId`, `sessionId`) from the database.
*/
public class DeleteViewPortion extends Request {

/**
* ID of the user who rated the item.
*/
protected String userId;
/**
* ID of the item which was rated.
*/
protected String itemId;
/**
* Identifier of a session.
*/
protected String sessionId;

/**
* Construct the request
* @param userId ID of the user who rated the item.
* @param itemId ID of the item which was rated.
*/
public DeleteViewPortion (String userId,String itemId) {
this.userId = userId;
this.itemId = itemId;
this.timeout = 1000;
}

/**
* @param sessionId Identifier of a session.
*/
public DeleteViewPortion setSessionId(String sessionId) {
this.sessionId = sessionId;
return this;
}

public String getUserId() {
return this.userId;
}

public String getItemId() {
return this.itemId;
}

public String getSessionId() {
return this.sessionId;
}

/**
* @return Used HTTP method
*/
@Override
public HTTPMethod getHTTPMethod() {
return HTTPMethod.DELETE;
}

/**
* @return URI to the endpoint including path parameters
*/
@Override
public String getPath() {
return "/viewportions/";
}

/**
* Get query parameters
* @return Values of query parameters (name of parameter: value of the parameter)
*/
@Override
public Map<String, Object> getQueryParameters() {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("userId", this.userId.toString());
params.put("itemId", this.itemId.toString());
if (this.sessionId!=null) {
params.put("sessionId", this.sessionId.toString());
}
return params;
}

/**
* Get body parameters
* @return Values of body parameters (name of parameter: value of the parameter)
*/
@Override
public Map<String, Object> getBodyParameters() {
HashMap<String, Object> params = new HashMap<String, Object>();
return params;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.recombee.api_client.api_requests;

/*
This file is auto-generated, do not edit
*/

import java.util.Date;
import java.util.Map;
import java.util.HashMap;

import com.recombee.api_client.util.HTTPMethod;

/**
* The view portions feature is currently experimental.
* List all the view portions of an item ever submitted by different users.
*/
public class ListItemViewPortions extends Request {

/**
* ID of the item of which the view portions are to be listed.
*/
protected String itemId;

/**
* Construct the request
* @param itemId ID of the item of which the view portions are to be listed.
*/
public ListItemViewPortions (String itemId) {
this.itemId = itemId;
this.timeout = 100000;
}


public String getItemId() {
return this.itemId;
}

/**
* @return Used HTTP method
*/
@Override
public HTTPMethod getHTTPMethod() {
return HTTPMethod.GET;
}

/**
* @return URI to the endpoint including path parameters
*/
@Override
public String getPath() {
return String.format("/items/%s/viewportions/", this.itemId);
}

/**
* Get query parameters
* @return Values of query parameters (name of parameter: value of the parameter)
*/
@Override
public Map<String, Object> getQueryParameters() {
HashMap<String, Object> params = new HashMap<String, Object>();
return params;
}

/**
* Get body parameters
* @return Values of body parameters (name of parameter: value of the parameter)
*/
@Override
public Map<String, Object> getBodyParameters() {
HashMap<String, Object> params = new HashMap<String, Object>();
return params;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.recombee.api_client.api_requests;

/*
This file is auto-generated, do not edit
*/

import java.util.Date;
import java.util.Map;
import java.util.HashMap;

import com.recombee.api_client.util.HTTPMethod;

/**
* The view portions feature is currently experimental.
* List all the view portions ever submitted by a given user.
*/
public class ListUserViewPortions extends Request {

/**
* ID of the user whose view portions are to be listed.
*/
protected String userId;

/**
* Construct the request
* @param userId ID of the user whose view portions are to be listed.
*/
public ListUserViewPortions (String userId) {
this.userId = userId;
this.timeout = 100000;
}


public String getUserId() {
return this.userId;
}

/**
* @return Used HTTP method
*/
@Override
public HTTPMethod getHTTPMethod() {
return HTTPMethod.GET;
}

/**
* @return URI to the endpoint including path parameters
*/
@Override
public String getPath() {
return String.format("/users/%s/viewportions/", this.userId);
}

/**
* Get query parameters
* @return Values of query parameters (name of parameter: value of the parameter)
*/
@Override
public Map<String, Object> getQueryParameters() {
HashMap<String, Object> params = new HashMap<String, Object>();
return params;
}

/**
* Get body parameters
* @return Values of body parameters (name of parameter: value of the parameter)
*/
@Override
public Map<String, Object> getBodyParameters() {
HashMap<String, Object> params = new HashMap<String, Object>();
return params;
}

}
Loading

0 comments on commit 7609085

Please sign in to comment.