# ----------------------------------------------------------------------- # Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved. # ----------------------------------------------------------------------- require 'json/pure' require 'App42_Ruby_API/App42ResponseBuilder' require 'push/PushNotification' require 'push/DeviceType' module App42 module Push # # # PushNotificationResponseBuilder class converts the JSON response retrieved from # the server to the value object i.e Push Notification # # class PushNotificationResponseBuilder < App42ResponseBuilder # # Converts the response in JSON format to the value object i.e Push Notification # # @param json # - response in JSON format # # @return Push Notification object filled with json data # # def buildResponse(json) pushObj = PushNotification.new() channelList = Array.new pushObj.channelList=(channelList) pushObj.strResponse=json jsonObj = JSON.parse(json) jsonObjApp42 = jsonObj.fetch("app42"); jsonObjResponse = jsonObjApp42.fetch("response"); pushObj.isResponseSuccess=(jsonObjResponse.fetch("success")); jsonObjPush= jsonObjResponse.fetch("push"); buildObjectFromJSONTree(pushObj, jsonObjPush); if jsonObjPush.key?("channels") == false return pushObj end jsonObjChannels = jsonObjPush.fetch("channels"); if jsonObjChannels.key?("channel") == false return pushObj; end if jsonObjChannels.fetch("channel").instance_of?(Hash) jsonObjChannel = jsonObjChannels.fetch("channel"); channelObject = App42::Push::Channel.new(pushObj) buildObjectFromJSONTree(channelObject,jsonObjChannel); else jsonObjChannelArray= jsonObjChannels.fetch("channel"); jsonObjChannelArray.length.times do |i| jsonObjChannel = jsonObjChannelArray.fetch(i); channelObject = App42::Push::Channel.new(pushObj) buildObjectFromJSONTree(channelObject,jsonObjChannel); end end return pushObj; end end end end