class App42::Game::RewardResponseBuilder

RewardResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Reward

Public Instance Methods

buildArrayRewards(json) click to toggle source

Converts the response in JSON format to the list of value objects i.e Reward

@param json

- response in JSON format

@return List of Reward object filled with json data

# File lib/game/RewardResponseBuilder.rb, line 61
def buildArrayRewards(json)
  rewardList = Array.new
  rewardsJSONObj = getServiceJSONObject("rewards", json)
  rewardsJSONArray = rewardsJSONObj.fetch("reward");

  if rewardsJSONObj["reward"].instance_of?(Array)
    rewardsJSONArray.length.times do |i|
      rewardJSONObj = rewardsJSONArray[i]
      reward = buildRewardObject(rewardJSONObj);
      reward.isResponseSuccess = isResponseSuccess(json)
      reward.strResponse=json
      rewardList.push(reward);
    end
  else
    rewardJSONObj = rewardsJSONObj["reward"]
    reward = buildRewardObject(rewardJSONObj);
    reward.strResponse=json
    reward.isResponseSuccess = isResponseSuccess(json)
    rewardList.push(reward);
  end
  return  rewardList
end
buildResponse(json) click to toggle source
Converts the response in JSON format to the value object i.e Reward

@param json

- response in JSON format

@return Reward object filled with json data

# File lib/game/RewardResponseBuilder.rb, line 25
def buildResponse(json)
  rewardsJSONObj = getServiceJSONObject("rewards", json)
  rewardJSONObj = rewardsJSONObj["reward"]
  reward = buildRewardObject(rewardJSONObj);
  reward.isResponseSuccess = isResponseSuccess(json)
  reward.strResponse=json
  return reward
end
buildRewardObject(rewardJSONObj) click to toggle source

Converts the Reward JSON object to the value object i.e Reward

@param rewardJSONObj

- Reward data as JSONObject

@return Reward object filled with json data

# File lib/game/RewardResponseBuilder.rb, line 44
def buildRewardObject(rewardJSONObj)
  reward = Reward.new()
  buildObjectFromJSONTree(reward, rewardJSONObj);
  return reward
end