require 'json/pure' require 'App42ResponseBuilder.rb' require 'appTab/License.rb' module App42 module AppTab # # # LicenseResponseBuilder class converts the JSON response retrieved from the # server to the value object i.e License # # class LicenseResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e License # # @param json # - response in JSON format # # @return License object filled with json data # # @throws Exception # def buildResponse(json) appTabJSONObj = getServiceJSONObject("appTab", json); licenceJSONObj = appTabJSONObj.fetch("licenses").fetch("license"); license = buildLicenseObject(licenceJSONObj); license.strResponse=json license.isResponseSuccess = isResponseSuccess(json) return license end # # Converts the License JSON object to the value object i.e License # # @param licenceJSONObj # - License data as JSONObject # # @return License object filled with json data # def buildLicenseObject(licenceJSONObj) license = License.new buildObjectFromJSONTree(license, licenceJSONObj); return license end # # Converts the response in JSON format to the list of value objects i.e # License # # @param json # - response in JSON format # # @return List of License object filled with json data # def buildArrayResponse(json) appTabJSONObj = getServiceJSONObject("appTab", json); license = License.new() licenseList = Array.new if appTabJSONObj.fetch("licenses").fetch("license").instance_of?(Array) licenseJSONArray = appTabJSONObj.fetch("licenses").fetch("license") licenseJSONArray.length.times do |i| licenseJSONObject = licenseJSONArray[i] license = buildLicenseObject(licenseJSONObject); license.strResponse=json license.isResponseSuccess = isResponseSuccess(json) licenseList.push(license) end else licenseJSONObject = appTabJSONObj["licenses"]["license"] license = buildLicenseObject(licenseJSONObject); license.strResponse=json license.isResponseSuccess = isResponseSuccess(json) licenseList.push(license) end return licenseList end end end end