Class: App42::Session::SessionResponseBuilder

Inherits:
App42ResponseBuilder show all
Defined in:
lib/session/SessionResponseBuilder.rb

Overview

SessionResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Session

Instance Method Summary collapse

Methods inherited from App42ResponseBuilder

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

Instance Method Details

#buildSessionResponse(json) ⇒ Object

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

Parameters:

  • json
    • response in JSON format

Returns:

  • Session object filled with json data



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
# File 'lib/session/SessionResponseBuilder.rb', line 30

def buildSessionResponse(json)
  sessionObj = Session.new
  attributeList = Array.new()
  sessionObj.attributeList = attributeList
  sessionObj.strResponse = json
  jsonObj = JSON.parse(json)
  jsonObjApp42 = jsonObj.fetch("app42")
  jsonObjResponse = jsonObjApp42.fetch("response")
  sessionObj.isResponseSuccess=(jsonObjResponse.fetch("success"))
  jsonObjSession = jsonObjResponse.fetch("session")

  buildObjectFromJSONTree(sessionObj,jsonObjSession)

  if jsonObjSession.has_key?("attributes") == false
    return sessionObj
  end

  jsonObjAttributes = jsonObjSession.fetch("attributes")

  if jsonObjAttributes.has_key?("attribute") == false
    return sessionObj
  end
  if jsonObjAttributes["attribute"].instance_of?(Hash)
    # Only One attribute is there
    jsonObjAttribute = jsonObjAttributes.fetch("attribute")
    attribute = App42::Session::Attribute.new(sessionObj)
    buildObjectFromJSONTree(attribute,jsonObjAttribute)
  else
    jsonObjAttributeArray = jsonObjAttributes.fetch("attribute")
    jsonObjAttributeArray.length.times do |i|
      # Get Individual Attribute Node and set it into Object
      jsonObjAttribute = jsonObjAttributeArray[i]
      attribute = App42::Session::Attribute.new(sessionObj)
      buildObjectFromJSONTree(attribute,jsonObjAttribute)
    end
  end
  return sessionObj
end