# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'json/pure' require 'App42_Ruby_API/App42ResponseBuilder' require 'email/Email' module App42 module Email # # EmailResponseBuilder class converts the JSON response retrieved from the # server to the value object i.e Email # class EmailResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e Email # # @param json # - response in JSON format # # @return Email object filled with json data # def buildResponse(json) emailObj = Email.new() configList = Array.new emailObj.configList=(configList) emailObj.strResponse=json jsonObj = JSON.parse(json) jsonObjApp42 = jsonObj["app42"] jsonObjResponse = jsonObjApp42["response"] emailObj.isResponseSuccess=(jsonObjResponse.fetch("success")) jsonObjEmail = jsonObjResponse["email"] buildObjectFromJSONTree(emailObj, jsonObjEmail); if jsonObjEmail.has_key?("configurations") == false return emailObj end jsonEmailConfig = jsonObjEmail["configurations"] if jsonEmailConfig.has_key?("config") == false return emailObj end if jsonEmailConfig["config"].instance_of?(Hash) # Only One attribute is there jsonObjConfig = jsonEmailConfig["config"] configItem = App42::Email::Configuration.new(emailObj) buildObjectFromJSONTree(configItem, jsonObjConfig); else # There is an Array of attribute jsonObjConfigArray = jsonEmailConfig["config"] jsonObjConfigArray.length.times do |i| # Get Individual Attribute Node and set it into Object jsonObjConfig = jsonObjConfigArray[i] configItem = App42::Email::Configuration.new(emailObj) buildObjectFromJSONTree(configItem, jsonObjConfig); end end return emailObj end end end end