Class: Coinbase::Advanced::REST::BaseResponse
- Inherits:
-
Object
- Object
- Coinbase::Advanced::REST::BaseResponse
- Defined in:
- lib/coinbase/advanced/rest/base_response.rb
Overview
Converts JSON object to Ruby-style object Similar to https://github.com/coinbase/coinbase-advanced-py/blob/v1.8.1/coinbase/rest/types/base_response.py
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(json_hash, snake_case: true) ⇒ BaseResponse
constructor
TODO: should snake case default be true or false? (or perhaps support both via aliasing if possible?).
- #to_data(value) ⇒ Object
Constructor Details
#initialize(json_hash, snake_case: true) ⇒ BaseResponse
TODO: should snake case default be true or false? (or perhaps support both via aliasing if possible?)
14 15 16 17 |
# File 'lib/coinbase/advanced/rest/base_response.rb', line 14 def initialize(json_hash, snake_case: true) @snake_case = snake_case @response = to_data(json_hash) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
11 12 13 |
# File 'lib/coinbase/advanced/rest/base_response.rb', line 11 def response @response end |
Instance Method Details
#to_data(value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/coinbase/advanced/rest/base_response.rb', line 19 def to_data(value) case value when Hash transformed_keys = value.keys.map { |key| @snake_case ? key.underscore.to_sym : key } transformed_values = value.values.map { |v| to_data(v) } Data.define(*transformed_keys).new(*transformed_values) when Array value.map { |v| to_data(v) } else value end end |