Class: RabbitMQ::HTTP::ResponseHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbitmq/http/client/response_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ResponseHelper

Returns a new instance of ResponseHelper.



11
12
13
# File 'lib/rabbitmq/http/client/response_helper.rb', line 11

def initialize(client)
  @client = client
end

Instance Method Details

#decode_resource(response) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rabbitmq/http/client/response_helper.rb', line 15

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

#decode_resource_collection(response) ⇒ Object



31
32
33
34
35
# File 'lib/rabbitmq/http/client/response_helper.rb', line 31

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

  collection.map { |i| Hashie::Mash.new(i) }
end

#decode_response_body(body) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/rabbitmq/http/client/response_helper.rb', line 23

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