App42 Cloud API

PHP cloud SDK

Gaming

The Game service allows Game, User, Score and ScoreBoard Management on the Cloud. The service allows Game Developer to create a Game and then do in Game Scoring using the Score service. It also allows to maintain a Scoreboard across game sessions using the ScoreBoard service. One can query for average or highest score for user for a Game and highest and average score across users for a Game. It also gives ranking of the user against other users for a particular game. The Reward and RewardPoints allows the Game Developer to assign rewards to a user and redeem the rewards. E.g. One can give Swords or Energy etc. The services Game, Score, ScoreBoard, Reward, RewardPoints can be used in Conjunction for complete Game Scoring and Reward Management.

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 GameService, buildGameService() method needs to be called.

$gameService = $api->buildGameService();

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

$gameName = "Game01";
$gameDescription = "GameDescription001";
						
$createGame = $gameService->createGame($gameName,$gameDescription);  /* returns the Game object. */ 
print_r("gameName is" . $game->getName()); 
print_r("gameDescription is" . $game->getGameDescription()); 
$jsonResponse = $game->toString(); /* returns the response in JSON format. */ 
                            

The functions available under Gaming API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is creating a game with name which is already in database, the function will throw the App42Exception (as shown below) with message as "Bad Request" and the appErrorCode as "3000" and the details as "The request parameters are invalid. Game with the name '<name>' already exists".

The response in case of exception is given below.

$gameName = "Game01";
$gameDescription = "GameDescription001";
							
try{
	$game = $gameService->createGame($gameName,$gameDescription);
} catch(App42Exception $ex) {
	$appErrorCode = $ex->getAppErrorCode();
	$httpErrorCode = $ex->getHttpErrorCode();
	if(appErrorCode == 3000)
{
    // Handle here for Bad Request (The request parameters are invalid. Game with the name '<name>' already exists.)
}
    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": 400,
			"appErrorCode": 3000,
			"message": "Bad Request",
			"details": "The Request parameters are invalid. Game with the name 'Game01' already exists"
		}
	}
							

Below are the HTTP Error Codes and their description, the function under the Gaming 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 Gaming API can throw.

/*
3000 - BAD REQUEST - The request parameters are invalid. Game with the name '<name>' already exists.
3001 - NOT FOUND - Games do not exist. 
3002 - NOT FOUND - Game with the name '<name>' does not exist. 
3003 - NOT FOUND - Game with id '<gameId>' does not exist.
3004 - BAD REQUEST - The request parameters are invalid. Reward with the name '<rewardName>' already exists.
3005 - NOT FOUND - Rewards do not exist.
3006 - NOT FOUND - Reward with the name '<name>' does not exist.
3007 - NOT FOUND - User with the name '<userName>' does not exist.
3008 - BAD REQUEST - The request parameters are invalid. Do not have enough reward points to redeem.
3009 - BAD REQUEST - The request parameters are invalid. Do not have enough scores to deduct.
3010 - NOT FOUND - Scores for the user with the name '<userName>' for the game with the name '<name>' do not exist.
3011 - NOT FOUND - The number of the games are less than the specified offset : ${offset}.
3012 - NOT FOUND - The number of the rewards are less than the specified offset : ${offset}.
3013 - NOT FOUND - Scores for the game with the name '<name>' does not exist. 
3014 - NOT FOUND - Reward Points for the user with the name '<userName>' do not exist.	           		
*/			

Various functions available under Gamming API has been explained below.

function createGame($gameName, $gameDescription)

Creates game on the cloud.

Parameters:

gameName - The game that has to be created
gameDescription - Description of the game to be created

Returns:

Game object containing the game which has been created

Response: Game Object

Exception:

This method throws following exception.
/*
3000 - BAD REQUEST - The request parameters are invalid. Game with the name '<name>' already exists.
*/ 		        
For more details click Exception
$gameName = "Game01";
$gameDescription = "GameDescription001";
						
$game = $gameService->createGame($gameName,$gameDescription); /* returns the Game object. */ 
print_r("gameName is" . $game->getName()); 
print_r("gameDescription is" . $game->getGameDescription()); 
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "description": "GameDescription001"
                }
            }
        }
    }
}
	
function getAllGames()

Fetches all games for the App.

Parameters:

N/A

Returns:

ArrayList of Game object containing all the games for the App

Response: Game Object

Exception:

This method throws following exception.
/*
3001 - NOT FOUND - Games do not exist. 
*/ 		       
For more details click Exception
$gameList = $gameService->getAllGames(); /* returns the list of Game object. */ 

foreach( $gameList as $game ){
print_r("gameName is" . $game->getName()); 
print_r("gameDescription is" . $game->getGameDescription()); 
}
$jsonResponse = $gameList->toString(); /* returns the response in JSON format. (as shown below)*/    
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": [
                    {
                        "name": "Game01",
                        "description": "GameDescription001"
                    },
                    {
                        "name": "Game02",
                        "description": "GameDescription001"
                    }
                ]
            }
        }
    }
}
function getAllGamesCount()

Fetches the count of all games for the App

Parameters:

N/A

Returns:

App42Response object containing count of all the Game for the App

Response: App42ResponseObject

Exception:

This method throws following exception.
/*
3001 - NOT FOUND - Games do not exist. 
*/ 		        
For more details click Exception
$response = $gameService->getAllGamesCount(); /* 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": 170
        }
    }
}

function getAllGamesByPaging($max, $offset) throws App42Exception

Fetches all games for the App by paging

Parameters:

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

Returns:

ArrayList of Game object containing all the games for the App

Response: Game Object

Exception:

This method throws following exception.
/*
3011 - NOT FOUND _ The number of the games are less than the specified offset : ${offset}.
*/ 		        
For more details click Exception
$max = 1;
$offset = 0;	

$gameList = $gameService->getAllGames($max,$offset); /* returns the list of Game object. */ 
foreach($gameList as $game){
print_r("gameName is" . $game->getName()); 
print_r("gameDescription is" . $game->getGameDescription());  
}
$jsonResponse = $gameList->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "gameName123Sat Jun 02 17:35:05 IST 2012",
                    "description": "gameDescription01"
                }
            }
        }
    }
}
function getGameByName($gameName)

Retrieves the game by the specified name.

Parameters:

gameName - Name of the game that has to be fetched

Returns:

Game object containing the game which has been created

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.
*/ 		       
For more details click Exception
$gameName = "Game01";									
						
$game = $gameService->getGameByName($gameName); /* returns the Game object. */ 
print_r("gameName is" . $game->getName()); 
print_r("gameDescription is" . $game->getGameDescription()); 
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "description": "GameDescription001"
                }
            }
        }
    }
}
function getScoresByUser($gameName,$userName)

Retrieves the scores for a game for the specified name.

Parameters:

gameName - Name of the game for which score has to be fetched
userName - The user for which score has to be fetched

Returns:

The game score for the specified user

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist. 
3010 - NOT FOUND - Scores for the user with the name '<userName>' for the game with the name '<name>' do not exist. 		
*/ 		       
For more details click Exception
$gameName = "Game02";
$userName = "Nick";									
						
$game = $scoreBoardService->getScoresByUser($gameName, $userName); /* returns the Game object. */ 
print_r("gameName is" . $game->getName()); 
print_r("gameDescription is" . $game->getGameDescription()); 
$scoreList = $game->getScoreList();
foreach( $scoreList as $score ){
print_r("gameName is". $score->getUserName());
print_r("value is" . $score->getValue());
}
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 400000
                        }
                    }
                }
            }
        }
    }
}

function getAverageScoreByUser($gameName,$userName)

Retrieves the average game score for the specified user.

Parameters:

gameName - Name of the game for which highest score has to be fetched
userName - The user for which highest score has to be fetched

Returns:

The average game score for the specified user

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist. 
3010 - NOT FOUND - Scores for the user with the name '<userName>' for the game with the name '<name>' do not exist. 		
*/ 		       
For more details click Exception
$gameName = "Game02";
$userName = "Nick";	
								
$game  = $scoreBoardService->getAverageScoreByUser($gameName, $userName); /* returns the Game object. */ 
print_r("Game Name is " . $game->getName());
$scoreList = $game->getScoreList();
for($scoreList as $score)
{  
print_r("User Name is " . $score->getUserName());
print_r("Value is " . $score->getValue());
}						
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 45
                        }
                    }
                }
            }
        }
    }
}

function getHighestScoreByUser($gameName,$userName)

Retrieves the highest game score for the specified user.

Parameters:

gameName - Name of the game for which highest score has to be fetched
userName - The user for which highest score has to be fetched

Returns:

The highest game score for the specified user

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist. 
3010 - NOT FOUND - Scores for the user with the name '<userName>' for the game with the name '<name>' do not exist. 		
*/ 		        
For more details click Exception
$gameName = "Game02";
$userName = "Nick";									
						
$game = $scoreBoardService->getHighestScoreByUser($gameName, $userName); /* returns the Game object. */ 
print_r("gameName is" .$game->getName()); 
$scoreList = $game->getScoreList();
foreach( $scoreList as $score )
{
print_r("gameName is". $score->getUserName());
print_r("value is" . $score->getValue());
} 
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/       
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 8790000
                        }
                    }
                }
            }
        }
    }
}
function getLowestScoreByUser($gameName,$userName)

Retrieves the lowest game score for the specified user

Parameters:

gameName - Name of the game for which lowest score has to be fetched
userName - The user for which lowest score has to be fetched

Returns:

The lowest game score for the specified user

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist. 
3010 - NOT FOUND - Scores for the user with the name '<userName>' for the game with the name '<name>' do not exist. 		
*/ 		        
For more details click Exception
$gameName = "Game02";
$userName = "Nick";										
						
$game = $scoreBoardService->getLowestScoreByUser($gameName, $userName); /* returns the Game object. */ 
print_r("gameName is" .$game->getName()); 
$scoreList = $game->getScoreList();
foreach( $scoreList as $score )
{
print_r("gameName is". $score->getUserName());
print_r("value is" . $score->getValue());
}
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 400000
                        }
                    }
                }
            }
        }
    }
}
function getTopRankings($gameName)

Retrieves the Top Rankings for the specified game.

Parameters:

gameName - Name of the game for which ranks have to be fetched

Returns:

The Top rankings for a game

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.
3013 - NOT FOUND - Scores for the game with the name '<name>' does not exist.     
*/		        
For more details click Exception
$gameName = "Game02";									
						
$game = $scoreBoardService->getTopRankings($gameName); /* returns the Game object. */ 
print_r("gameName is" .$game->getName());
$scoreList = $game->getScoreList();
foreach( $scoreList as $score )
{
print_r("gameName is". $score->getUserName());
print_r("value is" . $score->getValue());
} 
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": [
                            {
                                "userName": "GameUserName",
                                "value": 8790000
                            },
                            {
                                "userName": "GameUserName",
                                "value": 400000
                            }
                        ]
                    }
                }
            }
        }
    }
}
function getTopNRankings($gameName,$max)

Retrieves the Top Rankings for the specified game.

Parameters:

gameName - Name of the game for which ranks have to be fetched
max - Maximum number of records to be fetched

Returns:

The Top rankings for a game

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.
3013 - NOT FOUND - Scores for the game with the name '<name>' does not exist.     
*/		        
For more details click Exception
$gameName = "Game02";
$max = 2;

$game = $scoreBoardService->getTopNRankings($gameName,$max); /* returns the Game object. */ 
print_r("Game Name is " . $game->getName());
$scoreList = $game->getScoreList();
for($scoreList as $score)
{  
print_r("User Name is " . $score->getUserName());
print_r("Value is " . $score->getValue());
}
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/  						
                         
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": [
                            {
                                "userName": "Nick",
                                "value": 10014
                            },
                            {
                                "userName": "Jay",
                                "value": 10013
                            }
                        ]
                    }
                }
            }
        }
    }
}
function getUserRanking($gameName,$userName)

Retrieves the Top Rankings for the specified game.

Parameters:

gameName - Name of the game for which ranks have to be fetched
userName - Name of the user for which ranks have to be fetched

Returns:

The rank of the User

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.   
*/		        
For more details click Exception
$gameName = "Game02";
$userName = "Nick";

$game = $scoreBoardService->getUserRanking($gameName,$userName); /* returns the Game object. */ 
print_r("Game Name is " + $game->getName());
$scoreList = $game->getScoreList();
for($scoreList as $score)
{  
print_r("User Name is " . $score->getUserName());
print_r("Value is " . $score->getValue());
}
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/ 						
                         
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "rank": 4,
                            "value": 89
                        }
                    }
                }
            }
        }
    }
}
function saveUserScore($gameName, $gameUserName,$gameScore)

Saves the User score for a game.

Parameters:

gameName - Name of the game for which score has to be saved
gameUserName - The user for which score has to be saved
gameScore - The sore that has to be saved

Returns:

The saved score for a game

Response: Game Object

Exception:

This method throws following exception.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.		
*/ 		       
For more details click Exception
$gameName = "Game02";
$gameUserName = "Nick"; 
$gameScore = 400000
					
$game = $scoreBoardService->saveUserScore($gameName, $gameUserName, $gameScore); /* returns the Game object. */ 
print_r("Game Name is " + $game->getName());
$scoreList = $game->getScoreList();
foreach( $scoreList as $score )
{
print_r("User Name is " . $score->getUserName());
print_r("Value is " . $score->getValue());
}
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 400000,
                            "createdOn": "2012-05-10T07:31:18.535Z"
                        }
                    }
                }
            }
        }
    }
}
function createReward($rewardName, $rewardDescription)

Creates Reward. Reward can be Sword, Energy etc. When Reward Points have to be added the Reward name created using this method has to be specified.

Parameters:

rewardName - The reward that has to be created
rewardDescription - The description of the reward to be created

Returns:

Reward object containing the reward that has been created

Response: Reward Object

Exception:

This method throws following exception.
/*
3004 - BAD REQUEST - The request parameters are invalid. Reward with the name '<rewardName>' already exists. 
*/ 		        
For more details click Exception
$rewardName = "Reward01";
$rewardDescription = "Reward Description";
					
$reward = $rewardService->createReward($rewardName, $rewardDescription); /* returns the Reward object. */ 
print_r("rewardName is" . $reward->getName()); 
print_r("rewardDescription is" . $reward->getDescription(); 
$jsonResponse = $reward->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "Reward01",
                    "description": "Reward Description"
                }
            }
        }
    }
}
 
function getAllRewards()

Fetched all the Rewards.

Parameters:

N/A

Returns:

ArrayList of Reward objects containing all the rewards of the App

Response: Reward Object

Exception:

This method throws following exception.
/*
3005 - NOT FOUND - Rewards do not exist.
*/ 	    
For more details click Exception
$rewardList = $rewardService->getAllRewards(); /* returns the list of Reward object. */ 
foreach( $rewardList as $reward )
{
print_r("rewardName is" . $reward->getName()); 
print_r("rewardDescription is" . $reward->getDescription(); 
}
$jsonResponse = $rewardList->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": [
                    {
                        "name": "Reward01",
                        "description": "Reward Description"
                    },
                    {
                        "name": "Reward02",
                        "description": "Second Reward's Description "
                    }
                ]
            }
        }
    }
}
	
function getAllRewardsCount()

Fetches the count of all the Rewards

Parameters:

N/A

Returns:

App42Response objects containing count of all the rewards of the App

Response: App42ResponseObject

Exception:

This method throws following exception.
/*
3005 - NOT FOUND - Rewards do not exist. 
*/ 		   
For more details click Exception
$response = $rewardService->getAllRewardsCount(); /* 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": 80
       }
   }
}
function getAllRewards(int max, int offset) throws App42Exception

Fetches all the Rewards by paging.

Parameters:

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

Returns:

ArrayList of Reward objects containing all the rewards of the App

Response: Reward Object

Exception:

This method throws following exception.
/*
3012 - NOT FOUND _ The number of the rewards are less than the specified offset : ${offset}.
*/ 		    
For more details click Exception
$max = 1;
$offset = 0;										
						
$rewardList = $rewardService->getAllRewards($max,$offset); /* returns the list of Reward object. */ 
foreach($rewardList as $reward){
print_r("rewardName is" . $reward->getName()); 
print_r("rewardDescription is" . $reward->getDescription(); 
}
$jsonResponse = $rewardList->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "rewardName",
                    "description": "rewardDescription"
                }
            }
        }
    }
}
	
function getRewardByName($rewardName)

Retrieves the reward for the specified name.

Parameters:

rewardName - Name of the reward that has to be fetched

Returns:

Reward object containing the reward based on the rewardName

Response: Reward Object

Exception:

This method throws following exception.
/*
3006 - NOT FOUND - Reward with the name '<name>' does not exist. 
*/ 		   
For more details click Exception
$rewardName = "Reward01";
						
$reward = $rewardService->getRewardByName($rewardName); /* returns the Reward object. */ 
print_r("rewardName is" . $reward->getName()); 
print_r("rewardDescription is" . $reward->getDescription();  
$jsonResponse = $reward->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "Reward01",
                    "description": "Reward Description"
                }
            }
        }
    }
}
	
function earnRewards($gName, $gUserName, $rewardName, $rewardPoints)

Adds the reward points to an users account. Reward Points can be earned by the user which can be redeemed later.

Parameters:

gName - Name of the game for which reward points have to be added
gUserName - The user for whom reward points have to be added
rewardName - The rewards for which reward points have to be added
rewardsPoints - The points that have to be added

Returns:

Reward object containing the rewardpoints that has been added

Response: Reward Object

Exception:

This method throws following exception.
/* 
3002 - NOT FOUND - Game with the name '<name>' does not exist.
3006 - NOT FOUND - Reward with the name '<name>' does not exist. 
*/ 		    
For more details click Exception
$gameName = "Game01";
$gUserName = "Nick";
$rewardName = "Reward01";
$rewardPoints = 1000;
						
$reward = $rewardService->earnRewards($gName, $gUserName, $rewardName, $rewardPoints); /* returns the Reward object. */ 
print("rewardName is" .$reward->getName()); 
print_r("rewardgameName is" . $reward->getGameName());
print_r("rewarduserName is" . $reward->getUserName()); 
print_r("rewardpoints is" . $reward->getPoints());
$jsonResponse = $reward->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "User01",
                    "name": "Reward01",
                    "points": 1000
                }
            }
        }
    }
}
	
function redeemRewards($gName, $gUserName, $rewardName, $rewardPoints)

Deducts the rewardpoints from the earned rewards by a user.

Parameters:

gName - Name of the game for which reward points have to be deducted
gUserName - The user for whom reward points have to be deducted
rewardName - The rewards for which reward points have to be deducted
rewardsPoints - The points that have to be deducted

Returns:

Reward object containing the rewardpoints that has been deducted

Response: Reward Object

Exception:

This method throws following exception.
/* 
3002 - NOT FOUND - Game with the name '<name>' does not exist.
3006 - NOT FOUND - Reward with the name '<name>' does not exist. 
3008 - BAD REQUEST - The request parameters are invalid. Do not have enough reward points to redeem. 
*/ 		     
For more details click Exception
$gName = "Game01";
$gUserName = "Nick";
$rewardName = "Reward01";
$rewardPoints = 900;
						
$reward = $rewardService->redeemRewards($gName, $gUserName, $rewardName, $rewardPoints); /* returns the Reward object. */ 
print("rewardName is" .$reward->getName()); 
print_r("rewardgameName is" . $reward->getGameName());
print_r("rewarduserName is" . $reward->getUserName()); 
print_r("rewardpoints is" . $reward->getPoints());
$jsonResponse = $reward->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "User01",
                    "name": "Reward01",
                    "points": 900
                }
            }
        }
    }
}
	
function getGameRewardPointsForUser($gameName, $userName)

Fetches the reward points for a particular user.

Parameters:

gameName - Name of the game for which reward points have to be fetched
userName - The user for whom reward points have to be fetched

Returns:

Reward object containing the reward points for the specified user

Response: Reward Object

Exception:

This method throws following exception.
/* 
3002 - NOT FOUND - Game with the name '<name>' does not exist.
3006 - NOT FOUND - Reward with the name '<name>' does not exist. 
*/ 		     
For more details click Exception
$gameName = "Game01";
$userName = "Nick";
						
$reward = $rewardService->getGameRewardPointsForUser($gameName, $userName); /* returns the Reward object. */ 
print("rewardName is" .$reward->getName()); 
print_r("rewardgameName is" . $reward->getGameName());
print_r("rewarduserName is" . $reward->getUserName()); 
print_r("rewardpoints is" . $reward->getPoints()); 

$jsonResponse = $reward->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "User01",
                    "name": "Reward01",
                    "points": 900
                }
            }
        }
    }
}
	
function addScore($gameName, $gameUserName, $gameScore)

Adds game score for the specified user.

Parameters:

gameName - Name of the game for which scores have to be added
gameUserName - The user for whom scores have to be added
gameScore - The scores that have to be added

Returns:

Game object containing the scores that has been added

Response: Game Object

Exception:

This method throws following exception.
/* 
3002 - NOT FOUND - Game with the name '<name>' does not exist.
*/ 		    
For more details click Exception
$gameName = "Game01";
$gameUserName = "Nick";
$gameScore = 1000000;
						
$game = $scoreService->addScore($gameName, $gameUserName, $gameScore); /* returns the Game object. */ 
print_r("gameName is" . $game->getName()); 
$scoreList = $game->getScoreList();
foreach( $scoreList as $score )
{
print_r("gameName is" .$score->getUserName());
print_r("value is" . $score->getValue());
}
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 1000000
                        }
                    }
                }
            }
        }
    }
}
	
function deductScore($gameName, $gameUserName, $gameScore)

Deducts the score from users account for a particular Game

Parameters:

gameName - Name of the game for which scores have to be deducted
gameUserName - The user for whom scores have to be deducted
gameScore - The scores that have to be deducted

Returns:

Game object containing the scores that has been deducted

Response: Game Object

Exception:

This method throws following exception.
/* 
3002 - NOT FOUND - Game with the name '<name>' does not exist. 
3007 - NOT FOUND - User with the name '<userName>' does not exist. 
3009 - BAD REQUEST - The request parameters are invalid. Do not have enough scores to deduct. 
*/ 	      
For more details click Exception
$gameName = "Game01";
$gameUserName = "Nick";
$gameScore = 999900;
						
$game = $scoreService->deductScore($gameName, $gameUserName, $gameScore); /* returns the Game object. */ 
print_r("gameName is" . $game->getName()); 
$scoreList = $game->getScoreList();
foreach( $scoreList as $score )
{
print_r("gameName is" .$score->getUserName());
print_r("value is" . $score->getValue());
}
$jsonResponse = $game->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 999900
                        }
                    }
                }
            }
        }
    }
}