Class: App42::AppTab::UsageResponseBuilder
- Inherits:
-
App42ResponseBuilder
- Object
- App42ResponseBuilder
- App42::AppTab::UsageResponseBuilder
- Defined in:
- lib/appTab/UsageResponseBuilder.rb
Overview
UsageResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Usage
Instance Method Summary collapse
-
#buildResponse(json) ⇒ Object
Converts the response in JSON format to the value object i.e Usage.
Methods inherited from App42ResponseBuilder
#buildObjectFromJSONTree, #getNames, #getServiceJSONObject, #getTotalRecords, #isResponseSuccess
Instance Method Details
#buildResponse(json) ⇒ Object
Converts the response in JSON format to the value object i.e Usage
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/appTab/UsageResponseBuilder.rb', line 27 def buildResponse(json) appTabJSONObj = getServiceJSONObject("appTab", json); usageJsonObj = appTabJSONObj.fetch("usages").fetch("usage"); usage = Usage.new usage.strResponse = json usage.isResponseSuccess = isResponseSuccess(json) buildObjectFromJSONTree(usage, usageJsonObj); if usageJsonObj.key?("level") levelList = Array.new usage.levelList=(levelList) if usageJsonObj.fetch("level").instance_of?(Hash) levelJSONObj = usageJsonObj.fetch("level"); level = App42::AppTab::Level.new(usage) buildObjectFromJSONTree(level, levelJSONObj); else levelJSONArray = usageJsonObj.fetch("level"); levelJSONArray.length.times do |i| levelJSONObj = levelJSONArray.fetch(i); level = App42::AppTab::Level.new(usage) buildObjectFromJSONTree(level, levelJSONObj); end end elsif usageJsonObj.key?("oneTime") oneTimeList = Array.new usage.oneTimeList=(oneTimeList) if usageJsonObj.fetch("oneTime").instance_of?(Hash) oneTimeJSONObj = usageJsonObj.fetch("oneTime"); oneTime = App42::AppTab::OneTime.new(usage) buildObjectFromJSONTree(oneTime, oneTimeJSONObj); else oneTimeJSONArray = usageJsonObj.fetch("oneTime"); oneTimeJSONArray.length.times do |i| oneTimeJSONObj = oneTimeJSONArray.fetch(i); oneTime = App42::AppTab::OneTime.new(usage) buildObjectFromJSONTree(oneTime, oneTimeJSONObj); end end elsif usageJsonObj.key?("feature") featureList = Array.new usage.featureList=(featureList) if usageJsonObj.fetch("feature").instance_of?(Hash) featureJSONObj = usageJsonObj.fetch("feature"); feature = App42::AppTab::Feature.new(usage) buildObjectFromJSONTree(feature, featureJSONObj); else featureJSONArray = usageJsonObj.fetch("feature"); featureJSONArray.length.times do |i| featureJSONObj = featureJSONArray.fetch(i); feature = App42::AppTab::Feature.new(usage) buildObjectFromJSONTree(feature, featureJSONObj); end end elsif usageJsonObj.key?("bandwidth") bandwidthList = Array.new usage.bandwidthList=(bandwidthList) if usageJsonObj.fetch("bandwidth").instance_of?(Hash) bandwidthJSONObj = usageJsonObj.fetch("bandwidth"); bandwidth = App42::AppTab::Bandwidth.new(usage) buildObjectFromJSONTree(bandwidth, bandwidthJSONObj); else bandwidthJSONArray = usageJsonObj.fetch("bandwidth"); bandwidthJSONArray.length.times do |i| bandwidthJSONObj = bandwidthJSONArray.fetch(i); bandwidth = App42::AppTab::Bandwidth.new(usage) buildObjectFromJSONTree(bandwidth, bandwidthJSONObj); end end elsif usageJsonObj.key?("storage") storageList = Array.new usage.storageList=(storageList) if usageJsonObj.fetch("storage").instance_of?(Hash) storageJSONObj = usageJsonObj.fetch("storage"); storage = App42::AppTab::Storage.new(usage) buildObjectFromJSONTree(storage, storageJSONObj); else storageJSONArray = usageJsonObj.fetch("storage"); storageJSONArray.length.times do |i| storageJSONObj = storageJSONArray.fetch(i); storage = App42::AppTab::Storage.new(usage) buildObjectFromJSONTree(storage, storageJSONObj); end end elsif usageJsonObj.key?("time") timeList = Array.new usage.timeList=(timeList) if usageJsonObj.fetch("time").instance_of?(Hash) timeJSONObj = usageJsonObj.fetch("time"); time = App42::AppTab::Time.new(usage) buildObjectFromJSONTree(time, timeJSONObj); else timeJSONArray = usageJsonObj.fetch("time"); timeJSONArray.length.times do |i| timeJSONObj = timeJSONArray.fetch(i); time = App42::AppTab::Time.new(usage) buildObjectFromJSONTree(time, timeJSONObj); end end # elsif usageJsonObj.key?("custom") # customList = Array.new # usage.customList=(customList) # if usageJsonObj.fetch("custom").instance_of?(Hash) # customJSONObj = usageJsonObj.fetch("custom"); # custom = App42::Usage::Custom(usage) # buildObjectFromJSONTree(custom, customJSONObj); # else # customJSONArray = usageJsonObj.fetch("custom"); # customJSONArray.length.times do |i| # customJSONObj = customJSONArray.getJSONObject(i); # custom = App42::Usage::Custom(usage) # buildObjectFromJSONTree(custom, customJSONObj); # end # end end return usage; end |