class App42ResponseBuilder
Public Instance Methods
buildObjectFromJSONTree(obj,jsonObj)
click to toggle source
@param obj @param jsonObj @raise Exception
# File lib/App42_Ruby_API/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)
click to toggle source
# File lib/App42_Ruby_API/App42ResponseBuilder.rb, line 45 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)
click to toggle source
@param serviceName @param json @return @raise Exception
# File lib/App42_Ruby_API/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)
click to toggle source
# File lib/App42_Ruby_API/App42ResponseBuilder.rb, line 54 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 #json_obj = JSON.parse(json) rescue nil #totalRecords = json_obj.fetch("totalRecords") if !json_obj["app42"]["response"].nil? && json_obj["app42"]["response"].key?("totalRecords") end
isResponseSuccess(json)
click to toggle source
@param json @return @raise Exception
# File lib/App42_Ruby_API/App42ResponseBuilder.rb, line 37 def isResponseSuccess(json) jsonObj = JSON.parse(json) rescue nil p jsonObj jsonObjApp42 = jsonObj["app42"] jsonObjResponse = jsonObjApp42["response"] return jsonObjResponse["success"] end