Class: Cased::Response
- Inherits:
-
Object
- Object
- Cased::Response
- Defined in:
- lib/cased/response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Instance Method Summary collapse
- #error ⇒ Object
- #error? ⇒ Boolean
-
#initialize(response: nil, exception: nil) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(response: nil, exception: nil) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 |
# File 'lib/cased/response.rb', line 7 def initialize(response: nil, exception: nil) @response = response @body = response&.body @exception = exception end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/cased/response.rb', line 5 def body @body end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
5 6 7 |
# File 'lib/cased/response.rb', line 5 def exception @exception end |
Instance Method Details
#error ⇒ Object
13 14 15 |
# File 'lib/cased/response.rb', line 13 def error @exception.presence || (body && body['error']).presence end |
#error? ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cased/response.rb', line 17 def error? # If there was an exception during the execution of the request. return true if @exception.present? # If the HTTP response was outside of 200-299 return true unless @response.success? # If the HTTP response contained an error key. return true if body && body['error'].present? false end |
#success? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/cased/response.rb', line 30 def success? return false if @response.nil? @response.success? end |