require 'json/pure' require 'App42ResponseBuilder.rb' require 'appTab/SchemeData.rb' module App42 module AppTab class SchemeResponseBuilder < App42ResponseBuilder def buildResponse(json) appTabJSONObj = getServiceJSONObject("schemes", json); schemeJSONObj = appTabJSONObj.fetch("scheme"); scheme = App42::AppTab::SchemeData.new() scheme = buildSchemeObject(schemeJSONObj); scheme.strResponse = json scheme.isResponseSuccess = isResponseSuccess(json) return scheme; end def buildSchemeObject(schemeJSONObj) schemeObj = App42::AppTab::SchemeData.new() buildObjectFromJSONTree(schemeObj, schemeJSONObj); if schemeJSONObj.key?("schemes") && schemeJSONObj.fetch("schemes").key?("scheme") if schemeJSONObj.fetch("schemes").fetch("scheme").instance_of?(Hash) schemeJSONObject = schemeJSONObj.fetch("scheme"); buildObjectFromJSONTree(schemeObj, schemeJSONObject); else schemeJSONArray = schemeJSONObj.fetch("scheme"); schemeJSONArray.length.times do |i| schemeJSONOb = schemeJSONArray.fetch(i); buildObjectFromJSONTree(schemeObj, schemeJSONOb); end end end return schemeObj; end def buildArrayResponse(json) schemesJSONObj = getServiceJSONObject("schemes", json); schemeObj = Array.new(); if schemesJSONObj.fetch("scheme").instance_of?(Array) schemeJSONArray = schemesJSONObj.fetch("scheme"); schemeJSONArray.length.times do |i| schemeJSONObject = schemeJSONArray.fetch(i); schemeData = App42::AppTab::SchemeData.new() schemeData = buildSchemeObject(schemeJSONObject); schemeData.strResponse = json schemeData.isResponseSuccess = isResponseSuccess(json) schemeObj.push(schemeData); end else schemeJSONObject = schemesJSONObj.fetch("scheme"); schemeData = App42::AppTab::SchemeData.new() schemeData = buildSchemeObject(schemeJSONObject); schemeData.strResponse = json schemeData.isResponseSuccess = isResponseSuccess(json) schemeObj.push(schemeData); end return schemeObj; end end end end