Class: Tikkie::Api::Responses::Base
- Inherits:
-
Object
- Object
- Tikkie::Api::Responses::Base
- Defined in:
- lib/tikkie/api/responses/base.rb
Overview
Base class for all responses.
Direct Known Subclasses
BankAccount, Error, Payment, PaymentRequest, PaymentRequestCreated, PaymentRequests, Platform, Platforms, User, Users
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #errors ⇒ Object
-
#initialize(response) ⇒ Base
constructor
A new instance of Base.
- #response_code ⇒ Object
- #success? ⇒ Boolean
- #trace_id ⇒ Object
Constructor Details
#initialize(response) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 18 19 |
# File 'lib/tikkie/api/responses/base.rb', line 12 def initialize(response) if response.respond_to?(:body) @response = response @data = JSON.parse(response.body, symbolize_names: true) else @data = response end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/tikkie/api/responses/base.rb', line 10 def data @data end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/tikkie/api/responses/base.rb', line 10 def response @response end |
Instance Method Details
#error? ⇒ Boolean
29 30 31 |
# File 'lib/tikkie/api/responses/base.rb', line 29 def error? !success? end |
#errors ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tikkie/api/responses/base.rb', line 37 def errors @errors ||= begin errors = [] if data[:errors] data[:errors].each do |error| errors << Tikkie::Api::Responses::Error.new(error) end end errors end end |
#response_code ⇒ Object
21 22 23 |
# File 'lib/tikkie/api/responses/base.rb', line 21 def response_code response.code.to_i if response end |
#success? ⇒ Boolean
25 26 27 |
# File 'lib/tikkie/api/responses/base.rb', line 25 def success? response_code == 200 || response_code == 201 end |
#trace_id ⇒ Object
33 34 35 |
# File 'lib/tikkie/api/responses/base.rb', line 33 def trace_id response["Trace-Id"] if response end |