Class: RabbitMQ::HTTP::ResponseHelper
- Inherits:
-
Object
- Object
- RabbitMQ::HTTP::ResponseHelper
- Defined in:
- lib/rabbitmq/http/client/response_helper.rb
Instance Method Summary collapse
- #decode_resource(response) ⇒ Object
- #decode_resource_collection(response) ⇒ Object
- #decode_response_body(body) ⇒ Object
-
#initialize(client) ⇒ ResponseHelper
constructor
A new instance of ResponseHelper.
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.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 36 37 38 39 40 41 |
# 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 do |i| if i == [] Hashie::Mash.new() else Hashie::Mash.new(i) end end 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 |