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.
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 GameService, buildGameService() method needs to be called.
GameService 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.
String gameName = "Game01";
String gameDescription = "GameDescription001";
Game game = gameService.createGame(gameName,gameDescription); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
System.out.println("Game Description is " + game.getDescription());
String 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".
String gameName = "Game01";
String gameDescription = "GameDescription001";
try
{
Game game = gameService.createGame(gameName,gameDescription);
}
catch(App42Exception ex)
{
int appErrorCode = ex.getAppErrorCode();
int 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
}
String 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. 3015 - NOT FOUND - Scores betweem startDate '<startDate>' and endDate '<endDate>' for the game with the name '<name>' does not exist. 3016 - NOT FOUND - Scores with users '<userList>' for the game with the name '<name>' does not exist. */
Various functions available under Gamming API has been explained below.
Creates game on the cloud.
Parameters:
Returns:
Response: Game Object
Exception:
/* 3000 - BAD REQUEST - The request parameters are invalid. Game with the name '<name>' already exists. */
String gameName = "Game01";
String gameDescription = "GameDescription001";
Game game = gameService.createGame(gameName,gameDescription); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
System.out.println("Game Description is " + game.getDescription());
String jsonResponse = game.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"games": {
"game": {
"name": "Game01",
"description": "GameDescription001"
}
}
}
}
}
Fetches all games for the App.
Parameters:
Returns:
Response: ArrayList<Game> Object
Exception:
/* 3001 - NOT FOUND - Games do not exist. */
ArrayList<Game> gameList = gameService.getAllGames(); /* returns the list of Game object. */
for(Game game : gameList)
{
System.out.println("Game Name is " + game.getName());
System.out.println("Game Description is " + game.getDescription());
}
String 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"
}
]
}
}
}
}
Fetches the count of all games for the App
Parameters:
Returns:
Response: App42ResponseObject
App42Response response = gameService.getAllGamesCount(); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}
Fetches all games for the App by Paging
Parameters:
Returns:
Response: ArrayList<Game> Object
Exception:
/* 3011 - NOT FOUND - The number of the games are less than the specified offset : <offset>. */
int max = 1;
int offset = 0;
ArrayList<Game> gameList = gameService.getAllGames(max,offset); /* returns the list of Game object. */
for(Game game : gameList)
{
System.out.println("Game Name is " + game.getName());
System.out.println("Game Description is " + game.getDescription());
}
String jsonResponse = gameList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"games": {
"game": {
"name": "gameName3",
"description": "gameDescription01"
}
}
}
}
}
Retrieves the game by the specified name.
Parameters:
Returns:
Response: Game Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. */
String gameName = "Game01";
Game game = gameService.getGameByName(gameName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
System.out.println("Game Description is " + game.getDescription());
String jsonResponse = game.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"games": {
"game": {
"name": "Game01",
"description": "GameDescription001"
}
}
}
}
}
Retrieves the scores for a game for the specified name.
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game02";
String userName = "Nick";
Game game = scoreBoardService.getScoresByUser(gameName, userName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 400000
}
}
}
}
}
}
}
Retrieves the average game score for the specified user.
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game02";
String userName = "Nick";
Game game = scoreBoardService.getAverageScoreByUser(gameName, userName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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
}
}
}
}
}
}
}
Retrieves the highest game score for the specified user.
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game02";
String userName = "Nick";
Game game = scoreBoardService.getHighestScoreByUser(gameName, userName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 400000
}
}
}
}
}
}
}
Retrieves the lowest game score for the specified user
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game02";
String userName = "Nick";
Game game = scoreBoardService.getLowestScoreByUser(gameName, userName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 400000
}
}
}
}
}
}
}
Retrieves the Top Rankings for the specified game.
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game02";
Game game = scoreBoardService.getTopRankings(gameName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 8790000
},
{
"userName": "Jay",
"value": 400000
}
]
}
}
}
}
}
}
Retrieves the Top Rankings for the specified game.
Parameters:
Returns:
Response: Game Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. 3015 - NOT FOUND - Scores betweem startDate '<startDate>' and endDate '<endDate>' for the game with the name '<name>' does not exist. */
String gameName = "Game02";
Date startDate = new Date(new Date().getTime() -1000*60*60*24*20) ;
Date endDate = new Date(new Date().getTime()) ;
Game game = scoreBoardService.getTopRankings(gameName,startDate,endDate); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 8790000
},
{
"userName": "Jay",
"value": 400000
}
]
}
}
}
}
}
}
Retrieves the Top Rankings for the specified game.
Parameters:
Returns:
Response: Game Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. 3016 - NOT FOUND - Scores with users '<userList>' for the game with the name '<name>' does not exist. */
String gameName = "Game02";
ArrayList<String> userList = new ArrayList<String>();
userList.add("Nick");
userList.add("Jay");
Game game = scoreBoardService.getTopRankingsByGroup(gameName,userList); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 8790000
},
{
"userName": "Jay",
"value": 400000
}
]
}
}
}
}
}
}
Retrieves the Top Rankings for the specified game.
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game02";
String userName = "Nick";
Game game = scoreBoardService.getLastScoreByUser(gameName,userName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 10000
}
}
}
}
}
}
}
Retrieves the Top N Rankings for the specified game.
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game02";
int max = 2;
Game game = scoreBoardService.getTopNRankings(gameName,max); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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
}
]
}
}
}
}
}
}
Retrieves the User Rankings for the specified game.
Parameters:
Returns:
Response: Game Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. */
String gameName = "Game02";
String userName = "Nick";
Game game = scoreBoardService.getUserRanking(gameName,userName); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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
}
}
}
}
}
}
}
Saves the User score for a game.
Parameters:
Returns:
Response: Game Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. */
String gameName = "Game02";
String gameUserName = "Nick";
double gameScore = 400000
Game game = scoreBoardService.saveUserScore(gameName, gameUserName, gameScore); /* returns the Game object. */
System.out.println("Game Name is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("User Name is " + score.getUserName());
System.out.println("Value is " + score.getValue());
}
String 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": 400000,
"createdOn": "2012-05-10T07:31:18.535Z"
}
}
}
}
}
}
}
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:
Returns:
Response: Reward Object
Exception:
/* 3004 - BAD REQUEST - The request parameters are invalid. Reward with the name '<rewardName>' already exists. */
String rewardName = "Reward01";
String rewardDescription = "Reward Description";
Reward reward = rewardService.createReward(rewardName, rewardDescription); /* returns the Reward object. */
System.out.println("rewardName is " + reward.getName());
System.out.println("rewardDescription is " + reward.getDescription());
String jsonResponse = reward.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"rewards": {
"reward": {
"name": "Reward01",
"description": "Reward Description"
}
}
}
}
}
Fetches all the Rewards
Parameters:
Returns:
Response: ArrayList<Reward> Object
Exception:
/* 3005 - NOT FOUND - Rewards do not exist. */
ArrayList<Reward> rewardList = rewardService.getAllRewards(); /* returns the list of Reward object. */
for(Reward reward : rewardList)
{
System.out.println("rewardName is " + reward.getName());
System.out.println("rewardDescription is " + reward.getDescription());
}
String 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 "
}
]
}
}
}
}
Fetches the count of all the Rewards
Parameters:
Returns:
Response: App42ResponseObject
App42Response response = rewardService.getAllRewardsCount(); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}
Fetches all the Rewards by paging.
Parameters:
Returns:
Response: ArrayList<Reward> Object
Exception:
/* 3012 - NOT FOUND - The number of the rewards are less than the specified offset : <offset>. */
int max = 1;
int offset = 0;
ArrayList<Reward> rewardList = rewardService.getAllRewards(max,offset); /* returns the list of Reward object. */
for(Reward reward : rewardList)
{
System.out.println("rewardName is " + reward.getName());
System.out.println("rewardDescription is " + reward.getDescription());
}
String jsonResponse = rewardList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"rewards": {
"reward": {
"name": "rewardName",
"description": "rewardDescription"
}
}
}
}
}
Retrieves the reward for the specified name.
Parameters:
Returns:
Response: Reward Object
Exception:
/* 3006 - NOT FOUND - Reward with the name '<name>' does not exist. */
String rewardName = "Reward01";
Reward reward = rewardService.getRewardByName(rewardName); /* returns the Reward object. */
System.out.println("rewardName is " + reward.getName());
System.out.println("rewardDescription is " + reward.getDescription());
String jsonResponse = reward.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"rewards": {
"reward": {
"name": "Reward01",
"description": "Reward Description"
}
}
}
}
}
Adds the reward points to an users account. Reward Points can be earned by the user which can be redeemed later.
Parameters:
Returns:
Response: Reward Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. 3006 - NOT FOUND - Reward with the name '<name>' does not exist. */
String gameName = "Game01";
String gameUserName = "Nick";
String rewardName = "Reward01";
double rewardPoints = 1000;
Reward reward = rewardService.earnRewards(gameName, gameUserName, rewardName, rewardPoints); /* returns the Reward object. */
System.out.println("rewardName is " + reward.getName());
System.out.println("rewardgameName is " + reward.getGameName());
System.out.println("rewarduserName is " + reward.getUserName());
System.out.println("rewardpoints is " + reward.getPoints());
String jsonResponse = reward.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"rewards": {
"reward": {
"gameName": "Game01",
"userName": "Nick",
"name": "Reward01",
"points": 1000
}
}
}
}
}
Deducts the rewardpoints from the earned rewards by a user.
Parameters:
Returns:
Response: Reward Object
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. */
String gameName = "Game01";
String gameUserName = "Nick";
String rewardName = "Reward01";
double rewardPoints = 900;
Reward reward = rewardService.redeemRewards(gameName, gameUserName, rewardName, rewardPoints); /* returns the Reward object. */
System.out.println("rewardName is " + reward.getName());
System.out.println("rewardgameName is " + reward.getGameName());
System.out.println("rewarduserName is " + reward.getUserName());
System.out.println("rewardpoints is " + reward.getPoints());
String jsonResponse = reward.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"rewards": {
"reward": {
"gameName": "Game01",
"userName": "Nick",
"name": "Reward01",
"points": 900
}
}
}
}
}
Fetches the reward points for a particular user.
Parameters:
Returns:
Response: Reward Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. 3014 - NOT FOUND - Reward Points for the user with the name '<userName>' do not exist. */
String gameName = "Game01";
String userName = "Nick";
Reward reward = rewardService.getGameRewardPointsForUser(gameName, userName); /* returns the Reward object. */
System.out.println("rewardName is " + reward.getName());
System.out.println("rewardgameName is " + reward.getGameName());
System.out.println("rewarduserName is " + reward.getUserName());
System.out.println("rewardpoints is " + reward.getPoints());
String jsonResponse = reward.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"rewards": {
"reward": {
"gameName": "Game01",
"userName": "Nick",
"name": "Reward01",
"points": 900
}
}
}
}
}
Adds game score for the specified user.
Parameters:
Returns:
Response: Game Object
Exception:
/* 3002 - NOT FOUND - Game with the name '<name>' does not exist. */
String gameName = "Game01";
String gameUserName = "Nick";
double gameScore = 1000000;
Game game = scoreService.addScore(gameName, gameUserName, gameScore); /* returns the Game object. */
System.out.println("gameName is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("userName is " + score.getUserName());
System.out.println("value is " + score.getValue());
}
String jsonResponse = game.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"games": {
"game": {
"name": "Game01",
"scores": {
"score": {
"userName": "Nick",
"value": 1000000
}
}
}
}
}
}
}
Deducts the score from users account for a particular Game
Parameters:
Returns:
Response: Game Object
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. */
String gameName = "Game01";
String gameUserName = "Nick";
double gameScore = 999900;
Game game = scoreService.deductScore(gameName, gameUserName, gameScore); /* returns the Game object. */
System.out.println("gameName is " + game.getName());
ArrayList<Game.Score> scoreList = game.getScoreList();
for(Game.Score score : scoreList)
{
System.out.println("userName is " + score.getUserName());
System.out.println("value is " + score.getValue());
}
String jsonResponse = game.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"games": {
"game": {
"name": "Game01",
"scores": {
"score": {
"userName": "Nick",
"value": 999900
}
}
}
}
}
}
}