Class: Motion::HTTP::Response
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#original_request ⇒ Object
readonly
Returns the value of attribute original_request.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(original_request, status_code, headers, body) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #object ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(original_request, status_code, headers, body) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 |
# File 'lib/common/http/response.rb', line 6 def initialize(original_request, status_code, headers, body) @original_request = original_request @status_code = status_code @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/common/http/response.rb', line 4 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/common/http/response.rb', line 4 def headers @headers end |
#original_request ⇒ Object (readonly)
Returns the value of attribute original_request.
4 5 6 |
# File 'lib/common/http/response.rb', line 4 def original_request @original_request end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
4 5 6 |
# File 'lib/common/http/response.rb', line 4 def status_code @status_code end |
Instance Method Details
#inspect ⇒ Object
27 28 29 |
# File 'lib/common/http/response.rb', line 27 def inspect "<Motion::HTTP::Response status_code:#{status_code} headers:#{headers.inspect} body:#{body.inspect}>" end |
#object ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/common/http/response.rb', line 18 def object @object ||= case headers['Content-Type'] when /^application\/json/, /^application\/vnd.api\+json/ JSON.parse(body) else body end end |
#success? ⇒ Boolean
13 14 15 16 |
# File 'lib/common/http/response.rb', line 13 def success? return false unless status_code status_code >= 200 && status_code < 300 end |