Class: App42::Push::PushNotificationResponseBuilder

Inherits:
App42ResponseBuilder show all
Defined in:
lib/push/PushNotificationResposneBuilder.rb

Overview

PushNotificationResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Push Notification

Instance Method Summary collapse

Methods inherited from App42ResponseBuilder

#buildObjectFromJSONTree, #getNames, #getServiceJSONObject, #getTotalRecords, #isResponseSuccess

Instance Method Details

#buildResponse(json) ⇒ Object

Converts the response in JSON format to the value object i.e Push Notification

Parameters:

  • json
    • response in JSON format

Returns:

  • Push Notification object filled with json data



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/push/PushNotificationResposneBuilder.rb', line 28

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