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
- #client_error? ⇒ Boolean
-
#initialize(original_request, status_code, headers, body) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #object ⇒ Object
- #redirect? ⇒ Boolean
- #server_error? ⇒ Boolean
- #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
#client_error? ⇒ Boolean
21 22 23 |
# File 'lib/common/http/response.rb', line 21 def client_error? status_code && (400..499) === status_code end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/common/http/response.rb', line 38 def inspect "<Motion::HTTP::Response status_code:#{status_code} headers:#{headers.inspect} body:#{body.inspect}>" end |
#object ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/common/http/response.rb', line 29 def object @object ||= case headers['Content-Type'] when /^application\/json/, /^application\/vnd.api\+json/ JSON.parse(body) else body end end |
#redirect? ⇒ Boolean
17 18 19 |
# File 'lib/common/http/response.rb', line 17 def redirect? status_code && (300..399) === status_code end |
#server_error? ⇒ Boolean
25 26 27 |
# File 'lib/common/http/response.rb', line 25 def server_error? status_code && (500..599) === status_code end |
#success? ⇒ Boolean
13 14 15 |
# File 'lib/common/http/response.rb', line 13 def success? status_code && (200..299) === status_code end |