Class: App42ResponseBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/App42ResponseBuilder.rb

Instance Method Summary collapse

Instance Method Details

#buildObjectFromJSONTree(obj, jsonObj) ⇒ Object

@param obj

@param jsonObj
@raise Exception


11
12
13
14
15
16
17
18
# File 'lib/App42ResponseBuilder.rb', line 11

def buildObjectFromJSONTree(obj,jsonObj)
  names = getNames(jsonObj)
  for name in names
    value = jsonObj[name]
    fieldName = "@"+name
    obj.instance_variable_set(:"#{fieldName}", value)
  end
end

#getNames(obj) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/App42ResponseBuilder.rb', line 44

def getNames(obj)
  names = []
  obj.each do |key, value|
    # puts"key is #{key}"  # key holds the key, value holds the value
    names.push(key)
  end
  return names
end

#getServiceJSONObject(serviceName, json) ⇒ Object

@param serviceName

@param json
@return
@raise Exception


25
26
27
28
29
30
31
# File 'lib/App42ResponseBuilder.rb', line 25

def getServiceJSONObject(serviceName,json)
  jsonObj = JSON.parse(json) rescue nil
  jsonObjApp42 = jsonObj["app42"]
  jsonObjResponse = jsonObjApp42["response"]
  jsonObjService = jsonObjResponse["#{serviceName}"]
  return jsonObjService;
end

#getTotalRecords(json) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/App42ResponseBuilder.rb', line 53

def getTotalRecords(json)
  totalRecords = -1;
  jsonObj = JSON.parse(json) rescue nil
  jsonObjApp42 = jsonObj["app42"]
  jsonObjResponse = jsonObjApp42["response"]
  if jsonObjResponse != nil && jsonObjResponse.key?("totalRecords")
    totalRecords = jsonObjResponse.fetch("totalRecords");
  end
  return totalRecords
end

#isResponseSuccess(json) ⇒ Object

@param json

@return
@raise Exception


37
38
39
40
41
42
# File 'lib/App42ResponseBuilder.rb', line 37

def isResponseSuccess(json)
  jsonObj = JSON.parse(json) rescue nil
  jsonObjApp42 = jsonObj["app42"]
  jsonObjResponse = jsonObjApp42["response"]
  return jsonObjResponse["success"]
end