Class: Restfully::HTTP::Response
- Defined in:
- lib/restfully/http/response.rb
Overview
Container for an HTTP Response. Has status
, headers
and body
properties.
Constant Summary
Constants included from Parsing
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(status, headers, body) ⇒ Response
constructor
body
-
may be a string (that will be parsed when calling the #body function), or an object (that will be returned as is when calling the #body function).
- #raw_body ⇒ Object
Methods included from Headers
Methods included from Parsing
#select_parser_for, #serialize, #unserialize
Constructor Details
#initialize(status, headers, body) ⇒ Response
body
-
may be a string (that will be parsed when calling the #body function), or an object (that will be returned as is when calling the #body function)
9 10 11 12 13 |
# File 'lib/restfully/http/response.rb', line 9 def initialize(status, headers, body) @status = status.to_i @headers = sanitize_http_headers(headers) @body = body end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/restfully/http/response.rb', line 6 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/restfully/http/response.rb', line 6 def status @status end |
Instance Method Details
#body ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/restfully/http/response.rb', line 15 def body if @body.kind_of?(String) if @body.empty? nil else @unserialized_body ||= unserialize(@body, :content_type => @headers['Content-Type']) end else @body end end |
#raw_body ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/restfully/http/response.rb', line 27 def raw_body if @body.kind_of?(String) @body else @serialized_body ||= serialize(@body, :content_type => @headers['Content-Type']) unless @body.nil? end end |