Class: Wrest::Curl::Response
- Inherits:
-
Object
- Object
- Wrest::Curl::Response
show all
- Extended by:
- Forwardable
- Includes:
- HttpCodes, HttpShared::Headers
- Defined in:
- lib/wrest/curl/response.rb
Overview
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.
Instance Attribute Summary (collapse)
Instance Method Summary
(collapse)
Methods included from HttpCodes
#accepted?, #bad_request?, #created?, #forbidden?, #found?, #internal_server_error?, #method_not_allowed?, #moved_permanently?, #no_content?, #not_acceptable?, #not_found?, #not_modified?, #ok?, #see_other?, #temporary_redirect?, #unauthorized?, #unprocessable_entity?
#[]
Constructor Details
- (Response) initialize(http_response)
A new instance of Response
34
35
36
37
|
# File 'lib/wrest/curl/response.rb', line 34
def initialize(http_response)
@http_response = http_response
end
|
Instance Attribute Details
- (Object) deserialised_body
Returns the value of attribute deserialised_body
19
20
21
|
# File 'lib/wrest/curl/response.rb', line 19
def deserialised_body
@deserialised_body
end
|
- (Object) http_response
Returns the value of attribute http_response
18
19
20
|
# File 'lib/wrest/curl/response.rb', line 18
def http_response
@http_response
end
|
Instance Method Details
- (Object) code
47
48
49
|
# File 'lib/wrest/curl/response.rb', line 47
def code
@http_response.status
end
|
- (Boolean) connection_closed?
72
73
74
|
# File 'lib/wrest/curl/response.rb', line 72
def connection_closed?
self[StandardHeaders::Connection].downcase == StandardTokens::Close.downcase
end
|
- (Object) content_length
55
56
57
|
# File 'lib/wrest/curl/response.rb', line 55
def content_length
self[H::ContentLength].try(:to_i)
end
|
- (Object) content_type
59
60
61
|
# File 'lib/wrest/curl/response.rb', line 59
def content_type
self[H::ContentType].split(';').first
end
|
- (Object) deserialise(options = {})
39
40
41
|
# File 'lib/wrest/curl/response.rb', line 39
def deserialise(options = {})
@deserialised_body ||= deserialise_using(Wrest::Components::Translators.lookup(content_type),options)
end
|
- (Object) deserialise_using(translator, options = {})
43
44
45
|
# File 'lib/wrest/curl/response.rb', line 43
def deserialise_using(translator,options={})
translator.deserialise(@http_response,options)
end
|
- (Object) 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.
68
69
70
|
# File 'lib/wrest/curl/response.rb', line 68
def follow(redirect_request_options = {})
self
end
|
26
27
28
29
30
31
32
|
# File 'lib/wrest/curl/response.rb', line 26
def
.merge!(.inject({}) do |, tuple|
key, value = tuple
[key.downcase] = value
end)
end
|
- (Object) message
51
52
53
|
# File 'lib/wrest/curl/response.rb', line 51
def message
@http_response.status_line
end
|