class App42::Log::LogResponseBuilder
LogResponseBuilder
class converts the JSON response retrieved from the server to the value object i.e Log
Public Instance Methods
buildResponse(json)
click to toggle source
Converts the response in JSON format to the value object i.e Log
@param json
- response in JSON format
@return Log
object filled with json data
# File lib/log/LogResponseBuilder.rb, line 27 def buildResponse(json) puts "testing #{json}" logObj = Log.new() messageList = Array.new logObj.messageList= messageList logObj.strResponse=json jsonObj = JSON.parse(json) jsonObjApp42 = jsonObj.fetch("app42") jsonObjResponse = jsonObjApp42.fetch("response") logObj.isResponseSuccess = jsonObjResponse.fetch("success") jsonObjLog = jsonObjResponse["logs"] if jsonObjLog.key?("log") == false return logObj; end if jsonObjLog.fetch("log").instance_of?(Hash) # Only One attribute is there jsonObjLogMessage = jsonObjLog.fetch("log") messageItem = App42::Log::Message.new(logObj) buildObjectFromJSONTree(messageItem, jsonObjLogMessage); else jsonObjMessageArray = jsonObjLog.fetch("log") # There is an Array of attribute jsonObjMessageArray.length.times do |i| # Get Individual Attribute Node and set it into Object jsonObjLogMessage = jsonObjMessageArray[i] messageItem = App42::Log::Message.new(logObj) buildObjectFromJSONTree(messageItem, jsonObjLogMessage); end end return logObj; end