Class: Stash::Rewards::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/stash/rewards/response.rb

Instance Method Summary collapse

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

#bodyObject



22
23
24
# File 'lib/stash/rewards/response.rb', line 22

def body
  @body ||= @response.body
end

#error?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/stash/rewards/response.rb', line 10

def error?
  !@response.success? || (error_code != 0)
end

#error_codeObject



26
27
28
# File 'lib/stash/rewards/response.rb', line 26

def error_code
  @error_code ||= payload.dig('error', 'code').to_i
end

#error_messageObject



30
31
32
# File 'lib/stash/rewards/response.rb', line 30

def error_message
  api_error_message || error_payload
end

#payloadObject



14
15
16
# File 'lib/stash/rewards/response.rb', line 14

def payload
  @payload ||= JSON.parse(body)
end

#statusObject



18
19
20
# File 'lib/stash/rewards/response.rb', line 18

def status
  @status ||= @response.status
end