App42 Cloud API

Android 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 Score board 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.

public Game createGame(String gameName, String gameDescription) throws App42Exception

Creates a game on the cloud

Parameters:

gameName - Name of 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:

The method throws the following exception with the error code.
/*
3000 - BAD REQUEST - The request parameters are invalid. Game with the name '<name>' already exists.
*/ 		        
For more details click Exception

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"
                }
            }
        }
    }
}	
public ArrayList<Game> getAllGames() throws App42Exception

Fetches all games for the App

Parameters:

N/A

Returns:

List of Game object containing all the games for the App

Response: ArrayList<Game> Object

Exception:

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

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:

The method throws the following exception with the error code.
/*
3001 - NOT FOUND - Games do not exist.
*/ 		        
For more details click Exception
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
        }
    }
}
public ArrayList<Game> getAllGamesByPaging(int max, int 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:

List of Game object containing all the games for the App

Response: ArrayList<Game> Object

Exception:

The method throws the following exception with the error code.
/*
3011 - NOT FOUND - The number of the games are less than the specified offset : <offset>.
*/ 		        
For more details click Exception
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"
                }
            }
        }
    }
}
public Game getGameByName(String gameName) throws App42Exception

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:

The method throws the following exception with the error code.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.
*/ 		       
For more details click Exception
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"
                }
            }
        }
    }
}
public Game getScoresByUser(String gameName, String userName) throws App42Exception

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:

The method throws the following exception with the error code.
/*
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
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
                        }
                    }
                }
            }
        }
    }
}
public Game getAverageScoreByUser(String gameName, String userName) throws App42Exception

Retrieves the average game score for the specified user

Parameters:

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

Returns:

The average game score for the specified user

Response: Game Object

Exception:

The method throws the following exception with the error code.
/*
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
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
                        }
                    }
                }
            }
        }
    }
}
public Game getHighestScoreByUser(String gameName, String userName) throws App42Exception

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:

The method throws the following exception with the error code.
/*
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
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
                        }
                    }
                }
            }
        }
    }
}
public Game getLowestScoreByUser(String gameName, String userName) throws App42Exception

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:

The method throws the following exception with the error code.
/*
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
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
                        }
                    }
                }
            }
        }
    }
}
public Game getTopRankings(String gameName) throws App42Exception

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:

The method throws the following exception with the error code.
/*
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
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
                            }
                        ]
                    }
                }
            }
        }
    }
}
public Game getTopRankings(String gameName, Date startDate, Date endDate) throws App42Exception

Retrieves the Top Rankings for the specified game.

Parameters:

gameName - Name of the game for which ranks have to be fetched
startDate - Start date from which the ranking have to be fetched
endDate - End date up to which the ranking have to be fetched

Returns:

The Top rankings for a game

Response: Game Object

Exception:

The method throws the following exception with the error code.
/*
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.
*/		        
For more details click Exception
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
                            }
                        ]
                    }
                }
            }
        }
    }
}	
public Game getTopRankingsByGroup(String gameName, ArrayList<String> userList) throws App42Exception

Retrieves the Top Rankings for the specified game.

Parameters:

gameName - Name of the game for which ranks have to be fetched
userList - List of user from which ranking has to be fetched

Returns:

The Top rankings for a game

Response: Game Object

Exception:

The method throws the following exception with the error code.
/*
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.
*/		        
For more details click Exception
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
                            }
                        ]
                    }
                }
            }
        }
    }
}	
public Game getLastScoreByUser(String gameName,String userName) throws App42Exception

Retrieves the Top Rankings for the specified game.

Parameters:

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

Returns:

The Las Score for a game

Response: Game Object

Exception:

The method throws the following exception with the error code.
/*
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
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
                        }
                    }
                }
            }
        }
    }
}
public Game getTopNRankings(String gameName, int max) throws App42Exception

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:

The method throws the following exception with the error code.
/*
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
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
                            }
                        ]
                    }
                }
            }
        }
    }
}
public Game getUserRanking(String gameName, String userName) throws App42Exception

Retrieves the User Ranking 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:

The method throws the following exception with the error code.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.   
*/		        
For more details click Exception
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
                        }
                    }
                }
            }
        }
    }
}
public Game saveUserScore(String gameName, String gameUserName, double gameScore) throws App42Exception

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:

The method throws the following exception with the error code.
/*
3002 - NOT FOUND - Game with the name '<name>' does not exist.		
*/ 		       
For more details click Exception
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"
                        }
                    }
                }
            }
        }
    }
}
public Reward createReward(String rewardName, String rewardDescription) throws App42Exception

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:

The method throws the following exception with the error code.
/*
3004 - BAD REQUEST - The request parameters are invalid. Reward with the name '<rewardName>' already exists.
*/ 		        
For more details click Exception
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"
                }
            }
        }
    }
} 
public ArrayList<Reward> getAllRewards() throws App42Exception

Fetches all the Rewards

Parameters:

N/A

Returns:

List of Reward objects containing all the rewards of the App

Response: ArrayList<Reward> Object

Exception:

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

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:

The method throws the following exception with the error code.
/*
3005 - NOT FOUND - Rewards do not exist.
*/ 		   
For more details click Exception
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
       }
   }
}
public ArrayList<Reward> 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:

List of Reward objects containing all the rewards of the App

Response: ArrayList<Reward> Object

Exception:

The method throws the following exception with the error code.
/*
3012 - NOT FOUND - The number of the rewards are less than the specified offset : <offset>.
*/ 		    
For more details click Exception
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"
                }
            }
        }
    }
}	
public Reward getRewardByName(String rewardName) throws App42Exception

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:

The method throws the following exception with the error code.
/*
3006 - NOT FOUND - Reward with the name '<name>' does not exist.
*/ 		   
For more details click Exception
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"
                }
            }
        }
    }
}	
public Reward earnRewards(String gameName, String gameUserName, String rewardName, double rewardPoints) throws App42Exception

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

Parameters:

gameName - Name of the game for which reward points have to be added
gameUserName - The user for whom reward points have to be added
rewardName - The rewards for which reward points have to be added
rewardPoints - The points that have to be added

Returns:

Reward object containing the reward points that has been added

Response: Reward Object

Exception:

The method throws the following exception with the error code.
/* 
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
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
                }
            }
        }
    }
}	
public Reward redeemRewards(String gameName, String gameUserName, String rewardName, double rewardPoints) throws App42Exception

Deducts the reward points from the earned rewards by a user.

Parameters:

gameName - Name of the game for which reward points have to be deducted
gameUserName - The user for whom reward points have to be deducted
rewardName - The rewards for which reward points have to be deducted
rewardPoints - The points that have to be deducted

Returns:

Reward object containing the reward points that has been deducted

Response: Reward Object

Exception:

The method throws the following exception with the error code.
/* 
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
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
                }
            }
        }
    }
}	
public Reward getGameRewardPointsForUser(String gameName, String userName) throws App42Exception

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:

The method throws the following exception with the error code.
/* 
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.	
*/ 		     
For more details click Exception
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
                }
            }
        }
    }
}	
public ArrayList<Reward> getTopNRewardEarners(String gameName, String rewardName, int max) throws App42Exception

This function provides a list of specified number of top reward earners for a specific game.

Parameters:

gameName - Name of the game for which reward earners are to be fetched
rewardName - Name of the reward for which list of earners is to be fetched
max - Specifies the number of top earners to be fetched

Returns:

ArrayList of Reward object

Response: ArrayList<Reward> Object

Exception:

The method throws the following exception with the error code.
/* 
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.	
*/ 		     
For more details click Exception
String gameName = "Game";
String rewardName = "Reward";			
int max = 5;			

ArrayList<Reward> reward = rewardService.getTopNRewardEarners(gameName, rewardName, max); /* returns the ArrayList of Reward object. */ 
System.out.println("Reward Name is " + reward.get(0).getName());
System.out.println("Reward GameName is " + reward.get(0).getGameName());
System.out.println("Reward UserName is " + reward.get(0).getUserName());
System.out.println("Reward Points is " + reward.get(0).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
                }
            }
        }
    }
}	
public ArrayList<Reward> getAllRewardsByUser(String userName, String rewardName) throws App42Exception

This function returns you the details of all the specific rewards earned by the specified user.

Parameters:

userName - Name of the user whose rewards are to be fetched
rewardName - Name of the reward for which details are to be fetched

Returns:

ArrayList of Reward object

Response: ArrayList<Reward> Object

Exception:

The method throws the following exception with the error code.
/* 
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.	
*/ 		     
For more details click Exception
String userName = "Nick";						
String rewardName = "Reward";						

ArrayList<Reward> reward = rewardService.getAllRewardsByUser(userName, rewardName); /* returns the ArrayList of Reward object. */ 
System.out.println("Reward Name is " + reward.get(0).getName());
System.out.println("Reward GameName is " + reward.get(0).getGameName());
System.out.println("Reward UserName is " + reward.get(0).getUserName());
System.out.println("Reward Points is " + reward.get(0).getPoints());  
String jsonResponse = reward.toString(); /* returns the response in JSON format. (as shown below)*/    
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Poker",
                    "userName": "Nick",
                    "name": "Reward01",
                    "points": 900
                }
            }
        }
    }
}	
public ArrayList<Reward> getTopNRewardEarnersByGroup(String gameName, String rewardName, ArrayList<String> userList) throws App42Exception

This function returns you a list of group wise users who earned the top rewards in the specified game.

Parameters:

gameName - Name of the game for which top reward earners are to be fetched
rewardName - Name of the reward for which top earners are to be listed
userList - List of group wise users earning specified rewards

Returns:

ArrayList of Reward object

Response: ArrayList<Reward> Object

Exception:

The method throws the following exception with the error code.
/* 
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.	
*/ 		     
For more details click Exception
String gameName = "Game";
String rewardName = "Reward";		
ArrayList<String> userList = new ArrayList<String>();
userList.add("Nick");
userList.add("Joe");

ArrayList<Reward> reward = rewardService.getTopNRewardEarnersByGroup(gameName, rewardName, userList); /* returns the ArrayList of Reward object. */
System.out.println("Reward Name is " + reward.get(0).getName());
System.out.println("Reward GameName is " + reward.get(0).getGameName());
System.out.println("Reward UserName is " + reward.get(0).getUserName());
System.out.println("Reward Points is " + reward.get(0).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
                }
            }
        }
    }
}	
public Game addScore(String gameName, String gameUserName, double gameScore) throws App42Exception

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:

The method throws the following exception with the error code.
/* 
3002 - NOT FOUND - Game with the name '<name>' does not exist.
*/ 		    
For more details click Exception
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
                        }
                    }
                }
            }
        }
    }
}	
public Game deductScore(String gameName, String gameUserName, double gameScore) throws App42Exception

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:

The method throws the following exception with the error code.
/* 
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
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
                        }
                    }
                }
            }
        }
    }
}