The service is a Review & Rating manager for any item. The item can be anything which has an id e.g. App on a AppStore/Marketplace, items in a catalogue, articles, blogs etc. It manages the comments and its associated rating. It also provides methods to fetch average, highest etc. reviews. Reviews can be also be muted or unmuted if it has any objectionable content.
In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.
ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");
After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of ReviewService, buildReviewService() method needs to be called.
ReviewService reviewService = api.buildReviewService();
Once the API instance has been retrieved, You are ready to use the functions available for that particular API.
The methods available under a particular API will return the domain object (like Review in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.
String userID = "Nick";
String itemID = "itemID";
String reviewComment = "reviewComment";
double reviewRating = 3;
Review review = reviewService.createReview(userID,itemID,reviewComment,reviewRating); /* returns the Review object. */
System.out.println("userId is " + review.getUserId());
System.out.println("itemId is " + review.getItemId());
System.out.println("comment is " + review.getComment());
System.out.println("rating is " + review.getRating());
String jsonResponse = review.toString(); /* returns the response in JSON format. */
The functions available under Review/Rating API can throw some exceptions in abnormal conditions. Example of the same has been given below.
E.g. If App developer is requesting for a Review for the item Id which is not in database, the function will throw the App42Exception (as shown below) with message as "Not Found" and the appErrorCode as "3100" and the details as "Reviews for the Item with Id '<itemId>' do not exist".
String itemId = "itemID";
try
{
Review review = reviewService.getReviewsByItem(itemId);
}
catch(App42Exception ex)
{
int appErrorCode = ex.getAppErrorCode();
int httpErrorCode = ex.getHttpErrorCode();
if(appErrorCode == 3100)
{
// Handle here for Not Found (Reviews for the Item with Id '' do not exist.)
}
else if(appErrorCode == 1401)
{
// handle here for Client is not authorized
}
else if(appErrorCode == 1500)
{
// handle here for Internal Server Error
}
String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
}
{
"app42Fault": {
"httpErrorCode": 404,
"appErrorCode": 3100,
"message": "Not Found",
"details": "Reviews for the Item Id 'itemId' does not Exists"
}
}
Below are the HTTP Error Codes and their description, the function under the Review/Rating API can throw.
/* 1400 - BAD REQUEST - The Request parameters are invalid 1401 - UNAUTHORIZED - Client is not authorized 1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again */
Below are the Application Error Codes and their description, the function under the Review/Rating API can throw.
/* 3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist. 3101 - NOT FOUND - Review with the Id '<reviewId>' does not exist. 3102 - BAD REQUEST - Reviews for the User with Id '<userId>' and Item with Id '<itemId>' already exists. 3103 - NOT FOUND - Reviews do not exist. 3104 - NOT FOUND - The number of reviews are less than the specified offset : <offset>. 3105 - NOT FOUND - The number of reviews for the Item with Id '<itemId>' are less than the specified offset : <offset>. */
Various functions available under Review/Rating API has been explained below.
Creates review for the specified item on the cloud.
Parameters:
Returns:
Response: Review Object
Exception:
/* 3102 - BAD REQUEST - Reviews for the User with Id '<userId>' and Item with Id '<itemId>' already exists. */
String userID = "Nick";
String itemID = "itemID";
String reviewComment = "reviewComment";
double reviewRating = 3;
Review review = reviewService.createReview(userID,itemID,reviewComment,reviewRating); /* returns the Review object. */
System.out.println("userId is " + review.getUserId());
System.out.println("itemId is " + review.getItemId());
System.out.println("comment is " + review.getComment());
System.out.println("rating is " + review.getRating());
String jsonResponse = review.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": {
"userId": "Nick",
"itemId": "itemID",
"reviewId": "84faa1fe-f67d-47a5-8849-df61e96bf3eb",
"comment": "reviewComment",
"rating": 3,
"createdOn": "2012-05-08T13:21:10.266Z"
}
}
}
}
}
Fetches all reviews for the App.
Parameters:
Returns:
Response: ArrayList<Review> Object
Exception:
/* 3103 - NOT FOUND - Reviews do not exist. */
ArrayList<Review> reviewList = reviewService.getAllReviews(); /* returns the list of Review object. */
for(Review review : reviewList)
{
System.out.println("userId is " + review.getUserId());
System.out.println("itemId is " + review.getItemId());
System.out.println("comment is " + review.getComment());
System.out.println("rating is " + review.getRating());
}
String jsonResponse = reviewList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": [
{
"userId": "Nick",
"itemId": "itemID",
"reviewId": "84faa1fe-f67d-47a5-8849-df61e96bf3eb",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 3,
"createdOn": "2012-05-08T13:21:10.000Z"
},
{
"userId": "BOB",
"itemId": "itemID",
"reviewId": "c657fe7d-bce4-4585-afe1-4eb18c557a28",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 3,
"createdOn": "2012-05-08T13:22:11.000Z"
},
{
"userId": "Nick",
"itemId": "itemID",
"reviewId": "e371aefa-0753-43df-a18c-fa8850ce3b96",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 3,
"createdOn": "2012-05-08T13:22:50.000Z"
},
{
"userId": "Nick",
"itemId": "itemID",
"reviewId": "2d2753f1-cdb7-454b-8a52-ac6a163515fa",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 3,
"createdOn": "2012-05-08T13:23:24.000Z"
},
{
"userId": "Jill",
"itemId": "ItemID",
"reviewId": "037d06f9-f2c2-43dd-887f-d5ba2101a981",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 5,
"createdOn": "2012-05-08T13:24:19.000Z"
}
]
}
}
}
}
Fetches count of all reviews for the App.
Parameters:
Returns:
Response:App42Response Object
App42Response response = reviewService.getAllReviewsCount(); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}
Fetches all reviews for the App by Paging.
Parameters:
Returns:
Response: ArrayList<Review> Object
Exception:
/* 3104 - NOT FOUND - The number of reviews are less than the specified offset : <offset>. */
int max = 1;
int offset = 0;
ArrayList<Review> reviewList = reviewService.getAllReviews(max,offset); /* returns the list of Review object. */
for(Review review : reviewList)
{
System.out.println("userId is " + review.getUserId());
System.out.println("itemId is " + review.getItemId());
System.out.println("comment is " + review.getComment());
System.out.println("rating is " + review.getRating());
}
String jsonResponse = reviewList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": [
{
"userId": "Nick",
"itemId": "ItemID",
"reviewId": "f3c93a6f-c784-4108-83a9-76163c1ae2c6",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 5,
"createdOn": "2012-06-02T13:24:36.000Z"
},
{
"userId": "BOB",
"itemId": "ItemID",
"reviewId": "3fee9765-d0e9-49fb-a109-8d705e343a3b",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 5,
"createdOn": "2012-06-02T13:24:40.000Z"
}
]
}
}
}
}
Fetches All Reviews based on the itemId.
Parameters:
Returns:
Response: ArrayList<Review> Object
Exception:
/* 3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist. */
String itemId = "itemID";
ArrayList<Review> reviewList = reviewService.getReviewsByItem(itemId); /* returns the list of Review object. */
for(Review review : reviewList)
{
System.out.println("userId is " + review.getUserId());
System.out.println("itemId is " + review.getItemId());
System.out.println("comment is " + review.getComment());
System.out.println("rating is " + review.getRating());
}
String jsonResponse = reviewList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": [
{
"userId": "Nick",
"itemId": "itemID",
"reviewId": "84faa1fe-f67d-47a5-8849-df61e96bf3eb",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 3,
"createdOn": "2012-05-08T13:21:10.000Z"
},
{
"userId": "BOB",
"itemId": "itemID",
"reviewId": "2d2753f1-cdb7-454b-8a52-ac6a163515fa",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 3,
"createdOn": "2012-05-08T13:23:24.000Z"
},
{
"userId": "Alquert",
"itemId": "ItemID",
"reviewId": "037d06f9-f2c2-43dd-887f-d5ba2101a981",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 5,
"createdOn": "2012-05-08T13:24:19.000Z"
},
{
"userId": "Alquert",
"itemId": "itemID",
"reviewId": "a6072c3d-5003-44cf-92ff-264c3f424b3b",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 4,
"createdOn": "2012-05-08T13:26:40.000Z"
}
]
}
}
}
}
Fetches count of All Reviews based on the itemId
Parameters:
Returns:
Response: App42Response Object
String itemId = "ItemID"; App42Response response = reviewService.getReviewsCountByItem(itemId); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}
Fetches All Reviews based on the itemId by Paging
Parameters:
Returns:
Response: ArrayList<Review> Object
Exception:
/* 3105 - NOT FOUND - The number of reviews for the Item with Id '<itemId>' are less than the specified offset : <offset>. */
String itemId = "ItemID";
int max = 1;
int offset = 0;
ArrayList<Review> reviewList = reviewService.getReviewsByItem(itemId,max,offset); /* returns the list of Review object. */
for(Review review : reviewList)
{
System.out.println("userId is " + review.getUserId());
System.out.println("itemId is " + review.getItemId());
System.out.println("comment is " + review.getComment());
System.out.println("rating is " + review.getRating());
}
String jsonResponse = reviewList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": {
"userId": "Nick",
"itemId": "ItemID",
"reviewId": "54828228-b629-49b6-860c-b9c12021a52f",
"status": "UNMUTED",
"comment": "reviewComment",
"rating": 5,
"createdOn": "2012-06-02T13:23:03.000Z"
}
}
}
}
}
Fetches the average review for the specified itemId.
Parameters:
Returns:
Response: Review Object
Exception:
/* 3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist. */
String itemId = "itemID";
Review review = reviewService.getAverageReviewByItem(itemId); /* returns the Review object. */
System.out.println("itemId is " + review.getItemId());
System.out.println("rating is " + review.getRating());
String jsonResponse = review.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": {
"itemId": "itemID",
"rating": 4.108108
}
}
}
}
}
Fetches the highest review for the specified itemId.
Parameters:
Returns:
Response: Review Object
Exception:
/* 3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist. */
String itemId = "itemID";
Review review = reviewService.getHighestReviewByItem(itemId); /* returns the Review object. */
System.out.println("itemId is " + review.getItemId());
System.out.println("rating is " + review.getRating());
String jsonResponse = review.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": {
"itemId": "itemID",
"rating": 5
}
}
}
}
}
Fetches the lowest review for the specified itemId.
Parameters:
Returns:
Response: Review Object
Exception:
/* 3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist. */
String itemId = "itemID";
Review review = reviewService.getLowestReviewByItem(itemId); /* returns the Review object. */
System.out.println("itemId is " + review.getItemId());
System.out.println("rating is " + review.getRating());
String jsonResponse = review.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": {
"itemId": "itemID",
"rating": 3
}
}
}
}
}
Mutes the specified review.
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist. */
String reviewId = "430cc684-de35-4595-aa38-23c99bda18fc"; App42Response response = reviewService.mute(reviewId); /* returns the App42Response object. */ boolean success = response.isResponseSuccess(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": {
"reviewId": "430cc684-de35-4595-aa38-23c99bda18fc"
}
}
}
}
}
UnMutes the specified review.
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 3101 - NOT FOUND - Review with the Id '<reviewId>' does not exist. */
String reviewId = "430cc684-de35-4595-aa38-23c99bda18fc"; App42Response response = reviewService.unmute(reviewId); /* returns the App42Response object. */ boolean success = response.isResponseSuccess(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"reviews": {
"review": {
"reviewId": "430cc684-de35-4595-aa38-23c99bda18fc"
}
}
}
}
}