Class: Wrest::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/wrest/response.rb

Overview

Decorates a response providing support for deserialisation.

The following methods are also available (unlisted by rdoc because they’re forwarded):

:@http_response, :code, :message, :body, :http_version, :[], :content_length, :content_type, :each_header, :each_name, :each_value, :fetch, :get_fields, :key?, :type_params

They behave exactly like their Net::HTTPResponse equivalents.

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



26
27
28
# File 'lib/wrest/response.rb', line 26

def initialize(http_response)
  @http_response = http_response
end

Instance Method Details

#deserialiseObject



30
31
32
# File 'lib/wrest/response.rb', line 30

def deserialise
  deserialise_using(Wrest::Translators.load(@http_response.content_type))
end

#deserialise_using(translator) ⇒ Object



34
35
36
# File 'lib/wrest/response.rb', line 34

def deserialise_using(translator)
  translator.call(@http_response)
end