Class: Tikkie::Api::V1::Responses::Base
- Inherits:
-
Object
- Object
- Tikkie::Api::V1::Responses::Base
- Defined in:
- lib/tikkie/api/v1/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.
13 14 15 16 17 18 19 20 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 13 def initialize(response) if response.respond_to?(:body) @response = response @data = parse_body(response.body) else @data = response end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 11 def data @data end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
11 12 13 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 11 def response @response end |
Instance Method Details
#error? ⇒ Boolean
30 31 32 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 30 def error? !success? end |
#errors ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 38 def errors @errors ||= begin errors = [] if data[:errors] data[:errors].each do |error| errors << Tikkie::Api::V1::Responses::Error.new(error) end end errors end end |
#response_code ⇒ Object
22 23 24 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 22 def response_code response.code.to_i if response end |
#success? ⇒ Boolean
26 27 28 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 26 def success? (response_code == 200 || response_code == 201) && !@invalid end |
#trace_id ⇒ Object
34 35 36 |
# File 'lib/tikkie/api/v1/responses/base.rb', line 34 def trace_id response["Trace-Id"] if response end |