# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'json/pure' require 'App42ResponseBuilder.rb' require 'game/Reward.rb' module App42 module Game # # RewardResponseBuilder class converts the JSON response retrieved from the # server to the value object i.e Reward # class RewardResponseBuilder < App42ResponseBuilder # # 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 # # def buildResponse(json) rewardsJSONObj = getServiceJSONObject("rewards", json) rewardJSONObj = rewardsJSONObj["reward"] reward = buildRewardObject(rewardJSONObj); reward.isResponseSuccess = isResponseSuccess(json) reward.strResponse=json return reward end # # 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 # # def buildRewardObject(rewardJSONObj) reward = Reward.new() buildObjectFromJSONTree(reward, rewardJSONObj); return reward end # # 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 # # 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 end end end