App42 Cloud API

Ruby 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 = App42::ServiceAPI.new("<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";	
					
game = gameService.create_game(gameName,gameDescription);  /* returns the Game object. */ 
puts "gameName is #{game.name}";
puts "gameDescription is #{game.description}";
jsonResponse = game.to_s(); /* 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 '{gameName}' already Exists".

gameName = "Game01";
gameDescription = "GameDescription001";	
							
begin
  game = gameService.create_game(gameName,gameDescription);
rescue App42Exception => ex
  appErrorCode = ex.app_error_code;
  httpErrorCode = ex.http_error_code;

  if(appErrorCode == 3000)
    #Handle here for Bad Request (The request parameters are invalid. Game with the name '<name>' already exists.)

  elsif(appErrorCode == 1401)
    #handle here for Client is not authorized

  else(appErrorCode == 1500)
    #handle here for Internal Server Error
  end

  jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
end 
	{
		"app42Fault": {
			"httpErrorCode": 400,
			"appErrorCode": 3000,
			"message": "Bad Request",
			"details": "The Request parameters are invalid. Game 'Gun Fighter50' 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.

def create_game(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:

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
gameName = "Game01";
gameDescription = "GameDescription001";
						
game = gameService.create_game(gameName,gameDescription); /* returns the Game object. */ 
puts "gameName is #{game.name}";
puts "gameDescription is #{game.description}";
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "description": "GameDescription001"
                }
            }
        }
    }
}
def get_all_games()

Fetches all games for the App.

Parameters:

N/A

Returns:

ArrayList 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
gameList = Array.new();
gameList = gameService.get_all_games();
for game in gameList do
  puts "gameName is #{game.name}";
  puts "gameDescription is #{game.description}";
end
jsonResponse = gameList.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": [
                    {
                        "name": "Game01",
                        "description": "GameDescription001"
                    },
                    {
                        "name": "Game02",
                        "description": "GameDescription001"
                    }
                ]
            }
        }
    }
}
def get_all_games_count()

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

Exception:

The method throws the following exception with the error code
/*
3001 - NOT FOUND - Games do not exist. 
*/ 	
For more details click Exception
response = gameService.get_all_games_count(); /* returns the App42Response objects. */
success = response.isResponseSuccess();
totalRecords = response.totalRecords();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
def get_all_games_by_paging(max, offset)

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: 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
max = 1;
offset = 0;	
					
gameList = Array.new();
gameList = gameService.get_all_games_by_paging(max,offset); /* returns the list of Game object. */
for game in gameList do
  puts "gameName is #{game.name}";
  puts "gameDescription is #{game.description}";
end
jsonResponse = gameList.to_s(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "gameName3",
                    "description": "gameDescription01"
                }
            }
        }
    }
}	
def get_game_by_name(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:

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
gameName = "Game01";
						
game = gameService.get_game_by_name(gameName); /* returns the Game object. */ 
puts "gameName is #{game.name}";
puts "gameDescription is #{game.description}";
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "description": "GameDescription001"
                }
            }
        }
    }
}
def get_scores_by_user(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:

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
gameName = "Game02";
userName = "Nick";
						
game = scoreBoardService.get_scores_by_user(gameName, userName); /* returns the Game object. */
puts "gameName is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 400000
                        }
                    }
                }
            }
        }
    }
}
def get_average_score_by_user(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:

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
gameName = "Game02";
userName = "Nick";
									
game = scoreBoardService.get_average_score_by_user(gameName, userName); /* returns the Game object. */
puts "gameName is #{game.getName}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 45
                        }
                    }
                }
            }
        }
    }
}
def get_highest_score_by_user(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:

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
gameName = "Game02";
userName = "Nick";
						
game = scoreBoardService.get_highest_score_by_user(gameName, userName); /* returns the Game object. */
puts "gameName is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 400000
                        }
                    }
                }
            }
        }
    }
}
def get_lowest_score_by_user(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:

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
gameName = "Game02";
userName = "Nick";	
					
game = scoreBoardService.get_lowest_score_by_user(gameName, userName); /* returns the Game object. */
puts "gameName is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 400000
                        }
                    }
                }
            }
        }
    }
}
def get_top_rankings(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:

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
gameName = "Game02";

game = scoreBoardService.get_top_rankings(gameName); /* returns the Game object. */
puts "gameName is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* 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
                            }
                        ]
                    }
                }
            }
        }
    }
} 
def get_top_N_rankings($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:

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
gameName = "Game02";
max = 2;

game = scoreBoardService.get_top_N_rankings(gameName,max); /* returns the Game object. */
puts "Game Name is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* 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
                            }
                        ]
                    }
                }
            }
        }
    }
}
def get_user_ranking(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:

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
gameName = "Game02";
userName = "Nick";

game = scoreBoardService.get_user_ranking(gameName,userName); /* returns the Game object. */
puts"Game Name is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* 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
                        }
                    }
                }
            }
        }
    }
}
def save_user_score(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:

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
gameName = "Game02";
gameUserName = "Nick"; 
gameScore = 400000;
						
game = scoreBoardService.save_user_score(gameName, gameUserName, gameScore); /* returns the Game object. */
puts "gameName is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* 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"
                        }
                    }
                }
            }
        }
    }
}
def create_reward(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:

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
rewardName = "Reward01";
rewardDescription = "Reward Description";	
						
reward = rewardService.create_reward(rewardName, rewardDescription); /* returns the Reward object. */ 
puts "rewardName is #{reward.name}";
puts "rewardDescription is #{reward.description}";
jsonResponse = reward.to_s(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "Reward01",
                    "description": "Reward Description"
                }
            }
        }
    }
}
def get_all_rewards()

Fetches all the Rewards

Parameters:

N/A

Returns:

ArrayList 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
rewardList = Array.new();
rewardList = rewardService.get_all_rewards(); /* returns the list of Reward object. */
for reward in rewardList do
  puts "rewardName is #{reward.name}";
  puts "rewardDescription is #{reward.description}";
end
jsonResponse = rewardList.to_s(); /* 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 "
                    }
                ]
            }
        }
    }
}
def get_all_rewards_count()

Fetches the count of all the Rewards

Parameters:

N/A

Returns:

App42Response objects containing count of all the rewards of the App

Response: App42Response Object

Exception:

The method throws the following exception with the error code
/*
3005 - NOT FOUND - Rewards do not exist. 
*/ 	  
For more details click Exception
response = rewardService.get_all_rewards_count(); /* returns the App42Response objects. */
success = response.isResponseSuccess();
totalRecords = response.totalRecords();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*
                            
{
   "app42": {
       "response": {
           "success": true,
           "totalRecords": 3
       }
   }
}
def get_all_rewards_by_paging(max, offset)

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: 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
max = 1;
offset = 0;
						
rewardList  = Array.new();
rewardList = rewardService.get_all_rewards_by_paging(max,offset); /* returns the list of Reward object. */
for album in albumList do
  puts "rewardName is #{reward.name}";
  puts "rewardDescription is #{reward.description}";
end
jsonResponse = rewardList.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "rewardName",
                    "description": "rewardDescription"
                }
            }
        }
    }
}
def get_reward_by_name(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:

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
rewardName = "Reward01";
						
reward = rewardService.get_reward_by_name(rewardName); /* returns the Reward object. */ 
puts "rewardName is #{reward.name}";
puts "rewardDescription is #{reward.description}";
jsonResponse = reward.to_s(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "Reward01",
                    "description": "Reward Description"
                }
            }
        }
    }
}
def earn_rewards(gameName,gameUserName,rewardName,rewardPoints)

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 rewardpoints 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
gameName = "Game01";
gameUserName = "Nick";
rewardName = "Reward01";
rewardPoints = 1000;
						
reward = rewardService.earn_rewards(gameName, gameUserName, rewardName, rewardPoints); /* returns the Reward object. */ 
puts "rewardName is #{reward.name}";
puts "rewardgameName is #{reward.gameName}";
puts "rewarduserName is #{reward.userName}";
puts "rewardpoints  #{reward.points}";
jsonResponse = reward.to_s(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "Nick",
                    "name": "Reward01",
                    "points": 1000
                }
            }
        }
    }
}
def redeem_rewards(gameName,gameUserName,rewardName,rewardPoints)

Deducts the rewardpoints 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 rewardpoints 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
gameName = "Game01";
gameUserName = "Nick";
rewardName = "Reward01";
rewardPoints = 900;
						
reward = rewardService.redeem_rewards(gameName, gameUserName, rewardName, rewardPoints); /* returns the Reward object. */ 
puts "rewardName is #{reward.name}";
puts "rewardgameName is #{reward.gameName}";
puts "rewarduserName is #{reward.userName}";
puts "rewardpoints  #{reward.points}";
jsonResponse = reward.to_s(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "Nick",
                    "name": "Reward01",
                    "points": 900
                }
            }
        }
    }
}
def get_game_reward_points_for_user(gameName,gameUserName)

Fetches the reward points for a particular user.

Parameters:

gameName - Name of the game for which reward points have to be fetched
gameUserName - 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.
3006 - NOT FOUND - Reward with the name '<name>' does not exist. 
*/  		  
        
For more details click Exception
gameName = "Game01";
userName = "Nick";
						
reward = rewardService.get_game_reward_points_for_user(gameName, userName); /* returns the Reward object. */ 
puts "rewardName is #{reward.name}";
puts "rewardgameName is #{reward.gameName}";
puts "rewarduserName is #{reward.userName}";
puts "rewardpoints  #{reward.points}";

jsonResponse = reward.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "Nick",
                    "name": "Reward01",
                    "points": 900
                }
            }
        }
    }
}
def add_score(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:

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
gameName = "Game01";
gameUserName = "Nick";
gameScore = 1000000;
						
game = scoreService.add_score(gameName, gameUserName, gameScore); /* returns the Game object. */
puts "gameName is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 1000000
                        }
                    }
                }
            }
        }
    }
}
def deduct_score(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:

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
gameName = "Game01";
gameUserName = "Nick";
gameScore = 999900;	
					
game = scoreService.deduct_score(gameName, gameUserName, gameScore); /* returns the Game object. */
puts "gameName is #{game.name}";
scoreList = Array.new();
scoreList = game.scoreList();
for score in scoreList do
  puts "userName is #{score.userName}";
  puts "value is #{score.value}";
end
jsonResponse = game.to_s(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 999900
                        }
                    }
                }
            }
        }
    }
}