class App42::AppTab::BillResponseBuilder
BillResponseBuilder
class converts the JSON response retrieved from the server to the value object i.e Bill
Public Instance Methods
buildArrayResponse(json)
click to toggle source
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
# File lib/appTab/BillResponseBuilder.rb, line 223 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
buildBillObject(billJSONObj)
click to toggle source
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
# File lib/appTab/BillResponseBuilder.rb, line 43 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
buildResponse(json)
click to toggle source
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
# File lib/appTab/BillResponseBuilder.rb, line 25 def buildResponse(json) billsJsonObj = getServiceJSONObject("bills", json); billJsonObj = billsJsonObj.fetch("bill"); bill = buildBillObject(billJsonObj); bill.strResponse = json bill.isResponseSuccess = isResponseSuccess(json) return bill end