Class: Cookie::Models::BaseResponse Abstract
- Inherits:
-
Object
- Object
- Cookie::Models::BaseResponse
- Defined in:
- lib/cookie/models/base_response.rb
Overview
This class is abstract.
Subclass and add attributes specific to the endpoint
Base class for API responses that provides error checking capabilities
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error_code ⇒ String?
readonly
Error code if present.
-
#error_message ⇒ String?
readonly
Error message if present.
-
#expired ⇒ Boolean
readonly
Whether the session is expired.
-
#type ⇒ String
readonly
The type of response from the API.
Instance Method Summary collapse
-
#authentication_error? ⇒ Boolean
Whether the error is an authentication error.
-
#error? ⇒ Boolean
Whether the response contains an error.
-
#initialize(attributes) ⇒ BaseResponse
constructor
A new instance of BaseResponse.
Constructor Details
#initialize(attributes) ⇒ BaseResponse
Returns a new instance of BaseResponse.
22 23 24 25 26 27 |
# File 'lib/cookie/models/base_response.rb', line 22 def initialize(attributes) @type = attributes["type"] @error_code = attributes["errorCode"] @error_message = attributes["errorMessage"] @expired = attributes["expired"] || false end |
Instance Attribute Details
#error_code ⇒ String? (readonly)
Returns Error code if present.
13 14 15 |
# File 'lib/cookie/models/base_response.rb', line 13 def error_code @error_code end |
#error_message ⇒ String? (readonly)
Returns Error message if present.
16 17 18 |
# File 'lib/cookie/models/base_response.rb', line 16 def @error_message end |
#expired ⇒ Boolean (readonly)
Returns Whether the session is expired.
19 20 21 |
# File 'lib/cookie/models/base_response.rb', line 19 def expired @expired end |
#type ⇒ String (readonly)
Returns The type of response from the API.
10 11 12 |
# File 'lib/cookie/models/base_response.rb', line 10 def type @type end |
Instance Method Details
#authentication_error? ⇒ Boolean
Returns Whether the error is an authentication error.
35 36 37 |
# File 'lib/cookie/models/base_response.rb', line 35 def authentication_error? error? && error_code == "500" end |
#error? ⇒ Boolean
Returns Whether the response contains an error.
30 31 32 |
# File 'lib/cookie/models/base_response.rb', line 30 def error? !!(error_code && !error_code.empty?) end |