class App42::Message::QueueResponseBuilder

QueueResponseBuilder class converts the JSON response retrieved from the server to the value object i.e Queue

Public Instance Methods

buildResponse(json) click to toggle source

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

@param json

- response in JSON format

@return Queue object filled with json data

# File lib/message/QueueResponseBuilder.rb, line 29
def buildResponse(json)
  puts "testing #{json}"
  queuesJSONObj = getServiceJSONObject("queues", json)
  queueJSONObj =  queuesJSONObj["queue"]
  queueObj = Queue.new()

  messageList = Array.new
  queueObj.messageList=(messageList)

  queueObj.strResponse=json
  queueObj.isResponseSuccess= isResponseSuccess(json)
  buildObjectFromJSONTree(queueObj, queueJSONObj);

  if queueJSONObj.key?("messages") == false
    return queueObj
  end
  if queueJSONObj.fetch("messages").key?("message") == false
    return queueObj
  end
  if queueJSONObj.fetch("messages").fetch("message").instance_of?(Hash)
    messageObj = App42::Message::Message.new(queueObj)
    buildObjectFromJSONTree(messageObj,queueJSONObj.fetch("messages").fetch("message"));
  else
    messagesJSONArray = queueJSONObj.fetch("messages").fetch("message");
    messagesJSONArray.length.times do |i|
      messageJSONObj = messagesJSONArray[i]
      messageObj = App42::Message::Message.new(queueObj)
      buildObjectFromJSONTree(messageObj, messageJSONObj);
    end

  end
  return queueObj
end