Class: HTTPI::Response
- Inherits:
-
Object
- Object
- HTTPI::Response
- Defined in:
- lib/cs-httpi/response.rb
Overview
HTTPI::Response
Represents an HTTP response and contains various response details.
Constant Summary collapse
- SuccessfulResponseCodes =
Range of HTTP response codes considered to be successful.
200..299
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns any DIME attachments.
-
#body ⇒ Object
Returns the HTTP response body.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#raw_body ⇒ Object
Returns the value of attribute raw_body.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns whether the HTTP response is considered successful.
-
#initialize(code, headers, body) ⇒ Response
constructor
Initializer expects an HTTP response
code
,headers
andbody
. -
#multipart? ⇒ Boolean
Returns whether the HTTP response is a multipart response.
Constructor Details
#initialize(code, headers, body) ⇒ Response
Initializer expects an HTTP response code
, headers
and body
.
17 18 19 20 21 |
# File 'lib/cs-httpi/response.rb', line 17 def initialize(code, headers, body) self.code = code.to_i self.headers = Rack::Utils::HeaderHash.new(headers) self.raw_body = body end |
Instance Attribute Details
#attachments ⇒ Object
Returns any DIME attachments.
36 37 38 |
# File 'lib/cs-httpi/response.rb', line 36 def @attachments end |
#body ⇒ Object
Returns the HTTP response body.
42 43 44 45 |
# File 'lib/cs-httpi/response.rb', line 42 def body decode_body unless @body @body end |
#code ⇒ Object
Returns the value of attribute code.
23 24 25 |
# File 'lib/cs-httpi/response.rb', line 23 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
23 24 25 |
# File 'lib/cs-httpi/response.rb', line 23 def headers @headers end |
#raw_body ⇒ Object
Returns the value of attribute raw_body.
23 24 25 |
# File 'lib/cs-httpi/response.rb', line 23 def raw_body @raw_body end |
Instance Method Details
#error? ⇒ Boolean
Returns whether the HTTP response is considered successful.
26 27 28 |
# File 'lib/cs-httpi/response.rb', line 26 def error? !SuccessfulResponseCodes.include? code.to_i end |
#multipart? ⇒ Boolean
Returns whether the HTTP response is a multipart response.
31 32 33 |
# File 'lib/cs-httpi/response.rb', line 31 def multipart? !!(headers["Content-Type"] =~ /^multipart/i) end |