App42 Cloud API

iOS 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 allocate and initialize an instance of ServiceAPI. After initialization, apiKey and secretKey needs to be set which has been received while creating an application under App42.

ServiceAPI *serviceAPIObj = [[ServiceAPI alloc]init];
serviceAPIObj.apiKey = @"<API_KEY>";
serviceAPIObj.secretKey = @"<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 = [serviceAPIObj 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.

NSString *userID = @"Nick";
NSString *itemID = @"itemID";
NSString *reviewComment = @"reviewComment";
double reviewRating = 3;

Review *review = [reviewService createReview:userId itemID:itemId reviewComment:reviewComment reviewRating:reviewRating]; /* returns the Review object. */
NSLog(@"userId =%@", review.userId);
NSLog(@"itemId =%@", review.itemId);
NSLog(@"comment=%@ ,review.comment);
NSLog(@"rating=%f , review.rating);
NSString *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 Id '{Id}' does not Exists".

NSString *itemId = @"itemID";
@try{
Review *review = [reviewService getReviewsByItem:itemId]; /* returns the Review object. */
} @catch(App42Exception *ex) {
int appErrorCode = ex.appErrorCode;
int httpErrorCode = ex.httpErrorCode;
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
	}
NSString *jsonText = ex.reason; /* returns the Exception text in JSON format. (as shown below)*/
}
                            
{
"app42Fault": {
"httpErrorCode": 404,
"appErrorCode": 3100,
"message": "Not Found",
"details": "Reviews for the Item Id '007' 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.

-(Review*)createReview:(NSString*)userId itemID:(NSString*)itemId reviewComment:(NSString*)reviewComment reviewRating:(double)reviewRating

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
NSString *userID = @"Nick";
NSString *itemID = @"itemID";
NSString *reviewComment = @"reviewComment";
double reviewRating = 3;					

Review *review = [reviewService createReview:userId itemID:itemId reviewComment:reviewComment reviewRating:reviewRating]; /* returns the Review object. */
NSLog(@"userId =%@", review.userId);
NSLog(@"itemId =%@", review.itemId);
NSLog(@"comment=%@ ,review.comment);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. */
                            
{
    "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"
                }
            }
        }
    }
}
-(NSArray*)getAllReviews

Fetches all reviews for the App.

Parameters:

N/A

Returns:

List of Review object containing all the reviews for the App

Response: NSArray

Exception:

The method throws the following exception with the error code.
/*
3103 - NOT FOUND - Reviews do not exist.
*/ 		       
For more details click Exception
NSArray *reviewList = [reviewService getAllReviews]; /* returns the list of Review object. */
for(Review *review in reviewList){
NSLog(@"userId =%@", review.userId);
NSLog(@"itemId =%@", review.itemId);
NSLog(@"comment=%@ ,review.comment);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. */
}

                            
{
    "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"
                    }
                ]
            }
        }
    }
}
-(App42Response*)getAllReviewsCount

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

For more details click Exception
App42Response *response = [reviewService getAllReviewsCount]; /* returns the App42Response objects. */
BOOL  success = response.isResponseSuccess;
int totalRecords = response.totalRecords;
NSString *jsonResponse = [response toString]; /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
-(NSArray*)getAllReviews:(int)max offset:(int)offset

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: NSArray

Exception:

This method throws following exception.
/*
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;						

NSArray *reviewList = [reviewService getAllReviews:max offset:offset]; /* returns the list of Review object. */ 
for(Review *review in reviewList)
{
   	NSLog(@"userId =%@", review.userId);
NSLog(@"itemId =%@", review.itemId);
NSLog(@"comment=%@ ,review.comment);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. */

}
{
    "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"
                    }
                ]
            }
        }
    }
}
-(NSArray*)getReviewByItem:(NSString*)itemId

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: NSArray

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
NSString *itemId = @"itemID";
NSArray *reviewList = [reviewService getReviewByItem:itemId]; /* returns the list of Review object. */
for(Review *review in reviewList){
NSLog(@"userId =%@", review.userId);
NSLog(@"itemId =%@", review.itemId);
NSLog(@"comment=%@ ,review.comment);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. */
}

                            
{
    "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"
                    }
                ]
            }
        }
    }
}
-(App42Response*)getReviewsCountByItem:(NSString*)itemId

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

For more details click Exception
NSString *itemId = @"ItemID";
						
App42Response *response = [reviewService getReviewsCountByItem:itemId]; /* returns the App42Response objects. */
BOOL success = response.isResponseSuccess;
int totalRecords = response.totalRecords;
NSString *jsonResponse = [response toString]; /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
-(NSArray*)getReviewsByItem:(NSString*)itemId max:(int)max offset:(int)offse

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: NSArray

Exception:

This method throws following exception.
/*
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
NSString *itemId = @"ItemID";
int max = 1;	
int offset = 0;						

NSArray *reviewList = [reviewService getReviewsByItem:itemId max:max offset:offset]; /* returns the list of Review object. */ 
for(Review *review in reviewList)
{
    NSLog(@"userId =%@", review.userId);
NSLog(@"itemId =%@", review.itemId);
NSLog(@"comment=%@ ,review.comment);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. */

}
     
{
    "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"
                }
            }
        }
    }
}
-(Review*)getAverageReviewByItem:(NSString*)itemId

Fetches All Reviews by itemId.

Parameters:

itemId - The item for which reviews have to be fetched

Returns:

The average review for a item

Response: Review Object

NSString *itemId = @"itemID";
Review *review = [reviewService getAverageReviewByItem:itemId]; /* returns the Review object. */
NSLog(@"userId =%@", review.userId);
NSLog(@"itemId =%@", review.itemId);
NSLog(@"comment=%@ ,review.comment);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. */
                            
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "itemId": "itemID",
                    "rating": 4.108108
                }
            }
        }
    }
}

-(Review*)getHighestReviewByItem:(NSString*)itemId

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
NSString *itemId = @"itemID";
Review *review = [reviewService getHighestReviewByItem:itemId]; /* returns the Review object. */
NSLog(@"itemId =%@", review.itemId);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "itemId": "itemID",
                    "rating": 5
                }
            }
        }
    }
}
-(Review*)getLowestReviewByItem:(NSString*)itemId

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
NSString *itemId = @"itemID";
Review *review = [reviewService getLowestReviewByItem:itemId]; /* returns the Review object. */
NSLog(@"itemId =%@", review.itemId);
NSLog(@"rating=%f , review.rating);
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "itemId": "itemID",
                    "rating": 3
                }
            }
        }
    }
}


-(App42Response*)mute:(NSString*)reviewId

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
NSString *reviewId = @"430cc684-de35-4595-aa38-23c99bda18fc";

App42Response *response = [reviewService mute:reviewId]; /* returns the App42Response object. */
NSString *success = response.isResponseSuccess;
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "reviewId": "430cc684-de35-4595-aa38-23c99bda18fc"
                }
            }
        }
    }
}

-(App42Response*)unmute:(NSString*)reviewId

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
NSString *reviewId = @"430cc684-de35-4595-aa38-23c99bda18fc";
App42Response *response = [reviewService unmute:reviewId]; /* returns the App42Response object. */
NSString *success = response.isResponseSuccess;
NSString *jsonResponse = [review toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "reviewId": "430cc684-de35-4595-aa38-23c99bda18fc"
                }
            }
        }
    }
}