Class: Stash::Rewards::Response
- Inherits:
-
Object
- Object
- Stash::Rewards::Response
- Defined in:
- lib/stash/rewards/response.rb
Instance Method Summary collapse
- #body ⇒ Object
- #error? ⇒ Boolean
- #error_code ⇒ Object
- #error_message ⇒ Object
-
#initialize(faraday_response) ⇒ Response
constructor
A new instance of Response.
- #payload ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(faraday_response) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/stash/rewards/response.rb', line 6 def initialize(faraday_response) @response = faraday_response end |
Instance Method Details
#body ⇒ Object
22 23 24 |
# File 'lib/stash/rewards/response.rb', line 22 def body @body ||= @response.body end |
#error? ⇒ Boolean
10 11 12 |
# File 'lib/stash/rewards/response.rb', line 10 def error? !@response.success? || (error_code != 0) end |
#error_code ⇒ Object
26 27 28 |
# File 'lib/stash/rewards/response.rb', line 26 def error_code @error_code ||= payload.dig('error', 'code').to_i end |
#error_message ⇒ Object
30 31 32 |
# File 'lib/stash/rewards/response.rb', line 30 def || error_payload end |
#payload ⇒ Object
14 15 16 |
# File 'lib/stash/rewards/response.rb', line 14 def payload @payload ||= JSON.parse(body) end |
#status ⇒ Object
18 19 20 |
# File 'lib/stash/rewards/response.rb', line 18 def status @status ||= @response.status end |