Sha256: e2bc773ab027c98863a5dd8856b60a807bea47d41085be90ec8eae29ba942036

Contents?: true

Size: 925 Bytes

Versions: 1

Compression:

Stored size: 925 Bytes

Contents

require "hashie"
require "faraday"
require "faraday/follow_redirects"
require "multi_json"
require "uri"

module RabbitMQ
  module HTTP
    class ResponseHelper

      def initialize(client)
        @client = client
      end

      def decode_resource(response)
        if response.nil? || response.body.nil? || response.body.empty?
          Hashie::Mash.new
        else
          decode_response_body(response.body)
        end
      end

      def decode_response_body(body)
        if body.empty?
          Hashie::Mash.new
        else
          Hashie::Mash.new(body)
        end
      end

      def decode_resource_collection(response)
        collection = response.body.is_a?(Array) ? response.body : response.body.fetch('items')

        collection.map do |i|
          if i == []
            Hashie::Mash.new()
          else
            Hashie::Mash.new(i)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rabbitmq_http_api_client-3.0.0 lib/rabbitmq/http/client/response_helper.rb