Sha256: 26d3169dac5c5530feecb15eb436ca3d9e94fc1dff3572217a390054891dcd30

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

# -----------------------------------------------------------------------
#  Copyright © 2012 ShepHertz Technologies Pvt Ltd. All rights reserved.
# -----------------------------------------------------------------------

require 'json/pure'
require 'App42ResponseBuilder.rb'
require 'message/Queue.rb'

module App42
  module Message

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

      #
      # 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
      #
      #
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
App42_RUBY_SDK-0.8.3 lib/message/QueueResponseBuilder.rb