The ongoing football fever of FIFA World Cup 2014 has taken a cloud toll over us as we could not resist coming up with a Leaderboad of current matches on our blog.The battle going on among the players to take their teams to top 16 has already shot up the number of sleepless nights. Well, we were just wondering about the scenario when the top teams of 2014 will put their strategic game play in semi finals & finals to win the World Cup. Yes, it is going to get crazier.
FIFA 2014 Leaderboard is developed with Leaderboard APIs of App42 Backend as a Service. It will keep you well informed about the highs & lows of your favorite team. So, keep watching! Using such powerful backend APIs, FIFA 2014 Leaderboard has been developed in few hours with minimum lines of code. It was so easy that yesterday we thought to create a Leaderboard and today we have made it live. Exciting!!!
Below is an overview of our APIs that have been used to make it happen.
Initialize API
ServiceAPI serviceAPI = new ServiceAPI("API_KEY", "SECRET_KEY");
GameService gameService = serviceAPI.buildGameService();
ScoreBoardService scoreBoardService = serviceAPI.buildScoreBoardService();
Save score with additional data
/* get game Object
*
* gameName is the name of the game
*
*/
Game gameInstance = null;
try {
gameInstance = gameService.getGameByName("gameName");
} catch (App42Exception exception) {
int appErrorCode = exception.getAppErrorCode();
int httpErrorCode = exception.getHttpErrorCode();
if (appErrorCode == 3002) {
// create new game
gameInstance = gameService.createGame("gameName", "FIFA World Cup 2014");
}
}
// set DB Name
// you can create DB from your AppHQ Console
App42API.setDbName("DB_NAME");
// colName is the name of the collection
// null is done in order to retrieve all
scoreBoardService.setQuery("colName", null);
// add your additional data in the form of JSONObejct
// this will save your additional data in the db
scoreBoardService.addJSONObject(colName, jsonObject);
/* this will save your score
*
* gameName is the name of your game
* teamName is the country name
* score is the total points of the team
*/
Game game = scoreBoardService.saveUserScore("gameName", "teamName", score);
Retrieve Score
/*
* Create group-wise Leader Board
*
*/
ArrayList teamList = new ArrayList();
teamList.add("team1");
teamList.add("team2");
teamList.add("team3");
teamList.add("team4");
Game gameInstance = scoreBoardService.getTopNRankersByGroup(gameName,teamList);
// this will retrieve a sorted list of scores along with the
// additional data, based on the group you have created.
You can see how convenient, thrilling and easy it was for us to create a Leaderboard in no time at all. Similarly, you can also create a gaming Leaderboard of your choice with minimal coding in much lesser time.
Leave A Reply