require 'json/pure' require 'App42ResponseBuilder.rb' require 'appTab/PackageData.rb' module App42 module AppTab class PackageResponseBuilder < App42ResponseBuilder def buildResponse(json) schemesJSONObj = getServiceJSONObject("schemes", json); schemeJSONObj = schemesJSONObj.fetch("scheme"); packageData = App42::AppTab::PackageData.new() packageData = buildPackageDataObject(schemeJSONObj); packageData.strResponse = json packageData.isResponseSuccess = isResponseSuccess(json) return packageData; end def buildPackageDataObject(schemeJSONObj) packageObj = App42::AppTab::PackageData.new() if schemeJSONObj.key?("packages") && schemeJSONObj.fetch("packages").key?("packageItem") if schemeJSONObj.fetch("packages").fetch("packageItem").instance_of?(Hash) packageItemJSONObj = schemeJSONObj.fetch("packages").fetch("packageItem"); buildObjectFromJSONTree(packageObj, packageItemJSONObj); if packageItemJSONObj.key?("bandwidth") if packageItemJSONObj.fetch("bandwidth").instance_of?(Hash) bandwidthJSONObj = packageItemJSONObj.fetch("bandwidth"); bandwidth = App42::AppTab::BandwidthData.new(packageObj) buildObjectFromJSONTree(bandwidth, bandwidthJSONObj); if bandwidthJSONObj.key?("limit") if bandwidthJSONObj.fetch("limit").instance_of?(Hash) limitJsonObj = bandwidthJSONObj.fetch("limit"); limitObj = App42::AppTab::LimitBandwidth.new(bandwidth) buildObjectFromJSONTree(limitObj, limitJsonObj); end end end end if packageItemJSONObj.key?("features") && packageItemJSONObj.fetch("features").key?("feature") if packageItemJSONObj.fetch("features").fetch("feature").instance_of?(Hash) featureJSONObj = packageItemJSONObj.fetch("features").fetch("feature"); feature = App42::AppTab::FeatureData.new(packageObj) buildObjectFromJSONTree(feature, featureJSONObj); else packagesJSONArray = packageItemJSONObj.fetch("features").fetch("feature"); puts "---------I M HERE___________" packagesJSONArray.length.times do |i| featureJSONObj = packagesJSONArray.fetch(i); feature = App42::AppTab::FeatureData.new(packageObj) buildObjectFromJSONTree(feature, featureJSONObj); end end end if packageItemJSONObj.key?("storage") if packageItemJSONObj.fetch("storage").instance_of?(Hash) storageJSONObj = packageItemJSONObj.fetch("storage"); storage = App42::AppTab::StorageData.new(packageObj) buildObjectFromJSONTree(storage, storageJSONObj); if storageJSONObj.key?("limit") if storageJSONObj.fetch("limit").instance_of?(Hash) limitJsonObj = storageJSONObj.fetch("limit"); limitObj = App42::AppTab::LimitStorage.new(storage) buildObjectFromJSONTree(limitObj, limitJsonObj); end end end end end end return packageObj; end def buildArrayResponse(json) packagesJSONObj = getServiceJSONObject("schemes", json); packageList = Array.new() if packagesJSONObj.key?("scheme") && packagesJSONObj.fetch("scheme").key?("packages") && packagesJSONObj.fetch("scheme").fetch("packages").key?("packageItem") if packagesJSONObj.fetch("scheme").fetch("packages").fetch("packageItem").instance_of?(Array) schemeJSONArray = packagesJSONObj.fetch("scheme").fetch("packages").fetch("packageItem"); schemeJSONArray.length.times do |i| schemeJSONObject = schemeJSONArray.fetch(i); scheme = buildPackageDataObject(schemeJSONObject); scheme.strResponse = json scheme.isResponseSuccess = isResponseSuccess(json) packageList.push(scheme); end end else schemeJSONObj = packagesJSONObj.getJSONObject("scheme").fetch("packages").fetch("packageItem"); scheme = buildPackageDataObject(schemeJSONObj); scheme.strResponse = json scheme.isResponseSuccess = isResponseSuccess(json) packageList.push(scheme); end return packageList; end end end end