Class: REST::Response
- Inherits:
-
Object
- Object
- REST::Response
- Defined in:
- lib/rest/response.rb
Overview
Response holds a HTTP response
Constant Summary collapse
- CODES =
[ [200, :ok], [201, :created], [301, :moved_permanently], [302, :found], [400, :bad_request], [401, :unauthorized], [403, :forbidden], [422, :unprocessable_entity], [404, :not_found], [500, :internal_server_error] ]
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(status_code, headers = {}, body = '') ⇒ Response
constructor
-
status_code
: The status code of the response (ie. 200 or ‘404’) *headers
: The headers of the response *body
: The body of the response.
-
-
#success? ⇒ Boolean
Returns true when the status code is in the 2XX range.
Constructor Details
#initialize(status_code, headers = {}, body = '') ⇒ Response
-
status_code
: The status code of the response (ie. 200 or ‘404’) -
headers
: The headers of the response -
body
: The body of the response
29 30 31 32 33 |
# File 'lib/rest/response.rb', line 29 def initialize(status_code, headers={}, body='') @status_code = status_code.to_i @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
24 25 26 |
# File 'lib/rest/response.rb', line 24 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
24 25 26 |
# File 'lib/rest/response.rb', line 24 def headers @headers end |
#status_code ⇒ Object
Returns the value of attribute status_code.
24 25 26 |
# File 'lib/rest/response.rb', line 24 def status_code @status_code end |
Instance Method Details
#success? ⇒ Boolean
Returns true when the status code is in the 2XX range. Returns false otherwise.
42 43 44 |
# File 'lib/rest/response.rb', line 42 def success? (status_code.to_s =~ /2../) ? true : false end |