coinbase-sdk 0.6.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address/wallet_address.rb +44 -0
  3. data/lib/coinbase/address.rb +13 -4
  4. data/lib/coinbase/client/api/external_addresses_api.rb +26 -27
  5. data/lib/coinbase/client/api/fund_api.rb +336 -0
  6. data/lib/coinbase/client/api/onchain_identity_api.rb +108 -0
  7. data/lib/coinbase/client/api/smart_contracts_api.rb +80 -0
  8. data/lib/coinbase/client/api/transaction_history_api.rb +101 -0
  9. data/lib/coinbase/client/api/webhooks_api.rb +70 -0
  10. data/lib/coinbase/client/models/create_fund_operation_request.rb +249 -0
  11. data/lib/coinbase/client/models/create_fund_quote_request.rb +239 -0
  12. data/lib/coinbase/client/models/create_wallet_webhook_request.rb +232 -0
  13. data/lib/coinbase/client/models/crypto_amount.rb +239 -0
  14. data/lib/coinbase/client/models/ethereum_token_transfer.rb +327 -0
  15. data/lib/coinbase/client/models/ethereum_transaction.rb +12 -1
  16. data/lib/coinbase/client/models/faucet_transaction.rb +20 -4
  17. data/lib/coinbase/client/models/fiat_amount.rb +240 -0
  18. data/lib/coinbase/client/models/fund_operation.rb +373 -0
  19. data/lib/coinbase/client/models/fund_operation_fees.rb +238 -0
  20. data/lib/coinbase/client/models/fund_operation_list.rb +275 -0
  21. data/lib/coinbase/client/models/fund_quote.rb +339 -0
  22. data/lib/coinbase/client/models/multi_token_contract_options.rb +223 -0
  23. data/lib/coinbase/client/models/network_identifier.rb +2 -1
  24. data/lib/coinbase/client/models/nft_contract_options.rb +21 -4
  25. data/lib/coinbase/client/models/onchain_name.rb +357 -0
  26. data/lib/coinbase/client/models/onchain_name_list.rb +262 -0
  27. data/lib/coinbase/client/models/read_contract_request.rb +249 -0
  28. data/lib/coinbase/client/models/smart_contract_options.rb +1 -0
  29. data/lib/coinbase/client/models/smart_contract_type.rb +2 -1
  30. data/lib/coinbase/client/models/solidity_value.rb +287 -0
  31. data/lib/coinbase/client/models/{feature.rb → token_transfer_type.rb} +10 -10
  32. data/lib/coinbase/client/models/update_webhook_request.rb +0 -7
  33. data/lib/coinbase/client.rb +19 -0
  34. data/lib/coinbase/faucet_transaction.rb +64 -4
  35. data/lib/coinbase/smart_contract.rb +149 -0
  36. data/lib/coinbase/transaction.rb +8 -2
  37. data/lib/coinbase/version.rb +1 -1
  38. data/lib/coinbase/wallet.rb +35 -1
  39. data/lib/coinbase/webhook.rb +3 -7
  40. metadata +21 -3
@@ -0,0 +1,223 @@
1
+ =begin
2
+ #Coinbase Platform API
3
+
4
+ #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
+
6
+ The version of the OpenAPI document: 0.0.1-alpha
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.8.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Coinbase::Client
17
+ # Options for multi-token contract creation
18
+ class MultiTokenContractOptions
19
+ # The URI for all token metadata
20
+ attr_accessor :uri
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'uri' => :'uri'
26
+ }
27
+ end
28
+
29
+ # Returns all the JSON keys this model knows about
30
+ def self.acceptable_attributes
31
+ attribute_map.values
32
+ end
33
+
34
+ # Attribute type mapping.
35
+ def self.openapi_types
36
+ {
37
+ :'uri' => :'String'
38
+ }
39
+ end
40
+
41
+ # List of attributes with nullable: true
42
+ def self.openapi_nullable
43
+ Set.new([
44
+ ])
45
+ end
46
+
47
+ # Initializes the object
48
+ # @param [Hash] attributes Model attributes in the form of hash
49
+ def initialize(attributes = {})
50
+ if (!attributes.is_a?(Hash))
51
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::MultiTokenContractOptions` initialize method"
52
+ end
53
+
54
+ # check to see if the attribute exists and convert string to symbol for hash key
55
+ attributes = attributes.each_with_object({}) { |(k, v), h|
56
+ if (!self.class.attribute_map.key?(k.to_sym))
57
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::MultiTokenContractOptions`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
58
+ end
59
+ h[k.to_sym] = v
60
+ }
61
+
62
+ if attributes.key?(:'uri')
63
+ self.uri = attributes[:'uri']
64
+ else
65
+ self.uri = nil
66
+ end
67
+ end
68
+
69
+ # Show invalid properties with the reasons. Usually used together with valid?
70
+ # @return Array for valid properties with the reasons
71
+ def list_invalid_properties
72
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
73
+ invalid_properties = Array.new
74
+ if @uri.nil?
75
+ invalid_properties.push('invalid value for "uri", uri cannot be nil.')
76
+ end
77
+
78
+ invalid_properties
79
+ end
80
+
81
+ # Check to see if the all the properties in the model are valid
82
+ # @return true if the model is valid
83
+ def valid?
84
+ warn '[DEPRECATED] the `valid?` method is obsolete'
85
+ return false if @uri.nil?
86
+ true
87
+ end
88
+
89
+ # Checks equality by comparing each attribute.
90
+ # @param [Object] Object to be compared
91
+ def ==(o)
92
+ return true if self.equal?(o)
93
+ self.class == o.class &&
94
+ uri == o.uri
95
+ end
96
+
97
+ # @see the `==` method
98
+ # @param [Object] Object to be compared
99
+ def eql?(o)
100
+ self == o
101
+ end
102
+
103
+ # Calculates hash code according to all attributes.
104
+ # @return [Integer] Hash code
105
+ def hash
106
+ [uri].hash
107
+ end
108
+
109
+ # Builds the object from hash
110
+ # @param [Hash] attributes Model attributes in the form of hash
111
+ # @return [Object] Returns the model itself
112
+ def self.build_from_hash(attributes)
113
+ return nil unless attributes.is_a?(Hash)
114
+ attributes = attributes.transform_keys(&:to_sym)
115
+ transformed_hash = {}
116
+ openapi_types.each_pair do |key, type|
117
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
118
+ transformed_hash["#{key}"] = nil
119
+ elsif type =~ /\AArray<(.*)>/i
120
+ # check to ensure the input is an array given that the attribute
121
+ # is documented as an array but the input is not
122
+ if attributes[attribute_map[key]].is_a?(Array)
123
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
124
+ end
125
+ elsif !attributes[attribute_map[key]].nil?
126
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
127
+ end
128
+ end
129
+ new(transformed_hash)
130
+ end
131
+
132
+ # Deserializes the data based on type
133
+ # @param string type Data type
134
+ # @param string value Value to be deserialized
135
+ # @return [Object] Deserialized data
136
+ def self._deserialize(type, value)
137
+ case type.to_sym
138
+ when :Time
139
+ Time.parse(value)
140
+ when :Date
141
+ Date.parse(value)
142
+ when :String
143
+ value.to_s
144
+ when :Integer
145
+ value.to_i
146
+ when :Float
147
+ value.to_f
148
+ when :Boolean
149
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
150
+ true
151
+ else
152
+ false
153
+ end
154
+ when :Object
155
+ # generic object (usually a Hash), return directly
156
+ value
157
+ when /\AArray<(?<inner_type>.+)>\z/
158
+ inner_type = Regexp.last_match[:inner_type]
159
+ value.map { |v| _deserialize(inner_type, v) }
160
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
161
+ k_type = Regexp.last_match[:k_type]
162
+ v_type = Regexp.last_match[:v_type]
163
+ {}.tap do |hash|
164
+ value.each do |k, v|
165
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
166
+ end
167
+ end
168
+ else # model
169
+ # models (e.g. Pet) or oneOf
170
+ klass = Coinbase::Client.const_get(type)
171
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
172
+ end
173
+ end
174
+
175
+ # Returns the string representation of the object
176
+ # @return [String] String presentation of the object
177
+ def to_s
178
+ to_hash.to_s
179
+ end
180
+
181
+ # to_body is an alias to to_hash (backward compatibility)
182
+ # @return [Hash] Returns the object in the form of hash
183
+ def to_body
184
+ to_hash
185
+ end
186
+
187
+ # Returns the object in the form of hash
188
+ # @return [Hash] Returns the object in the form of hash
189
+ def to_hash
190
+ hash = {}
191
+ self.class.attribute_map.each_pair do |attr, param|
192
+ value = self.send(attr)
193
+ if value.nil?
194
+ is_nullable = self.class.openapi_nullable.include?(attr)
195
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
196
+ end
197
+
198
+ hash[param] = _to_hash(value)
199
+ end
200
+ hash
201
+ end
202
+
203
+ # Outputs non-array value in the form of hash
204
+ # For object, use to_hash. Otherwise, just return the value
205
+ # @param [Object] value Any valid value
206
+ # @return [Hash] Returns the value in the form of hash
207
+ def _to_hash(value)
208
+ if value.is_a?(Array)
209
+ value.compact.map { |v| _to_hash(v) }
210
+ elsif value.is_a?(Hash)
211
+ {}.tap do |hash|
212
+ value.each { |k, v| hash[k] = _to_hash(v) }
213
+ end
214
+ elsif value.respond_to? :to_hash
215
+ value.to_hash
216
+ else
217
+ value
218
+ end
219
+ end
220
+
221
+ end
222
+
223
+ end
@@ -21,11 +21,12 @@ module Coinbase::Client
21
21
  ETHEREUM_MAINNET = "ethereum-mainnet".freeze
22
22
  POLYGON_MAINNET = "polygon-mainnet".freeze
23
23
  SOLANA_DEVNET = "solana-devnet".freeze
24
+ SOLANA_MAINNET = "solana-mainnet".freeze
24
25
  ARBITRUM_MAINNET = "arbitrum-mainnet".freeze
25
26
  UNKNOWN_DEFAULT_OPEN_API = "unknown_default_open_api".freeze
26
27
 
27
28
  def self.all_vars
28
- @all_vars ||= [BASE_SEPOLIA, BASE_MAINNET, ETHEREUM_HOLESKY, ETHEREUM_MAINNET, POLYGON_MAINNET, SOLANA_DEVNET, ARBITRUM_MAINNET, UNKNOWN_DEFAULT_OPEN_API].freeze
29
+ @all_vars ||= [BASE_SEPOLIA, BASE_MAINNET, ETHEREUM_HOLESKY, ETHEREUM_MAINNET, POLYGON_MAINNET, SOLANA_DEVNET, SOLANA_MAINNET, ARBITRUM_MAINNET, UNKNOWN_DEFAULT_OPEN_API].freeze
29
30
  end
30
31
 
31
32
  # Builds the enum from string
@@ -22,11 +22,15 @@ module Coinbase::Client
22
22
  # The symbol of the NFT
23
23
  attr_accessor :symbol
24
24
 
25
+ # The base URI for the NFT metadata
26
+ attr_accessor :base_uri
27
+
25
28
  # Attribute mapping from ruby-style variable name to JSON key.
26
29
  def self.attribute_map
27
30
  {
28
31
  :'name' => :'name',
29
- :'symbol' => :'symbol'
32
+ :'symbol' => :'symbol',
33
+ :'base_uri' => :'base_uri'
30
34
  }
31
35
  end
32
36
 
@@ -39,7 +43,8 @@ module Coinbase::Client
39
43
  def self.openapi_types
40
44
  {
41
45
  :'name' => :'String',
42
- :'symbol' => :'String'
46
+ :'symbol' => :'String',
47
+ :'base_uri' => :'String'
43
48
  }
44
49
  end
45
50
 
@@ -75,6 +80,12 @@ module Coinbase::Client
75
80
  else
76
81
  self.symbol = nil
77
82
  end
83
+
84
+ if attributes.key?(:'base_uri')
85
+ self.base_uri = attributes[:'base_uri']
86
+ else
87
+ self.base_uri = nil
88
+ end
78
89
  end
79
90
 
80
91
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -90,6 +101,10 @@ module Coinbase::Client
90
101
  invalid_properties.push('invalid value for "symbol", symbol cannot be nil.')
91
102
  end
92
103
 
104
+ if @base_uri.nil?
105
+ invalid_properties.push('invalid value for "base_uri", base_uri cannot be nil.')
106
+ end
107
+
93
108
  invalid_properties
94
109
  end
95
110
 
@@ -99,6 +114,7 @@ module Coinbase::Client
99
114
  warn '[DEPRECATED] the `valid?` method is obsolete'
100
115
  return false if @name.nil?
101
116
  return false if @symbol.nil?
117
+ return false if @base_uri.nil?
102
118
  true
103
119
  end
104
120
 
@@ -108,7 +124,8 @@ module Coinbase::Client
108
124
  return true if self.equal?(o)
109
125
  self.class == o.class &&
110
126
  name == o.name &&
111
- symbol == o.symbol
127
+ symbol == o.symbol &&
128
+ base_uri == o.base_uri
112
129
  end
113
130
 
114
131
  # @see the `==` method
@@ -120,7 +137,7 @@ module Coinbase::Client
120
137
  # Calculates hash code according to all attributes.
121
138
  # @return [Integer] Hash code
122
139
  def hash
123
- [name, symbol].hash
140
+ [name, symbol, base_uri].hash
124
141
  end
125
142
 
126
143
  # Builds the object from hash
@@ -0,0 +1,357 @@
1
+ =begin
2
+ #Coinbase Platform API
3
+
4
+ #This is the OpenAPI 3.0 specification for the Coinbase Platform APIs, used in conjunction with the Coinbase Platform SDKs.
5
+
6
+ The version of the OpenAPI document: 0.0.1-alpha
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.8.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Coinbase::Client
17
+ # A representation of an onchain stored name from name systems i.e. ENS or Basenames
18
+ class OnchainName
19
+ # The ID for the NFT related to this name
20
+ attr_accessor :token_id
21
+
22
+ # The onchain address of the owner of the name
23
+ attr_accessor :owner_address
24
+
25
+ # The onchain address of the manager of the name
26
+ attr_accessor :manager_address
27
+
28
+ # The primary onchain address of the name
29
+ attr_accessor :primary_address
30
+
31
+ # The readable format for the name in complete form
32
+ attr_accessor :domain
33
+
34
+ # The visual representation attached to this name
35
+ attr_accessor :avatar
36
+
37
+ # The ID of the blockchain network
38
+ attr_accessor :network_id
39
+
40
+ # The expiration date for this name's ownership
41
+ attr_accessor :expires_at
42
+
43
+ # The metadata attached to this name
44
+ attr_accessor :text_records
45
+
46
+ # Whether this name is the primary name for the owner (This is when the ETH coin address for this name is equal to the primary_address. More info here https://docs.ens.domains/ensip/19)
47
+ attr_accessor :is_primary
48
+
49
+ # Attribute mapping from ruby-style variable name to JSON key.
50
+ def self.attribute_map
51
+ {
52
+ :'token_id' => :'token_id',
53
+ :'owner_address' => :'owner_address',
54
+ :'manager_address' => :'manager_address',
55
+ :'primary_address' => :'primary_address',
56
+ :'domain' => :'domain',
57
+ :'avatar' => :'avatar',
58
+ :'network_id' => :'network_id',
59
+ :'expires_at' => :'expires_at',
60
+ :'text_records' => :'text_records',
61
+ :'is_primary' => :'is_primary'
62
+ }
63
+ end
64
+
65
+ # Returns all the JSON keys this model knows about
66
+ def self.acceptable_attributes
67
+ attribute_map.values
68
+ end
69
+
70
+ # Attribute type mapping.
71
+ def self.openapi_types
72
+ {
73
+ :'token_id' => :'String',
74
+ :'owner_address' => :'String',
75
+ :'manager_address' => :'String',
76
+ :'primary_address' => :'String',
77
+ :'domain' => :'String',
78
+ :'avatar' => :'String',
79
+ :'network_id' => :'String',
80
+ :'expires_at' => :'Time',
81
+ :'text_records' => :'Hash<String, String>',
82
+ :'is_primary' => :'Boolean'
83
+ }
84
+ end
85
+
86
+ # List of attributes with nullable: true
87
+ def self.openapi_nullable
88
+ Set.new([
89
+ ])
90
+ end
91
+
92
+ # Initializes the object
93
+ # @param [Hash] attributes Model attributes in the form of hash
94
+ def initialize(attributes = {})
95
+ if (!attributes.is_a?(Hash))
96
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::OnchainName` initialize method"
97
+ end
98
+
99
+ # check to see if the attribute exists and convert string to symbol for hash key
100
+ attributes = attributes.each_with_object({}) { |(k, v), h|
101
+ if (!self.class.attribute_map.key?(k.to_sym))
102
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::OnchainName`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
103
+ end
104
+ h[k.to_sym] = v
105
+ }
106
+
107
+ if attributes.key?(:'token_id')
108
+ self.token_id = attributes[:'token_id']
109
+ else
110
+ self.token_id = nil
111
+ end
112
+
113
+ if attributes.key?(:'owner_address')
114
+ self.owner_address = attributes[:'owner_address']
115
+ else
116
+ self.owner_address = nil
117
+ end
118
+
119
+ if attributes.key?(:'manager_address')
120
+ self.manager_address = attributes[:'manager_address']
121
+ else
122
+ self.manager_address = nil
123
+ end
124
+
125
+ if attributes.key?(:'primary_address')
126
+ self.primary_address = attributes[:'primary_address']
127
+ end
128
+
129
+ if attributes.key?(:'domain')
130
+ self.domain = attributes[:'domain']
131
+ else
132
+ self.domain = nil
133
+ end
134
+
135
+ if attributes.key?(:'avatar')
136
+ self.avatar = attributes[:'avatar']
137
+ end
138
+
139
+ if attributes.key?(:'network_id')
140
+ self.network_id = attributes[:'network_id']
141
+ else
142
+ self.network_id = nil
143
+ end
144
+
145
+ if attributes.key?(:'expires_at')
146
+ self.expires_at = attributes[:'expires_at']
147
+ else
148
+ self.expires_at = nil
149
+ end
150
+
151
+ if attributes.key?(:'text_records')
152
+ if (value = attributes[:'text_records']).is_a?(Hash)
153
+ self.text_records = value
154
+ end
155
+ end
156
+
157
+ if attributes.key?(:'is_primary')
158
+ self.is_primary = attributes[:'is_primary']
159
+ else
160
+ self.is_primary = nil
161
+ end
162
+ end
163
+
164
+ # Show invalid properties with the reasons. Usually used together with valid?
165
+ # @return Array for valid properties with the reasons
166
+ def list_invalid_properties
167
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
168
+ invalid_properties = Array.new
169
+ if @token_id.nil?
170
+ invalid_properties.push('invalid value for "token_id", token_id cannot be nil.')
171
+ end
172
+
173
+ if @owner_address.nil?
174
+ invalid_properties.push('invalid value for "owner_address", owner_address cannot be nil.')
175
+ end
176
+
177
+ if @manager_address.nil?
178
+ invalid_properties.push('invalid value for "manager_address", manager_address cannot be nil.')
179
+ end
180
+
181
+ if @domain.nil?
182
+ invalid_properties.push('invalid value for "domain", domain cannot be nil.')
183
+ end
184
+
185
+ if @network_id.nil?
186
+ invalid_properties.push('invalid value for "network_id", network_id cannot be nil.')
187
+ end
188
+
189
+ if @expires_at.nil?
190
+ invalid_properties.push('invalid value for "expires_at", expires_at cannot be nil.')
191
+ end
192
+
193
+ if @is_primary.nil?
194
+ invalid_properties.push('invalid value for "is_primary", is_primary cannot be nil.')
195
+ end
196
+
197
+ invalid_properties
198
+ end
199
+
200
+ # Check to see if the all the properties in the model are valid
201
+ # @return true if the model is valid
202
+ def valid?
203
+ warn '[DEPRECATED] the `valid?` method is obsolete'
204
+ return false if @token_id.nil?
205
+ return false if @owner_address.nil?
206
+ return false if @manager_address.nil?
207
+ return false if @domain.nil?
208
+ return false if @network_id.nil?
209
+ return false if @expires_at.nil?
210
+ return false if @is_primary.nil?
211
+ true
212
+ end
213
+
214
+ # Checks equality by comparing each attribute.
215
+ # @param [Object] Object to be compared
216
+ def ==(o)
217
+ return true if self.equal?(o)
218
+ self.class == o.class &&
219
+ token_id == o.token_id &&
220
+ owner_address == o.owner_address &&
221
+ manager_address == o.manager_address &&
222
+ primary_address == o.primary_address &&
223
+ domain == o.domain &&
224
+ avatar == o.avatar &&
225
+ network_id == o.network_id &&
226
+ expires_at == o.expires_at &&
227
+ text_records == o.text_records &&
228
+ is_primary == o.is_primary
229
+ end
230
+
231
+ # @see the `==` method
232
+ # @param [Object] Object to be compared
233
+ def eql?(o)
234
+ self == o
235
+ end
236
+
237
+ # Calculates hash code according to all attributes.
238
+ # @return [Integer] Hash code
239
+ def hash
240
+ [token_id, owner_address, manager_address, primary_address, domain, avatar, network_id, expires_at, text_records, is_primary].hash
241
+ end
242
+
243
+ # Builds the object from hash
244
+ # @param [Hash] attributes Model attributes in the form of hash
245
+ # @return [Object] Returns the model itself
246
+ def self.build_from_hash(attributes)
247
+ return nil unless attributes.is_a?(Hash)
248
+ attributes = attributes.transform_keys(&:to_sym)
249
+ transformed_hash = {}
250
+ openapi_types.each_pair do |key, type|
251
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
252
+ transformed_hash["#{key}"] = nil
253
+ elsif type =~ /\AArray<(.*)>/i
254
+ # check to ensure the input is an array given that the attribute
255
+ # is documented as an array but the input is not
256
+ if attributes[attribute_map[key]].is_a?(Array)
257
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
258
+ end
259
+ elsif !attributes[attribute_map[key]].nil?
260
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
261
+ end
262
+ end
263
+ new(transformed_hash)
264
+ end
265
+
266
+ # Deserializes the data based on type
267
+ # @param string type Data type
268
+ # @param string value Value to be deserialized
269
+ # @return [Object] Deserialized data
270
+ def self._deserialize(type, value)
271
+ case type.to_sym
272
+ when :Time
273
+ Time.parse(value)
274
+ when :Date
275
+ Date.parse(value)
276
+ when :String
277
+ value.to_s
278
+ when :Integer
279
+ value.to_i
280
+ when :Float
281
+ value.to_f
282
+ when :Boolean
283
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
284
+ true
285
+ else
286
+ false
287
+ end
288
+ when :Object
289
+ # generic object (usually a Hash), return directly
290
+ value
291
+ when /\AArray<(?<inner_type>.+)>\z/
292
+ inner_type = Regexp.last_match[:inner_type]
293
+ value.map { |v| _deserialize(inner_type, v) }
294
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
295
+ k_type = Regexp.last_match[:k_type]
296
+ v_type = Regexp.last_match[:v_type]
297
+ {}.tap do |hash|
298
+ value.each do |k, v|
299
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
300
+ end
301
+ end
302
+ else # model
303
+ # models (e.g. Pet) or oneOf
304
+ klass = Coinbase::Client.const_get(type)
305
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
306
+ end
307
+ end
308
+
309
+ # Returns the string representation of the object
310
+ # @return [String] String presentation of the object
311
+ def to_s
312
+ to_hash.to_s
313
+ end
314
+
315
+ # to_body is an alias to to_hash (backward compatibility)
316
+ # @return [Hash] Returns the object in the form of hash
317
+ def to_body
318
+ to_hash
319
+ end
320
+
321
+ # Returns the object in the form of hash
322
+ # @return [Hash] Returns the object in the form of hash
323
+ def to_hash
324
+ hash = {}
325
+ self.class.attribute_map.each_pair do |attr, param|
326
+ value = self.send(attr)
327
+ if value.nil?
328
+ is_nullable = self.class.openapi_nullable.include?(attr)
329
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
330
+ end
331
+
332
+ hash[param] = _to_hash(value)
333
+ end
334
+ hash
335
+ end
336
+
337
+ # Outputs non-array value in the form of hash
338
+ # For object, use to_hash. Otherwise, just return the value
339
+ # @param [Object] value Any valid value
340
+ # @return [Hash] Returns the value in the form of hash
341
+ def _to_hash(value)
342
+ if value.is_a?(Array)
343
+ value.compact.map { |v| _to_hash(v) }
344
+ elsif value.is_a?(Hash)
345
+ {}.tap do |hash|
346
+ value.each { |k, v| hash[k] = _to_hash(v) }
347
+ end
348
+ elsif value.respond_to? :to_hash
349
+ value.to_hash
350
+ else
351
+ value
352
+ end
353
+ end
354
+
355
+ end
356
+
357
+ end