require 'json/pure' require 'App42ResponseBuilder.rb' require 'appTab/Bill.rb' require 'appTab/BillMonth.rb' module App42 module AppTab # # # BillResponseBuilder class converts the JSON response retrieved from the # server to the value object i.e Bill # # class BillResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e Bill # # @param json # - response in JSON format # # @return Bill object filled with json data # # @throws Exception # def buildResponse(json) billsJsonObj = getServiceJSONObject("bills", json); billJsonObj = billsJsonObj.fetch("bill"); bill = buildBillObject(billJsonObj); bill.strResponse = json bill.isResponseSuccess = isResponseSuccess(json) return bill end # # Converts the Bill JSON object to the value object i.e Bill # # @param billJSONObj # - Bill data as JSONObject # # @return Bill object filled with json data # def buildBillObject(billJSONObj) bill = Bill.new buildObjectFromJSONTree(bill, billJSONObj) if billJSONObj.key?("storageTransaction") storageTransJson = billJSONObj["storageTransaction"] storageTrans = StorageTransaction.new() transactionList = Array.new storageTrans.transactionList=(transactionList) buildObjectFromJSONTree(storageTrans, storageTransJson) if storageTransJson.key?("transactions") && storageTransJson["transactions"].key?("transaction") if storageTransJson["transactions"].fetch("transaction").instance_of?(Hash) transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction"); transaction = App42::AppTab::TransactionStor.new(storageTrans) buildObjectFromJSONTree(transaction, transactionJsonObj) else transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction"); transactionJsonArray.length.times do |i| transactionJsonObj = userJSONArray[i] transaction = App42::AppTab::TransactionStor.new(storageTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); end end end end if billJSONObj.key?("timeTransaction") storageTransJson = billJSONObj.fetch("timeTransaction"); timeTrans = TimeTransaction.new() transactionList = Array.new timeTrans.transactionList=(transactionList) buildObjectFromJSONTree(timeTrans,storageTransJson); if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction") if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash) transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction"); transaction = App42::AppTab::TransactionTim.new(timeTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); else transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction"); transactionJsonArray.length.times do |i| transactionJsonObj = transactionJsonArray.fetch(i); transaction = App42::AppTab::TransactionTim.new(timeTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); end end end end if billJSONObj.key?("bandWidthTransaction") storageTransJson = billJSONObj.fetch("bandWidthTransaction"); bwTrans = BandwidthTransaction.new() transactionList = Array.new bwTrans.transactionList=(transactionList) buildObjectFromJSONTree(bwTrans,storageTransJson); if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction") if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash) transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction"); transaction = App42::AppTab::TransactionBand.new(bwTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); else transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction"); transactionJsonArray.length.times do |i| transactionJsonObj = transactionJsonArray.fetch(i); transaction = App42::AppTab::TransactionBand.new(bwTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); end end end end if billJSONObj.key?("levelTransaction") storageTransJson = billJSONObj.fetch("levelTransaction"); levelTrans = LevelTransaction.new() transactionList = Array.new levelTrans.transactionList=(transactionList) buildObjectFromJSONTree(levelTrans, storageTransJson); if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction") if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash) transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction"); transaction = App42::AppTab::TransactionLev.new(levelTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); else transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction"); transactionJsonArray.length.times do |i| transactionJsonObj = transactionJsonArray.fetch(i); transaction = App42::AppTab::TransactionLev.new(levelTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); end end end end if billJSONObj.key?("featureTransaction") storageTransJson = billJSONObj.fetch("featureTransaction"); featureTrans = FeatureTransaction.new() transactionList = Array.new featureTrans.transactionList=(transactionList) buildObjectFromJSONTree(featureTrans,storageTransJson); if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction") if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash) transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction"); transaction = App42::AppTab::TransactionFeat.new(featureTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); else transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction"); transactionJsonArray.length.times do |i| transactionJsonObj = transactionJsonArray.fetch(i); transaction = App42::AppTab::TransactionFeat.new(featureTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); end end end end if billJSONObj.key?("licenseTransaction") storageTransJson = billJSONObj.fetch("licenseTransaction"); licenseTrans = LicenseTransaction.new() transactionList = Array.new licenseTrans.transactionList=(transactionList) buildObjectFromJSONTree(licenseTrans, storageTransJson); if storageTransJson.key?("transactions") && storageTransJson.fetch("transactions").key?("transaction") if storageTransJson.fetch("transactions").fetch("transaction").instance_of?(Hash) transactionJsonObj = storageTransJson.fetch("transactions").fetch("transaction"); transaction = App42::AppTab::TransactionLic.new(licenseTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); else transactionJsonArray = storageTransJson.fetch("transactions").fetch("transaction"); transactionJsonArray.length.times do |i| transactionJsonObj = transactionJsonArray.fetch(i); transaction = App42::AppTab::TransactionLic.new(licenseTrans) buildObjectFromJSONTree(transaction, transactionJsonObj); end end end end return bill; end # # Converts the response in JSON format to the list of value objects i.e # Bill # # @param json # - response in JSON format # # @return List of Bill object filled with json data # # def buildArrayResponse(json) billsJSONObj = getServiceJSONObject("bill", json); billJSONArray = billsJSONObj["bill"] billList = Array.new() billJSONArray.length.times do |i| billJSONObject = billJSONArray[i] bill = buildBillObject(billJSONObject); bill.strResponse=json bill.isResponseSuccess = isResponseSuccess(json) billList.push(bill) end return billList end end end end