App42 Cloud API

PHP 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.

$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 = $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 user 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.

$userID = "Nick";
$itemID = "itemID";
$reviewComment = "reviewComment";
$reviewRating = 3;	
				
$review = $reviewService->createReview($userID,$itemID,$reviewComment,$reviewRating);  /*the Review object. */ 
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
$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 Exception with message as "Not Found" and the appErrorCode as "3100" and the details as "Reviews for the Item with Id '<itemId>' do not exist"

$itemId = "itemID";
							
try{
	$review = $reviewService->getReviewsByItem($itemId);
   }  
   catch(App42Exception $ex) 
{
	$appErrorCode = $ex->getAppErrorCode();
	$httpErrorCode = $ex->getHttpErrorCode();
	if(appErrorCode == 3100)
{
    // Handle here for Not Found (Reviews for the Item with Id '<itemId>' do not exist. )
}
    else if(appErrorCode == 1401){
    // handle here for Client is not authorized
}
    else if(appErrorCode == 1500){
    // handle here for Internal Server Error
}	
	$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.

function createReview($userID, $itemID, $reviewComment, $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:

This method throws following exception.
/*
3102 - BAD REQUEST - Reviews for the User with Id '<userId>' and Item with Id '<itemId>' already exists. 
*/ 		  
        
For more details click Exception
$userID = "Nick";
$itemID = "itemID";
$reviewComment = "reviewComment";
$reviewRating = 3;
						
$review = $reviewService->createReview($userID,$itemID,$reviewComment,$reviewRating); /*the Review object. */ 
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
$jsonResponse = $review->toString(); /* returns the response in JSON format. (as shown below)*/   
For more details click Exception
{
    "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"
                }
            }
        }
    }
}

function getAllReviews()

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:

This method throws following exception.
/*
3103 - NOT FOUND - Reviews do not exist.	
*/ 		  
        
For more details click Exception
$reviewList = $reviewService->getAllReviews(); /* returns the list of Review object. */ 
foreach( $reviewList as $review )
{
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
}
$jsonResponse = $reviewList->toString(); /* returns the response in JSON format. (as shown below)*/   
For more details click Exception
{
    "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": "itemIDs",
                        "reviewId": "c657fe7d-bce4-4585-afe1-4eb18c557a28",
                        "status": "UNMUTED",
                        "comment": "reviewComment",
                        "rating": 3,
                        "createdOn": "2012-05-08T13:22:11.000Z"
                    },
                    {
                        "userId": "Nick",
                        "itemId": "itemIDs",
                        "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"
                    }
                ]
            }
        }
    }
}

function 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

Exception:

This method throws following exception.
/*
3103 - NOT FOUND - Reviews do not exist.	
*/ 		  
        
For more details click Exception
$response = $reviewService->getAllReviewsCount(); /* returns the App42Response objects. */
$success = $response->isResponseSuccess();
$totalRecords = $response->getTotalRecords();
$jsonResponse = $response->toString(); /* returns the response in JSON format. (as shown below)*/    
For more details click Exception
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}

$getAllReviews($max, $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: Review Object

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
$max = 1;
$offset = 0;
						
$reviewList = $reviewService->getAllReviews($max,$offset); /* returns the list of Review object. */ 
foreach($reviewList as $review)
{
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
}
$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"
                    }
                ]
            }
        }
    }
}
function getReviewByItem($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: ArrayList<Review> Object

Exception:

This method throws following exception.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		  
        
For more details click Exception
$itemId = "itemID";						
$reviewList = $reviewService->getReviewByItem($itemId); /* returns the list of Review object. */ 

foreach( $reviewList as $review )
{
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
}
$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"
                    }
                ]
            }
        }
    }
}
function getReviewsCountByItem($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

Exception:

This method throws following exception.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		  
        
For more details click Exception
$itemId = "ItemID";	
					
$response = $reviewService->getReviewsCountByItem($itemId); /* returns the App42Response objects. */
$success = $response->isResponseSuccess();
$totalRecords = $response->getTotalRecords();
$jsonResponse = $response->toString(); /* returns the response in JSON format. (as shown below)*/          
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
function getReviewByItem($itemId, $max, $offset)

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: Review Object

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>'.
*/ 		  
        
div class="exc">
For more details click Exception
$itemId = "ItemID";
$max = 1;	
$offset = 0;	
		
$reviewList = $reviewService->getReviewByItem($itemId,$max,$offset); /* returns the list of Review object. */ 
foreach($reviewList as $review)
{
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
}
$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"
                }
            }
        }
    }
}
function getAverageReviewByItem($itemId)

Fetches All Reviews by 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:

This method throws following exception.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		  
        
For more details click Exception
$itemId = "itemID";
						
$review = $reviewService->getAverageReviewByItem($itemId); /*the Review object. */ 
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
$jsonResponse = $review->toString(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "itemId": "itemID",
                    "rating": 4.108108
                }
            }
        }
    }
}
function getHighestReviewByItem($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:

This method throws following exception.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		  
        
For more details click Exception
$itemId = "itemID";
						
$review = $reviewService->getHighestReviewByItem($itemId); /*the Review object. */ 
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
$jsonResponse = $review->toString(); /* returns the response in JSON format. (as shown below)*/   
For more details click Exception
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "itemId": "itemID",
                    "rating": 5
                }
            }
        }
    }
}
function getLowestReviewByItem($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:

This method throws following exception.
/*
3100 - NOT FOUND - Reviews for the Item with Id '<itemId>' do not exist.
*/ 		  
        
For more details click Exception
$itemId = "itemID";
					
$review = $reviewService->getLowestReviewByItem($itemId); /*the Review object. */ 
print_r("userId is" . $review->getUserId());  
print_r("itemId is" . $review->getItemId()); 
print_r("comment is" . $review->getComment()); 
print_r("rating is" . $review->getRating()); 
$jsonResponse = $review->toString(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "itemId": "itemID",
                    "rating": 3
                }
            }
        }
    }
}
function mute($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:

This method throws following exception.
/*
3101 - NOT FOUND - Review with the Id '<reviewId>' does not exist. 
*/ 		  
        
For more details click Exception
$reviewId = "430cc684-de35-4595-aa38-23c99bda18fc";						
$response = $reviewService->mute($reviewId); /* returns the App42Response object. */
$success = $response->isResponseSuccess();
$jsonResponse = $response->toString(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "reviewId": "430cc684-de35-4595-aa38-23c99bda18fc"
                }
            }
        }
    }
}
function unmute($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:

This method throws following exception.
/*
3101 - NOT FOUND - Review with the Id '<reviewId>' does not exist. 
*/ 		  
        
For more details click Exception
$reviewId = "430cc684-de35-4595-aa38-23c99bda18fc";						
$response = $reviewService->mute($reviewId); /* returns the App42Response object. */
$success = $response->isResponseSuccess();
$jsonResponse = $response->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "reviews": {
                "review": {
                    "reviewId": "430cc684-de35-4595-aa38-23c99bda18fc"
                }
            }
        }
    }
}