# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'json/pure' require 'App42ResponseBuilder.rb' require 'game/Game.rb' module App42 module Game # # # GameResponseBuilder class converts the JSON response retrieved from the # server to the value object i.e Game # # class GameResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e Game # # @param json # - response in JSON format # # @return Game object filled with json data # # def buildResponse(json) gamesJSONObj = getServiceJSONObject("games", json) gameJSONObj = gamesJSONObj["game"] game = buildGameObject(gameJSONObj); game.isResponseSuccess = isResponseSuccess(json) game.strResponse=json return game end # # Converts the response in JSON format to the list of value objects i.e # Game # # @param json # - response in JSON format # # @return List of Game object filled with json data # # def buildArrayResponse(json) gamesJSONObj = getServiceJSONObject("games", json) gameList = Array.new if gamesJSONObj["game"].instance_of?(Array) gameJSONArray = gamesJSONObj["game"] gameJSONArray.length.times do |i| gameJSONObj = gameJSONArray[i] game = buildGameObject(gameJSONObj); game.isResponseSuccess = isResponseSuccess(json) game.strResponse=json gameList.push(game) end else gameJSONObject = gamesJSONObj["game"] game = buildGameObject(gameJSONObject); game.isResponseSuccess = isResponseSuccess(json) game.strResponse=json gameList.push(game) end return gameList end # # Converts the Game JSON object to the value object i.e Game # # @param gameJSONObject # - Game data as JSONObject # # @return Game object filled with json data # def buildGameObject(gameJSONObject) game = Game.new() scoreList = Array.new game.scoreList=(scoreList) buildObjectFromJSONTree(game, gameJSONObject); if gameJSONObject.key?("scores") && gameJSONObject.fetch("scores").key?("score") if gameJSONObject.fetch("scores").fetch("score").instance_of?(Hash) scoreJSONObj = gameJSONObject.fetch("scores").fetch("score"); score = App42::Game::Score.new(game) buildObjectFromJSONTree(score, scoreJSONObj); else scoreJSONArray= gameJSONObject.fetch("scores").fetch("score"); scoreJSONArray.length.times do |i| scoreJSONObj = scoreJSONArray[i] score = App42::Game::Score.new(game) buildObjectFromJSONTree(score, scoreJSONObj); end end end return game end end end end