Class: Wrest::Http::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/wrest/http/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



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

def initialize(http_response)
  @http_response = http_response
end

Instance Method Details

#deserialiseObject



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

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

#deserialise_using(translator) ⇒ Object



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

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

#headersObject



39
40
41
# File 'lib/wrest/http/response.rb', line 39

def headers
  @http_response.to_hash
end