Class Wrest::Curl::Response

  1. lib/wrest/curl/response.rb
Parent: Object

Decorates a response providing support for deserialisation.

Also provides set of HTTP response code checkers. For instance, the method ok? checks if the response was successful with HTTP code 200. See HttpCodes for a list of all such response checkers.

Included modules

  1. HttpShared::Headers
  2. HttpCodes

Attributes

http_response [R]

Public class methods

new (http_response)
[show source]
    # File lib/wrest/curl/response.rb, line 33
33:       def initialize(http_response)
34:         @http_response = http_response
35:         initialize_http_header
36:       end

Public instance methods

code ()
[show source]
    # File lib/wrest/curl/response.rb, line 46
46:       def code
47:         @http_response.status
48:       end
connection_closed? ()
[show source]
    # File lib/wrest/curl/response.rb, line 71
71:       def connection_closed?
72:         self[StandardHeaders::Connection].downcase == StandardTokens::Close.downcase
73:       end
content_length ()
[show source]
    # File lib/wrest/curl/response.rb, line 54
54:       def content_length
55:         self[H::ContentLength].try(:to_i)
56:       end
content_type ()
[show source]
    # File lib/wrest/curl/response.rb, line 58
58:       def content_type
59:         self[H::ContentType].split(';').first
60:       end
deserialise (options = {})
[show source]
    # File lib/wrest/curl/response.rb, line 38
38:       def deserialise(options = {})
39:         deserialise_using(Wrest::Components::Translators.lookup(content_type),options)
40:       end
deserialise_using (translator,options={})
[show source]
    # File lib/wrest/curl/response.rb, line 42
42:       def deserialise_using(translator,options={})
43:         translator.deserialise(@http_response,options)
44:       end
follow (redirect_request_options = {})

A null object implementation - invoking this method on a response simply returns the same response unless the response is a Redirection (code 3xx), in which case a get is invoked on the url stored in the response headers under the key ‘location’ and the new Response is returned.

[show source]
    # File lib/wrest/curl/response.rb, line 67
67:       def follow(redirect_request_options = {})
68:         self
69:       end
initialize_http_header ()
[show source]
    # File lib/wrest/curl/response.rb, line 25
25:       def initialize_http_header
26:         headers.merge!(headers.inject({}) do |downcased_headers, tuple|
27:           key, value = tuple
28:           downcased_headers[key.downcase] = value
29:           downcased_headers
30:         end)
31:       end
message ()
[show source]
    # File lib/wrest/curl/response.rb, line 50
50:       def message
51:         @http_response.status_line
52:       end