require 'json/pure' require 'App42ResponseBuilder.rb' require 'appTab/Test.rb' require 'appTab/DiscountType.rb' module App42 module AppTab class DiscountResponseBuilder < App42ResponseBuilder def buildResponse(json) discountsJSONObj = getServiceJSONObject("discounts", json); discountJSONObj = discountsJSONObj.fetch("discount"); discountData = App42::AppTab::Test.new() discountData = buildDiscountObject(discountJSONObj); discountData.strResponse = json discountData.isResponseSuccess = isResponseSuccess(json) return discountData; end def buildDiscountObject(discountJSONObj) discount1 = App42::AppTab::Test.new() buildObjectFromJSONTree(discount1, discountJSONObj); if discountJSONObj.key?("discountDetails") if discountJSONObj.fetch("discountDetails").instance_of?(Hash) profileJSONObj = discountJSONObj.fetch("discountDetails"); discounDetails = App42::AppTab::Discount.new(discount1) buildObjectFromJSONTree(discounDetails, profileJSONObj); end end return discount1; end # # @param discountJSONObj # @return # @throws Exception # def buildArrayObject(json) discountJSONObj = getServiceJSONObject("discounts", json); discountList = Array.new if discountJSONObj.fetch("discount").instance_of?(Array) discountsJSONArray = discountJSONObj.fetch("discount"); discountsJSONArray.length.times do |i| discountJSONObj1 = discountsJSONArray.fetch(i); discountObj = App42::AppTab::Test.new() discountObj = buildDiscountObject(discountJSONObj1); discountObj.strResponse = json discountObj.isResponseSuccess = isResponseSuccess(json) discountList.push(discountObj); end else jsonObjConfig = discountJSONObj.fetch("discount"); discountObj = App42::AppTab::Test.new() discountObj = buildDiscountObject(jsonObjConfig); discountObj.strResponse = json discountObj.isResponseSuccess = isResponseSuccess(json) discountList.push(discountObj); end return discountList; end end end end