Class: Restify::Response
- Inherits:
-
Object
- Object
- Restify::Response
- Defined in:
- lib/restify/response.rb
Overview
Constant Summary collapse
- SYMBOL_TO_STATUS_CODE =
Map of status symbols to codes. From Rack::Utils.
Rack::Utils::SYMBOL_TO_STATUS_CODE
- STATUS_CODE_TO_SYMBOL =
Map of status codes to symbols.
SYMBOL_TO_STATUS_CODE.invert
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Response body as string.
-
#code ⇒ Fixnum
readonly
Response status code.
-
#headers ⇒ Hash<String, String>
readonly
Response headers as hash.
-
#message ⇒ String
readonly
Response status message.
-
#request ⇒ Request
readonly
The request that led to this response.
-
#status ⇒ Symbol
readonly
Response status symbol.
-
#uri ⇒ Addressable::URI
readonly
Last effective URI.
Instance Method Summary collapse
-
#content_type ⇒ String
Return content type header from response headers.
- #decoded_body ⇒ Object private
- #follow_location ⇒ Object private
-
#initialize(request, uri, code, headers, body) ⇒ Response
constructor
private
A new instance of Response.
-
#links ⇒ Array<Link>
Return list of links from the Link header.
-
#success? ⇒ Boolean
Check if response is successful e.g.
Constructor Details
#initialize(request, uri, code, headers, body) ⇒ Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Response.
76 77 78 79 80 81 82 83 84 |
# File 'lib/restify/response.rb', line 76 def initialize(request, uri, code, headers, body) @request = request @uri = uri @code = code @status = STATUS_CODE_TO_SYMBOL[code] @headers = convert_headers(headers) @body = body = Rack::Utils::HTTP_STATUS_CODES[code] end |
Instance Attribute Details
#body ⇒ String (readonly)
Response body as string.
33 34 35 |
# File 'lib/restify/response.rb', line 33 def body @body end |
#code ⇒ Fixnum (readonly)
Response status code.
45 46 47 |
# File 'lib/restify/response.rb', line 45 def code @code end |
#headers ⇒ Hash<String, String> (readonly)
Response headers as hash.
39 40 41 |
# File 'lib/restify/response.rb', line 39 def headers @headers end |
#message ⇒ String (readonly)
Response status message.
60 61 62 |
# File 'lib/restify/response.rb', line 60 def end |
#request ⇒ Request (readonly)
The request that led to this response.
66 67 68 |
# File 'lib/restify/response.rb', line 66 def request @request end |
#status ⇒ Symbol (readonly)
Response status symbol.
54 55 56 |
# File 'lib/restify/response.rb', line 54 def status @status end |
#uri ⇒ Addressable::URI (readonly)
Last effective URI.
72 73 74 |
# File 'lib/restify/response.rb', line 72 def uri @uri end |
Instance Method Details
#content_type ⇒ String
Return content type header from response headers.
109 110 111 |
# File 'lib/restify/response.rb', line 109 def content_type headers['CONTENT_TYPE'] end |
#decoded_body ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 126 127 128 129 130 |
# File 'lib/restify/response.rb', line 123 def decoded_body @decoded_body ||= begin case content_type when /\Aapplication\/json($|;)/ JSON.load body end end end |
#follow_location ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
133 134 135 |
# File 'lib/restify/response.rb', line 133 def follow_location headers['LOCATION'] || headers['CONENT_LOCATION'] end |
#links ⇒ Array<Link>
Return list of links from the Link header.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/restify/response.rb', line 90 def links @links ||= begin if headers['LINK'] begin Link.parse(headers['LINK']) rescue ArgumentError => e warn e [] end else [] end end end |
#success? ⇒ Boolean
Check if response is successful e.g. the status code is on of 2XX.
118 119 120 |
# File 'lib/restify/response.rb', line 118 def success? (200...300).include? code end |