class App42::Game::GameResponseBuilder
GameResponseBuilder
class converts the JSON response retrieved from the server to the value object i.e Game
Public Instance Methods
buildArrayResponse(json)
click to toggle source
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
# File lib/game/GameResponseBuilder.rb, line 47 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
buildGameObject(gameJSONObject)
click to toggle source
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
# File lib/game/GameResponseBuilder.rb, line 79 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
buildResponse(json)
click to toggle source
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
# File lib/game/GameResponseBuilder.rb, line 27 def buildResponse(json) gamesJSONObj = getServiceJSONObject("games", json) gameJSONObj = gamesJSONObj["game"] game = buildGameObject(gameJSONObj); game.isResponseSuccess = isResponseSuccess(json) game.strResponse=json return game end