coinbase-sdk 0.0.5 → 0.0.7

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address.rb +113 -40
  3. data/lib/coinbase/asset.rb +18 -4
  4. data/lib/coinbase/authenticator.rb +1 -1
  5. data/lib/coinbase/client/api/server_signers_api.rb +429 -0
  6. data/lib/coinbase/client/api/stake_api.rb +86 -0
  7. data/lib/coinbase/client/api/trades_api.rb +342 -0
  8. data/lib/coinbase/client/models/broadcast_trade_request.rb +232 -0
  9. data/lib/coinbase/client/models/build_staking_operation_request.rb +291 -0
  10. data/lib/coinbase/client/models/create_address_request.rb +0 -14
  11. data/lib/coinbase/client/models/create_server_signer_request.rb +239 -0
  12. data/lib/coinbase/client/models/create_trade_request.rb +256 -0
  13. data/lib/coinbase/client/models/create_wallet_request.rb +1 -1
  14. data/lib/coinbase/client/models/create_wallet_request_wallet.rb +233 -0
  15. data/lib/coinbase/client/models/feature.rb +42 -0
  16. data/lib/coinbase/client/models/request_faucet_funds200_response.rb +222 -0
  17. data/lib/coinbase/client/models/seed_creation_event.rb +240 -0
  18. data/lib/coinbase/client/models/seed_creation_event_result.rb +274 -0
  19. data/lib/coinbase/client/models/server_signer.rb +235 -0
  20. data/lib/coinbase/client/models/server_signer_event.rb +239 -0
  21. data/lib/coinbase/client/models/server_signer_event_event.rb +105 -0
  22. data/lib/coinbase/client/models/server_signer_event_list.rb +275 -0
  23. data/lib/coinbase/client/models/server_signer_list.rb +275 -0
  24. data/lib/coinbase/client/models/signature_creation_event.rb +363 -0
  25. data/lib/coinbase/client/models/signature_creation_event_result.rb +329 -0
  26. data/lib/coinbase/client/models/staking_operation.rb +222 -0
  27. data/lib/coinbase/client/models/trade.rb +365 -0
  28. data/lib/coinbase/client/models/trade_list.rb +275 -0
  29. data/lib/coinbase/client/models/transaction.rb +338 -0
  30. data/lib/coinbase/client/models/transaction_type.rb +39 -0
  31. data/lib/coinbase/client/models/transfer.rb +33 -1
  32. data/lib/coinbase/client/models/wallet.rb +74 -4
  33. data/lib/coinbase/client.rb +23 -0
  34. data/lib/coinbase/errors.rb +3 -0
  35. data/lib/coinbase/server_signer.rb +57 -0
  36. data/lib/coinbase/trade.rb +147 -0
  37. data/lib/coinbase/transaction.rb +125 -0
  38. data/lib/coinbase/transfer.rb +38 -71
  39. data/lib/coinbase/user.rb +14 -89
  40. data/lib/coinbase/wallet.rb +188 -27
  41. data/lib/coinbase.rb +19 -4
  42. metadata +43 -2
@@ -0,0 +1,342 @@
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
+ Contact: yuga.cohler@coinbase.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.5.0
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module Coinbase::Client
16
+ class TradesApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Broadcast a trade
23
+ # Broadcast a trade
24
+ # @param wallet_id [String] The ID of the wallet the address belongs to
25
+ # @param address_id [String] The ID of the address the trade belongs to
26
+ # @param trade_id [String] The ID of the trade to broadcast
27
+ # @param broadcast_trade_request [BroadcastTradeRequest]
28
+ # @param [Hash] opts the optional parameters
29
+ # @return [Trade]
30
+ def broadcast_trade(wallet_id, address_id, trade_id, broadcast_trade_request, opts = {})
31
+ data, _status_code, _headers = broadcast_trade_with_http_info(wallet_id, address_id, trade_id, broadcast_trade_request, opts)
32
+ data
33
+ end
34
+
35
+ # Broadcast a trade
36
+ # Broadcast a trade
37
+ # @param wallet_id [String] The ID of the wallet the address belongs to
38
+ # @param address_id [String] The ID of the address the trade belongs to
39
+ # @param trade_id [String] The ID of the trade to broadcast
40
+ # @param broadcast_trade_request [BroadcastTradeRequest]
41
+ # @param [Hash] opts the optional parameters
42
+ # @return [Array<(Trade, Integer, Hash)>] Trade data, response status code and response headers
43
+ def broadcast_trade_with_http_info(wallet_id, address_id, trade_id, broadcast_trade_request, opts = {})
44
+ if @api_client.config.debugging
45
+ @api_client.config.logger.debug 'Calling API: TradesApi.broadcast_trade ...'
46
+ end
47
+ # verify the required parameter 'wallet_id' is set
48
+ if @api_client.config.client_side_validation && wallet_id.nil?
49
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling TradesApi.broadcast_trade"
50
+ end
51
+ # verify the required parameter 'address_id' is set
52
+ if @api_client.config.client_side_validation && address_id.nil?
53
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling TradesApi.broadcast_trade"
54
+ end
55
+ # verify the required parameter 'trade_id' is set
56
+ if @api_client.config.client_side_validation && trade_id.nil?
57
+ fail ArgumentError, "Missing the required parameter 'trade_id' when calling TradesApi.broadcast_trade"
58
+ end
59
+ # verify the required parameter 'broadcast_trade_request' is set
60
+ if @api_client.config.client_side_validation && broadcast_trade_request.nil?
61
+ fail ArgumentError, "Missing the required parameter 'broadcast_trade_request' when calling TradesApi.broadcast_trade"
62
+ end
63
+ # resource path
64
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/trades/{trade_id}/broadcast'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)).sub('{' + 'trade_id' + '}', CGI.escape(trade_id.to_s))
65
+
66
+ # query parameters
67
+ query_params = opts[:query_params] || {}
68
+
69
+ # header parameters
70
+ header_params = opts[:header_params] || {}
71
+ # HTTP header 'Accept' (if needed)
72
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
73
+ # HTTP header 'Content-Type'
74
+ content_type = @api_client.select_header_content_type(['application/json'])
75
+ if !content_type.nil?
76
+ header_params['Content-Type'] = content_type
77
+ end
78
+
79
+ # form parameters
80
+ form_params = opts[:form_params] || {}
81
+
82
+ # http body (model)
83
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(broadcast_trade_request)
84
+
85
+ # return_type
86
+ return_type = opts[:debug_return_type] || 'Trade'
87
+
88
+ # auth_names
89
+ auth_names = opts[:debug_auth_names] || []
90
+
91
+ new_options = opts.merge(
92
+ :operation => :"TradesApi.broadcast_trade",
93
+ :header_params => header_params,
94
+ :query_params => query_params,
95
+ :form_params => form_params,
96
+ :body => post_body,
97
+ :auth_names => auth_names,
98
+ :return_type => return_type
99
+ )
100
+
101
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
102
+ if @api_client.config.debugging
103
+ @api_client.config.logger.debug "API called: TradesApi#broadcast_trade\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
104
+ end
105
+ return data, status_code, headers
106
+ end
107
+
108
+ # Create a new trade for an address
109
+ # Create a new trade
110
+ # @param wallet_id [String] The ID of the wallet the source address belongs to
111
+ # @param address_id [String] The ID of the address to conduct the trade from
112
+ # @param create_trade_request [CreateTradeRequest]
113
+ # @param [Hash] opts the optional parameters
114
+ # @return [Trade]
115
+ def create_trade(wallet_id, address_id, create_trade_request, opts = {})
116
+ data, _status_code, _headers = create_trade_with_http_info(wallet_id, address_id, create_trade_request, opts)
117
+ data
118
+ end
119
+
120
+ # Create a new trade for an address
121
+ # Create a new trade
122
+ # @param wallet_id [String] The ID of the wallet the source address belongs to
123
+ # @param address_id [String] The ID of the address to conduct the trade from
124
+ # @param create_trade_request [CreateTradeRequest]
125
+ # @param [Hash] opts the optional parameters
126
+ # @return [Array<(Trade, Integer, Hash)>] Trade data, response status code and response headers
127
+ def create_trade_with_http_info(wallet_id, address_id, create_trade_request, opts = {})
128
+ if @api_client.config.debugging
129
+ @api_client.config.logger.debug 'Calling API: TradesApi.create_trade ...'
130
+ end
131
+ # verify the required parameter 'wallet_id' is set
132
+ if @api_client.config.client_side_validation && wallet_id.nil?
133
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling TradesApi.create_trade"
134
+ end
135
+ # verify the required parameter 'address_id' is set
136
+ if @api_client.config.client_side_validation && address_id.nil?
137
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling TradesApi.create_trade"
138
+ end
139
+ # verify the required parameter 'create_trade_request' is set
140
+ if @api_client.config.client_side_validation && create_trade_request.nil?
141
+ fail ArgumentError, "Missing the required parameter 'create_trade_request' when calling TradesApi.create_trade"
142
+ end
143
+ # resource path
144
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/trades'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s))
145
+
146
+ # query parameters
147
+ query_params = opts[:query_params] || {}
148
+
149
+ # header parameters
150
+ header_params = opts[:header_params] || {}
151
+ # HTTP header 'Accept' (if needed)
152
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
153
+ # HTTP header 'Content-Type'
154
+ content_type = @api_client.select_header_content_type(['application/json'])
155
+ if !content_type.nil?
156
+ header_params['Content-Type'] = content_type
157
+ end
158
+
159
+ # form parameters
160
+ form_params = opts[:form_params] || {}
161
+
162
+ # http body (model)
163
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(create_trade_request)
164
+
165
+ # return_type
166
+ return_type = opts[:debug_return_type] || 'Trade'
167
+
168
+ # auth_names
169
+ auth_names = opts[:debug_auth_names] || []
170
+
171
+ new_options = opts.merge(
172
+ :operation => :"TradesApi.create_trade",
173
+ :header_params => header_params,
174
+ :query_params => query_params,
175
+ :form_params => form_params,
176
+ :body => post_body,
177
+ :auth_names => auth_names,
178
+ :return_type => return_type
179
+ )
180
+
181
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
182
+ if @api_client.config.debugging
183
+ @api_client.config.logger.debug "API called: TradesApi#create_trade\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
184
+ end
185
+ return data, status_code, headers
186
+ end
187
+
188
+ # Get a trade by ID
189
+ # Get a trade by ID
190
+ # @param wallet_id [String] The ID of the wallet the address belongs to
191
+ # @param address_id [String] The ID of the address the trade belongs to
192
+ # @param trade_id [String] The ID of the trade to fetch
193
+ # @param [Hash] opts the optional parameters
194
+ # @return [Trade]
195
+ def get_trade(wallet_id, address_id, trade_id, opts = {})
196
+ data, _status_code, _headers = get_trade_with_http_info(wallet_id, address_id, trade_id, opts)
197
+ data
198
+ end
199
+
200
+ # Get a trade by ID
201
+ # Get a trade by ID
202
+ # @param wallet_id [String] The ID of the wallet the address belongs to
203
+ # @param address_id [String] The ID of the address the trade belongs to
204
+ # @param trade_id [String] The ID of the trade to fetch
205
+ # @param [Hash] opts the optional parameters
206
+ # @return [Array<(Trade, Integer, Hash)>] Trade data, response status code and response headers
207
+ def get_trade_with_http_info(wallet_id, address_id, trade_id, opts = {})
208
+ if @api_client.config.debugging
209
+ @api_client.config.logger.debug 'Calling API: TradesApi.get_trade ...'
210
+ end
211
+ # verify the required parameter 'wallet_id' is set
212
+ if @api_client.config.client_side_validation && wallet_id.nil?
213
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling TradesApi.get_trade"
214
+ end
215
+ # verify the required parameter 'address_id' is set
216
+ if @api_client.config.client_side_validation && address_id.nil?
217
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling TradesApi.get_trade"
218
+ end
219
+ # verify the required parameter 'trade_id' is set
220
+ if @api_client.config.client_side_validation && trade_id.nil?
221
+ fail ArgumentError, "Missing the required parameter 'trade_id' when calling TradesApi.get_trade"
222
+ end
223
+ # resource path
224
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/trades/{trade_id}'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s)).sub('{' + 'trade_id' + '}', CGI.escape(trade_id.to_s))
225
+
226
+ # query parameters
227
+ query_params = opts[:query_params] || {}
228
+
229
+ # header parameters
230
+ header_params = opts[:header_params] || {}
231
+ # HTTP header 'Accept' (if needed)
232
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
233
+
234
+ # form parameters
235
+ form_params = opts[:form_params] || {}
236
+
237
+ # http body (model)
238
+ post_body = opts[:debug_body]
239
+
240
+ # return_type
241
+ return_type = opts[:debug_return_type] || 'Trade'
242
+
243
+ # auth_names
244
+ auth_names = opts[:debug_auth_names] || []
245
+
246
+ new_options = opts.merge(
247
+ :operation => :"TradesApi.get_trade",
248
+ :header_params => header_params,
249
+ :query_params => query_params,
250
+ :form_params => form_params,
251
+ :body => post_body,
252
+ :auth_names => auth_names,
253
+ :return_type => return_type
254
+ )
255
+
256
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
257
+ if @api_client.config.debugging
258
+ @api_client.config.logger.debug "API called: TradesApi#get_trade\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
259
+ end
260
+ return data, status_code, headers
261
+ end
262
+
263
+ # List trades for an address.
264
+ # List trades for an address.
265
+ # @param wallet_id [String] The ID of the wallet the address belongs to
266
+ # @param address_id [String] The ID of the address to list trades for
267
+ # @param [Hash] opts the optional parameters
268
+ # @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
269
+ # @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
270
+ # @return [TradeList]
271
+ def list_trades(wallet_id, address_id, opts = {})
272
+ data, _status_code, _headers = list_trades_with_http_info(wallet_id, address_id, opts)
273
+ data
274
+ end
275
+
276
+ # List trades for an address.
277
+ # List trades for an address.
278
+ # @param wallet_id [String] The ID of the wallet the address belongs to
279
+ # @param address_id [String] The ID of the address to list trades for
280
+ # @param [Hash] opts the optional parameters
281
+ # @option opts [Integer] :limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
282
+ # @option opts [String] :page A cursor for pagination across multiple pages of results. Don&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
283
+ # @return [Array<(TradeList, Integer, Hash)>] TradeList data, response status code and response headers
284
+ def list_trades_with_http_info(wallet_id, address_id, opts = {})
285
+ if @api_client.config.debugging
286
+ @api_client.config.logger.debug 'Calling API: TradesApi.list_trades ...'
287
+ end
288
+ # verify the required parameter 'wallet_id' is set
289
+ if @api_client.config.client_side_validation && wallet_id.nil?
290
+ fail ArgumentError, "Missing the required parameter 'wallet_id' when calling TradesApi.list_trades"
291
+ end
292
+ # verify the required parameter 'address_id' is set
293
+ if @api_client.config.client_side_validation && address_id.nil?
294
+ fail ArgumentError, "Missing the required parameter 'address_id' when calling TradesApi.list_trades"
295
+ end
296
+ if @api_client.config.client_side_validation && !opts[:'page'].nil? && opts[:'page'].to_s.length > 5000
297
+ fail ArgumentError, 'invalid value for "opts[:"page"]" when calling TradesApi.list_trades, the character length must be smaller than or equal to 5000.'
298
+ end
299
+
300
+ # resource path
301
+ local_var_path = '/v1/wallets/{wallet_id}/addresses/{address_id}/trades'.sub('{' + 'wallet_id' + '}', CGI.escape(wallet_id.to_s)).sub('{' + 'address_id' + '}', CGI.escape(address_id.to_s))
302
+
303
+ # query parameters
304
+ query_params = opts[:query_params] || {}
305
+ query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
306
+ query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
307
+
308
+ # header parameters
309
+ header_params = opts[:header_params] || {}
310
+ # HTTP header 'Accept' (if needed)
311
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
312
+
313
+ # form parameters
314
+ form_params = opts[:form_params] || {}
315
+
316
+ # http body (model)
317
+ post_body = opts[:debug_body]
318
+
319
+ # return_type
320
+ return_type = opts[:debug_return_type] || 'TradeList'
321
+
322
+ # auth_names
323
+ auth_names = opts[:debug_auth_names] || []
324
+
325
+ new_options = opts.merge(
326
+ :operation => :"TradesApi.list_trades",
327
+ :header_params => header_params,
328
+ :query_params => query_params,
329
+ :form_params => form_params,
330
+ :body => post_body,
331
+ :auth_names => auth_names,
332
+ :return_type => return_type
333
+ )
334
+
335
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
336
+ if @api_client.config.debugging
337
+ @api_client.config.logger.debug "API called: TradesApi#list_trades\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
338
+ end
339
+ return data, status_code, headers
340
+ end
341
+ end
342
+ end
@@ -0,0 +1,232 @@
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
+ Contact: yuga.cohler@coinbase.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.5.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Coinbase::Client
17
+ class BroadcastTradeRequest
18
+ # The hex-encoded signed payload of the trade
19
+ attr_accessor :signed_payload
20
+
21
+ # The hex-encoded signed payload of the approval transaction
22
+ attr_accessor :approve_transaction_signed_payload
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'signed_payload' => :'signed_payload',
28
+ :'approve_transaction_signed_payload' => :'approve_transaction_signed_payload'
29
+ }
30
+ end
31
+
32
+ # Returns all the JSON keys this model knows about
33
+ def self.acceptable_attributes
34
+ attribute_map.values
35
+ end
36
+
37
+ # Attribute type mapping.
38
+ def self.openapi_types
39
+ {
40
+ :'signed_payload' => :'String',
41
+ :'approve_transaction_signed_payload' => :'String'
42
+ }
43
+ end
44
+
45
+ # List of attributes with nullable: true
46
+ def self.openapi_nullable
47
+ Set.new([
48
+ ])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::BroadcastTradeRequest` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::BroadcastTradeRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'signed_payload')
67
+ self.signed_payload = attributes[:'signed_payload']
68
+ else
69
+ self.signed_payload = nil
70
+ end
71
+
72
+ if attributes.key?(:'approve_transaction_signed_payload')
73
+ self.approve_transaction_signed_payload = attributes[:'approve_transaction_signed_payload']
74
+ end
75
+ end
76
+
77
+ # Show invalid properties with the reasons. Usually used together with valid?
78
+ # @return Array for valid properties with the reasons
79
+ def list_invalid_properties
80
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
81
+ invalid_properties = Array.new
82
+ if @signed_payload.nil?
83
+ invalid_properties.push('invalid value for "signed_payload", signed_payload cannot be nil.')
84
+ end
85
+
86
+ invalid_properties
87
+ end
88
+
89
+ # Check to see if the all the properties in the model are valid
90
+ # @return true if the model is valid
91
+ def valid?
92
+ warn '[DEPRECATED] the `valid?` method is obsolete'
93
+ return false if @signed_payload.nil?
94
+ true
95
+ end
96
+
97
+ # Checks equality by comparing each attribute.
98
+ # @param [Object] Object to be compared
99
+ def ==(o)
100
+ return true if self.equal?(o)
101
+ self.class == o.class &&
102
+ signed_payload == o.signed_payload &&
103
+ approve_transaction_signed_payload == o.approve_transaction_signed_payload
104
+ end
105
+
106
+ # @see the `==` method
107
+ # @param [Object] Object to be compared
108
+ def eql?(o)
109
+ self == o
110
+ end
111
+
112
+ # Calculates hash code according to all attributes.
113
+ # @return [Integer] Hash code
114
+ def hash
115
+ [signed_payload, approve_transaction_signed_payload].hash
116
+ end
117
+
118
+ # Builds the object from hash
119
+ # @param [Hash] attributes Model attributes in the form of hash
120
+ # @return [Object] Returns the model itself
121
+ def self.build_from_hash(attributes)
122
+ return nil unless attributes.is_a?(Hash)
123
+ attributes = attributes.transform_keys(&:to_sym)
124
+ transformed_hash = {}
125
+ openapi_types.each_pair do |key, type|
126
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
127
+ transformed_hash["#{key}"] = nil
128
+ elsif type =~ /\AArray<(.*)>/i
129
+ # check to ensure the input is an array given that the attribute
130
+ # is documented as an array but the input is not
131
+ if attributes[attribute_map[key]].is_a?(Array)
132
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
133
+ end
134
+ elsif !attributes[attribute_map[key]].nil?
135
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
136
+ end
137
+ end
138
+ new(transformed_hash)
139
+ end
140
+
141
+ # Deserializes the data based on type
142
+ # @param string type Data type
143
+ # @param string value Value to be deserialized
144
+ # @return [Object] Deserialized data
145
+ def self._deserialize(type, value)
146
+ case type.to_sym
147
+ when :Time
148
+ Time.parse(value)
149
+ when :Date
150
+ Date.parse(value)
151
+ when :String
152
+ value.to_s
153
+ when :Integer
154
+ value.to_i
155
+ when :Float
156
+ value.to_f
157
+ when :Boolean
158
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
159
+ true
160
+ else
161
+ false
162
+ end
163
+ when :Object
164
+ # generic object (usually a Hash), return directly
165
+ value
166
+ when /\AArray<(?<inner_type>.+)>\z/
167
+ inner_type = Regexp.last_match[:inner_type]
168
+ value.map { |v| _deserialize(inner_type, v) }
169
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
170
+ k_type = Regexp.last_match[:k_type]
171
+ v_type = Regexp.last_match[:v_type]
172
+ {}.tap do |hash|
173
+ value.each do |k, v|
174
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
175
+ end
176
+ end
177
+ else # model
178
+ # models (e.g. Pet) or oneOf
179
+ klass = Coinbase::Client.const_get(type)
180
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
181
+ end
182
+ end
183
+
184
+ # Returns the string representation of the object
185
+ # @return [String] String presentation of the object
186
+ def to_s
187
+ to_hash.to_s
188
+ end
189
+
190
+ # to_body is an alias to to_hash (backward compatibility)
191
+ # @return [Hash] Returns the object in the form of hash
192
+ def to_body
193
+ to_hash
194
+ end
195
+
196
+ # Returns the object in the form of hash
197
+ # @return [Hash] Returns the object in the form of hash
198
+ def to_hash
199
+ hash = {}
200
+ self.class.attribute_map.each_pair do |attr, param|
201
+ value = self.send(attr)
202
+ if value.nil?
203
+ is_nullable = self.class.openapi_nullable.include?(attr)
204
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
205
+ end
206
+
207
+ hash[param] = _to_hash(value)
208
+ end
209
+ hash
210
+ end
211
+
212
+ # Outputs non-array value in the form of hash
213
+ # For object, use to_hash. Otherwise, just return the value
214
+ # @param [Object] value Any valid value
215
+ # @return [Hash] Returns the value in the form of hash
216
+ def _to_hash(value)
217
+ if value.is_a?(Array)
218
+ value.compact.map { |v| _to_hash(v) }
219
+ elsif value.is_a?(Hash)
220
+ {}.tap do |hash|
221
+ value.each { |k, v| hash[k] = _to_hash(v) }
222
+ end
223
+ elsif value.respond_to? :to_hash
224
+ value.to_hash
225
+ else
226
+ value
227
+ end
228
+ end
229
+
230
+ end
231
+
232
+ end