App42 Cloud API

iOS cloud SDK

Gaming

In order to use the various functions available under a particular API, a developer will have to allocate and initialize an instance of ServiceAPI. After initialization, apiKey and secretKey needs to be set which has been received while creating an application under App42.

ServiceAPI *serviceAPIObj = [[ServiceAPI alloc]init];
serviceAPIObj.apiKey = @"<API_KEY>";
serviceAPIObj.secretKey = @"<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 = [serviceAPIObj 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.

NSString *gameName = @"Game01";
NSString *gameDescription = @"GameDescription001";

Game *game = [gameService createGame:gameName gameDescription:gameDescription];  /* returns the Game object. */ 
NSLog(@"Game Name is = %@",game.name);
NSLog(@"Game Description is = %@",game.description); 
NSString *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 '{gameName}' already Exists".

NSString *gameName = @"Game01";
NSString *gameDescription = @"GameDescription001";

@try{
	Game *game = [gameService createGame:gameName gameDescription:gameDescription];  /* returns the Game object. */ 
} @catch(App42Exception *ex) {
	int appErrorCode = ex.appErrorCode;
	int httpErrorCode = ex.httpErrorCode;
	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
	}
	NSString *jsonText = ex.reason; /* 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 '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.

-(Game*)createGame:(NSString*)gameName gameDescription:(NSString*)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
NSString *gameName = @"Game01";
NSString *gameDescription = @"GameDescription001";

Game *game = [gameService createGame:gameName gameDescription:gameDescription];  /* returns the Game object. */ 
NSLog(@"Game Name is = %@",game.name);
NSLog(@"Game Description is = %@",game.description); 
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "description": "GameDescription001"
                }
            }
        }
    }
}
	
-(NSArray*)getAllGames

Fetches all games for the App.

Parameters:

N/A

Returns:

List of Game object containing all the games for the App

Response:NSArray

Exception:

The method throws the following exception with the error code.
/*
3001 - NOT FOUND - Games do not exist.
*/ 		       
For more details click Exception
NSArray *gameList = [gameService getAllGames]; /* returns the list of Game object. */ 
for(Game *game in gameList){
	NSLog(@"Game Name is = %@",game.name);
	NSLog(@"Game Description is = %@",game.description); 
	NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
}

                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": [
                    {
                        "name": "Game01",
                        "description": "GameDescription001"
                    },
                    {
                        "name": "Game02",
                        "description": "GameDescription001"
                    }
                ]
            }
        }
    }
}
-(App42Response*)getAllGamesCount

Fetches the count of all games for the App

Parameters:

N/A

Returns:

App42Response object containing count of all the Game for the App

Response: App42ResponseObject

For more details click Exception
App42Response *response = [gameService getAllGamesCount]; /* returns the App42Response objects. */
BOOL success = response.isResponseSuccess;
int totalRecords = response.totalRecords;
NSString *jsonResponse = [response toString]; /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
-(NSArray*)getAllGames:max offset: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:

List of Game object containing all the games for the App

Response: NSArray

Exception:

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

NSArray *gameList = [gameService getAllGames:max offset:offset]; /* returns the list of Game object. */ 
for(Game *game in gameList)
{
	NSLog(@"Game Name is = %@",game.name);
	NSLog(@"Game Description is = %@",game.description); 
	NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
}
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "gameName3",
                    "description": "gameDescription01"
                }
            }
        }
    }
}
-(Game*)getGameByName:(NSString*)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
NSString *gameName = @"Game01";
						
Game *game = [gameService getGameByName:gameName];  /* returns the Game object. */ 
	NSLog(@"Game Name is = %@",game.name);
	NSLog(@"Game Description is = %@",game.description); 
	NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "description": "GameDescription001"
                }
            }
        }
    }
}
-(Game*)getScoresByUser:(NSString*)gameName gameUserName:(NSString*)gameUserName

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
NSString *gameName = @"Game02";
NSString *userName = @"Nick";
   
Game *game = [scoreBoardService getScoresByUser:gameName gameUserName:gameUserName];  /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 400000
                        }
                    }
                }
            }
        }
    }
}

-(Game*)getAverageScoreByUser:(NSString*)gameName userName:(NSString*)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
NSString *gameName = @"Game02";
NSString *userName = @"Nick";						

Game *game = [scoreBoardService getAverageScoreByUser:gameName userName:userName]; /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
   
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "value": 45
                        }
                    }
                }
            }
        }
    }
}
-(Game*)getHighestScoreByUser:(NSString*)gameName gameUserName:(NSString*)gameUserName

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

Game *game = [scoreBoardService getHighestScoreByUser:gameName gameUserName:gameUserName];  /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 8790000
                        }
                    }
                }
            }
        }
    }
}
-(Game*)getLowestScoreByUser:(NSString*)gameName gameUserName:(NSString*)gameUserName

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

Game *game = [scoreBoardService getLowestScoreByUser:gameName gameUserName:gameUserName];  /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 400000
                        }
                    }
                }
            }
        }
    }
}
-(Game*)getTopRankings:(NSString*)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
NSString *gameName = @"Game02";

Game *game = [scoreBoardService getTopRankings:gameName];  /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": [
                            {
                                "userName": "GameUserName",
                                "value": 8790000
                            },
                            {
                                "userName": "GameUserName",
                                "value": 400000
                            }
                        ]
                    }
                }
            }
        }
    }
}
-(Game*)getTopNRankings:(NSString*)gameName max:(int)max

Retrieves the Top Rankings for the specified game.

Parameters:

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

Returns:

The Top rankings for a game

Response: Game Object

Exception:

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

Game *game = [scoreBoardService getTopNRankings:gameName max:max]; /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
    
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": [
                            {
                                "userName": "Nick",
                                "value": 10014
                            },
                            {
                                "userName": "Jay",
                                "value": 10013
                            }
                        ]
                    }
                }
            }
        }
    }
}
-(Game*)getUserRanking:(NSString*)gameName userName:(NSString*)userName

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 rank of the User

Response: Game Object

Exception:

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

Game *game = [scoreBoardService getUserRanking:gameName userName:userName]; /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
 
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "Nick",
                            "rank": 4,
                            "value": 89
                        }
                    }
                }
            }
        }
    }
}
-(Game*)saveUserScore:(NSString*)gameName gameUserName:(NSString*)gameUserName gameScore:(double)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
NSString *gameName = @"Game02";
NSString *gameUserName = @"Nick"; 
double gameScore = 400000;						

Game *game = [scoreBoardService saveUserScore:gameName gameUserName:gameUserName gameScore:gameScore];  /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game02",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 400000,
                            "createdOn": "2012-05-10T07:31:18.535Z"
                        }
                    }
                }
            }
        }
    }
}
-(Reward*)createReward:(NSString*)rewardName rewardDescription:(NSString*)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
NSString *rewardName = @"Reward01";
NSString *rewardDescription = @"Reward Description";						
Reward *reward = [rewardService createReward:rewardName rewardDescription:rewardDescription];  /* returns the Reward object. */ 
NSLog(@"rewardName is = %@",reward.name);
NSLog(@"rewardDescription is = %@",reward.description);
NSString *jsonResponse = [reward toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "Reward01",
                    "description": "Reward Description"
                }
            }
        }
    }
}
 
-(NSArray*)getAllRewards

Fetches all the Rewards

Parameters:

N/A

Returns:

List of Reward objects containing all the rewards of the App

Response: NSArray

Exception:

The method throws the following exception with the error code.
/*
3005 - NOT FOUND - Rewards do not exist.
*/ 	    
For more details click Exception
NSArray *rewardList = [rewardService getAllRewards]; /* returns the list of Reward object. */ 
for(Reward *reward in rewardList){
	NSLog(@"rewardName is = %@",reward.name);
	NSLog(@"rewardDescription is = %@",reward.description);
	NSString *jsonResponse = [reward toString]; /* returns the response in JSON format. (as shown below)*/
}
NSString *jsonResponse = [rewardList toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": [
                    {
                        "name": "Reward01",
                        "description": "Reward Description"
                    },
                    {
                        "name": "Reward02",
                        "description": "Second Reward's Description "
                    }
                ]
            }
        }
    }
}
	
-(App42Response*)getAllRewardsCount

Fetches the count of all the Rewards

Parameters:

N/A

Returns:

App42Response objects containing count of all the rewards of the App

Response: App42ResponseObject

For more details click Exception
App42Response *response = [rewardService getAllRewardsCount]; /* returns the App42Response objects. */
BOOL success = response.isResponseSuccess;
int totalRecords = response.totalRecords;
NSString *jsonResponse = [response toString]; /* returns the response in JSON format. (as shown below)*/   
{
   "app42": {
       "response": {
           "success": true,
           "totalRecords": 3
       }
   }
}
-(NSArray*)getAllRewards:(int)max offset:(int)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:

List of Reward objects containing all the rewards of the App

Response: NSArray

Exception:

This method throws following exception.
/*
3012 - NOT FOUND - The number of the rewards are less than the specified offset : <offset>.
*/ 		    
For more details click Exception
int max = 1;
int offset = 0;			
NSArray *rewardList = [rewardService getAllRewards:max offset:offset]; /* returns the list of Reward object. */ 
for(Reward *reward in rewardList)
{
NSLog(@"rewardName is = %@",reward.name);
NSLog(@"rewardDescription is = %@",reward.description);
NSString *jsonResponse = [reward toString]; /* returns the response in JSON format. (as shown below)*/
  
}
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "rewardName",
                    "description": "rewardDescription"
                }
            }
        }
    }
}	
-(Reward*)getRewardByName:(NSString*)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
NSString *rewardName = @"Reward01";
						
Reward *reward = [rewardService getRewardByName:rewardName];  /* returns the Reward object. */ 
NSLog(@"rewardName is = %@",reward.name);
NSLog(@"rewardDescription is = %@",reward.description);
NSString *jsonResponse = [reward toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "name": "Reward01",
                    "description": "Reward Description"
                }
            }
        }
    }
}
	
-(Reward*)earnRewards:(NSString*)gameName gameUserName:(NSString*)gameUserName rewardName:(NSString*)rewardName rewardPoints:(double)rewardsPoints

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
NSString *gameName = @"Game01";
NSString *gameUserName = @"Nick";
NSString *rewardName = @"Reward01";
double rewardPoints = 1000;
						
Reward *reward = [rewardService earnRewards:gameName gameUserName:gameUserName rewardName:rewardName rewardPoints:rewardsPoints];  /* returns the Reward object. */ 
NSLog(@"rewardName is = %@",reward.name);
NSLog(@"rewardGameName is  = %@",reward.gameName);
NSLog(@"rewardUserName is = %@",reward.userName);
NSLog(@"rewardDescription is = %f",reward.points);
NSString *jsonResponse = [reward toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "User01",
                    "name": "Reward01",
                    "points": 1000
                }
            }
        }
    }
}
	
-(Reward*)redeemRewards:(NSString*)gameName gameUserName:(NSString*)gameUserName rewardName:(NSString*)rewardName rewardPoints:(double)rewardsPoints

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
NSString *gameName = @"Game01";
NSString *gameUserName = @"Nick";
NSString *rewardName = @"Reward01";
double rewardPoints = 900;
						
Reward *reward = [rewardService redeemRewards:gameName gameUserName:gameUserName rewardName:rewardName rewardPoints:rewardsPoints];  /* returns the Reward object. */ 
NSLog(@"rewardName is = %@",reward.name);
NSLog(@"rewardGameName is  = %@",reward.gameName);
NSLog(@"rewardUserName is = %@",reward.userName);
NSLog(@"rewardDescription is = %f",reward.points);
NSString *jsonResponse = [reward toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "User01",
                    "name": "Reward01",
                    "points": 900
                }
            }
        }
    }
}
	
-(Reward*)getGameRewardPointsForUser:(NSString*)gameName userName:(NSString*)userName

Fetches the reward points for a particular user.

Parameters:

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

Returns:

Reward object containing the reward points for the specified user

Response: Reward Object

Exception:

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
NSString *gameName = @"Game01";
NSString *userName = @"Nick";						

Reward *reward = [rewardService getGameRewardPointsForUser:gameName userName:userName];  /* returns the Reward object. */ 
NSLog(@"rewardName is = %@",reward.name);
NSLog(@"rewardGameName is  = %@",reward.gameName);
NSLog(@"rewardUserName is = %@",reward.userName);
NSLog(@"rewardDescription is = %f",reward.points);
NSString *jsonResponse = [reward toString]; /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "rewards": {
                "reward": {
                    "gameName": "Game01",
                    "userName": "User01",
                    "name": "Reward01",
                    "points": 900
                }
            }
        }
    }
}
	
-(Game*)addScore:(NSString*)gameName gameUserName:(NSString*)gameUserName gScore:(double)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
NSString *gameName = @"Game01";
NSString *gameUserName = @"Nick";
double gameScore = 1000000;

Game *game = [scoreService addScore:gameName gameUserName:gameUserName gScore:gameScore];  /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 1000000
                        }
                    }
                }
            }
        }
    }
}
	
-(Game*)deductScore:(NSString*)gameName gameUserName:(NSString*)gameUserName gameScore:(double)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
NSString *gameName = @"Game01";
NSString *gameUserName = @"Nick";
double gameScore = 999900;
						
Game *game = [scoreService deductScore:gameName gameUserName:gameUserName gameScore:gameScore];  /* returns the Game object. */ 
NSLog(@"Game name is = %@",game.name);
NSMutableArray *scoreList = game.scoreList;
for(Score *score in scoreList)
{
	NSLog(@"User Name is = %@",score.userName);
	NSLog(@"Value is = %f",score.value); 
}
NSString *jsonResponse = [game toString]; /* returns the response in JSON format. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "games": {
                "game": {
                    "name": "Game01",
                    "scores": {
                        "score": {
                            "userName": "GameUserName",
                            "value": 999900
                        }
                    }
                }
            }
        }
    }
}