App42 Cloud API

Android Cloud SDK

Review/Rating

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.

public Review createReview(String userID, String itemID, String reviewComment, double reviewRating)throws App42Exception

Creates review for the specified item on the cloud.

Parameters:

userID - The user who has created the review
itemID - The item for which the review has to be created
reviewComment - The review comment
reviewRating - Review rating in double

Returns:

Review object containing the review which has been created

Response: Review Object

Exception:

The method throws the following exception with the error code.
/*
3102 - BAD REQUEST - Reviews for the User with Id '<userId>' and Item with Id '<itemId>' already exists.
*/ 	        
For more details click Exception
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"
                }
            }
        }
    }
}
public ArrayList<Review> getAllReviews() throws App42Exception

Fetches all reviews for the App.

Parameters:

N/A

Returns:

List of Review object containing all the reviews for the App

Response: ArrayList<Review> Object

Exception:

The method throws the following exception with the error code.
/*
3103 - NOT FOUND - Reviews do not exist.
*/ 		       
For more details click Exception
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"
                    }
                ]
            }
        }
    }
}
public App42Response getAllReviewsCount() throws App42Exception

Fetches count of all reviews for the App.

Parameters:

N/A

Returns:

App42Response containing count of all the reviews for the App

Response:App42Response Object

Exception:

The method throws the following exception with the error code.
/*
3103 - NOT FOUND - Reviews do not exist.
*/ 	        
For more details click Exception
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
        }
    }
}
public ArrayList<Review> getAllReviews(int max, int offset) throws App42Exception

Fetches all reviews for the App by Paging.

Parameters:

max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

List of Review object containing all the reviews for the App

Response: ArrayList<Review> Object

Exception:

The method throws the following exception with the error code.
/*
3104 - NOT FOUND - The number of reviews are less than the specified offset : <offset>.
*/ 		        
For more details click Exception
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"
                    }
                ]
            }
        }
    }
}
public ArrayList<Review> getReviewsByItem(String itemId) throws App42Exception

Fetches All Reviews based on the itemId.

Parameters:

itemId - The item for which reviews have to be fetched

Returns:

List of Review object containing all the reviews for a item

Response: ArrayList<Review> Object

Exception:

The method throws the following exception with the error code.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		       
For more details click Exception
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"
                    }
                ]
            }
        }
    }
}
public App42Response getReviewsCountByItem(String itemId) throws App42Exception

Fetches count of All Reviews based on the itemId

Parameters:

itemId - The item for which count of reviews have to be fetched

Returns:

App42Response containing count of all the reviews for a item

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		       
For more details click Exception
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
        }
    }
}
public ArrayList<Review> getReviewByItem(String itemId, int max, int offset) throws App42Exception

Fetches All Reviews based on the itemId by Paging

Parameters:

itemId - The item for which reviews have to be fetched
max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

List of Review object containing all the reviews for a item

Response: ArrayList<Review> Object

Exception:

The method throws the following exception with the error code.
/*
3105 - NOT FOUND - The number of reviews for the Item with Id '<itemId>' are less than the specified offset : <offset>.
*/ 		        
For more details click Exception
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"
                }
            }
        }
    }
}
public Review getAverageReviewByItem(String itemId) throws App42Exception

Fetches the average review for the specified itemId.

Parameters:

itemId - The item for which reviews have to be fetched

Returns:

Review object containing the average review for a item

Response: Review Object

Exception:

The method throws the following exception with the error code.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 	        
For more details click Exception
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
                }
            }
        }
    }
}
public Review getHighestReviewByItem(String itemId) throws App42Exception

Fetches the highest review for the specified itemId.

Parameters:

itemId - The item for which the highest review has to be fetched

Returns:

Review object containing the highest review for a item

Response: Review Object

Exception:

The method throws the following exception with the error code.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		        
For more details click Exception
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
                }
            }
        }
    }
}
public Review getLowestReviewByItem(String itemId) throws App42Exception

Fetches the lowest review for the specified itemId.

Parameters:

itemId - The item for which the lowest review has to be fetched

Returns:

Review object containing the lowest review for a item

Response: Review Object

Exception:

The method throws the following exception with the error code.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		        
For more details click Exception
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
                }
            }
        }
    }
}
public App42Response mute(String reviewId)throws App42Exception

Mutes the specified review.

Parameters:

reviewId - The Id of the review which has to be muted

Returns:

App42Response if muted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		        
For more details click Exception
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"
                }
            }
        }
    }
}
public App42Response unmute(String reviewId)throws App42Exception

UnMutes the specified review.

Parameters:

reviewId - The Id of the review which has to be unmuted

Returns:

App42Response if unmuted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/*
3101 - NOT FOUND - Review with the Id '<reviewId>' does not exist.
*/ 		       
For more details click Exception
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"
                }
            }
        }
    }
}