Class: Square::ApiResponse
- Inherits:
-
CoreLibrary::ApiResponse
- Object
- CoreLibrary::ApiResponse
- Square::ApiResponse
- Defined in:
- lib/square/http/api_response.rb
Overview
Http response received.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
Class Method Summary collapse
-
.create(parent_instance) ⇒ Object
The factory method for creating the API Response instance of the SDK from its parent instance in the core lirbary.
Instance Method Summary collapse
-
#initialize(http_response, data: nil, errors: nil) ⇒ ApiResponse
constructor
The constructor.
Constructor Details
#initialize(http_response, data: nil, errors: nil) ⇒ ApiResponse
The constructor
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/square/http/api_response.rb', line 10 def initialize(http_response, data: nil, errors: nil) super @errors = errors if (data.is_a? Hash) && data.keys.any? @body = Struct.new(*data.keys) do define_method(:to_s) { http_response.raw_body } end.new(*data.values) @cursor = data.fetch(:cursor, nil) data.reject! { |k| %i[cursor errors].include?(k) } @data = data.keys.any? ? Struct.new(*data.keys).new(*data.values) : nil else @data = data @body = data end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/square/http/api_response.rb', line 4 def body @body end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
4 5 6 |
# File 'lib/square/http/api_response.rb', line 4 def cursor @cursor end |
Class Method Details
.create(parent_instance) ⇒ Object
The factory method for creating the API Response instance of the SDK from its parent instance in the core lirbary.
32 33 34 35 36 37 |
# File 'lib/square/http/api_response.rb', line 32 def self.create(parent_instance) ApiResponse.new(CoreLibrary::HttpResponse .new(parent_instance.status_code, parent_instance.reason_phrase, parent_instance.headers, parent_instance.raw_body, parent_instance.request), data: parent_instance.data, errors: parent_instance.errors) end |