coinbase-sdk 0.0.1 → 0.0.2

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coinbase/address.rb +88 -49
  3. data/lib/coinbase/asset.rb +2 -1
  4. data/lib/coinbase/authenticator.rb +52 -0
  5. data/lib/coinbase/balance_map.rb +1 -1
  6. data/lib/coinbase/client/api/addresses_api.rb +385 -0
  7. data/lib/coinbase/client/api/transfers_api.rb +256 -0
  8. data/lib/coinbase/client/api/users_api.rb +79 -0
  9. data/lib/coinbase/client/api/wallets_api.rb +348 -0
  10. data/lib/coinbase/client/api_client.rb +431 -0
  11. data/lib/coinbase/client/api_error.rb +58 -0
  12. data/lib/coinbase/client/configuration.rb +375 -0
  13. data/lib/coinbase/client/models/address.rb +273 -0
  14. data/lib/coinbase/client/models/address_balance_list.rb +275 -0
  15. data/lib/coinbase/client/models/address_list.rb +275 -0
  16. data/lib/coinbase/client/models/asset.rb +260 -0
  17. data/lib/coinbase/client/models/balance.rb +239 -0
  18. data/lib/coinbase/client/models/create_address_request.rb +239 -0
  19. data/lib/coinbase/client/models/create_transfer_request.rb +273 -0
  20. data/lib/coinbase/client/models/create_wallet_request.rb +221 -0
  21. data/lib/coinbase/client/models/error.rb +278 -0
  22. data/lib/coinbase/client/models/transfer.rb +393 -0
  23. data/lib/coinbase/client/models/transfer_list.rb +275 -0
  24. data/lib/coinbase/client/models/user.rb +231 -0
  25. data/lib/coinbase/client/models/wallet.rb +241 -0
  26. data/lib/coinbase/client/models/wallet_list.rb +275 -0
  27. data/lib/coinbase/client/version.rb +15 -0
  28. data/lib/coinbase/client.rb +57 -0
  29. data/lib/coinbase/constants.rb +5 -1
  30. data/lib/coinbase/middleware.rb +21 -0
  31. data/lib/coinbase/network.rb +2 -2
  32. data/lib/coinbase/transfer.rb +69 -54
  33. data/lib/coinbase/user.rb +64 -0
  34. data/lib/coinbase/wallet.rb +146 -54
  35. data/lib/coinbase.rb +73 -9
  36. metadata +74 -6
@@ -0,0 +1,375 @@
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
+ module Coinbase::Client
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
64
+
65
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
66
+ # Overrides the access_token if set
67
+ # @return [Proc]
68
+ attr_accessor :access_token_getter
69
+
70
+ # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
71
+ # HTTP responses with return type `File` will be returned as a stream of binary data.
72
+ # Default to false.
73
+ attr_accessor :return_binary_data
74
+
75
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
76
+ # details will be logged with `logger.debug` (see the `logger` attribute).
77
+ # Default to false.
78
+ #
79
+ # @return [true, false]
80
+ attr_accessor :debugging
81
+
82
+ # Defines the logger used for debugging.
83
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
84
+ #
85
+ # @return [#debug]
86
+ attr_accessor :logger
87
+
88
+ # Defines the temporary folder to store downloaded files
89
+ # (for API endpoints that have file response).
90
+ # Default to use `Tempfile`.
91
+ #
92
+ # @return [String]
93
+ attr_accessor :temp_folder_path
94
+
95
+ # The time limit for HTTP request in seconds.
96
+ # Default to 0 (never times out).
97
+ attr_accessor :timeout
98
+
99
+ # Set this to false to skip client side validation in the operation.
100
+ # Default to true.
101
+ # @return [true, false]
102
+ attr_accessor :client_side_validation
103
+
104
+ ### TLS/SSL setting
105
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
106
+ # Default to true.
107
+ #
108
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
109
+ #
110
+ # @return [true, false]
111
+ attr_accessor :ssl_verify
112
+
113
+ ### TLS/SSL setting
114
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
115
+ #
116
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
117
+ #
118
+ attr_accessor :ssl_verify_mode
119
+
120
+ ### TLS/SSL setting
121
+ # Set this to customize the certificate file to verify the peer.
122
+ #
123
+ # @return [String] the path to the certificate file
124
+ attr_accessor :ssl_ca_file
125
+
126
+ ### TLS/SSL setting
127
+ # Client certificate file (for client certificate)
128
+ attr_accessor :ssl_client_cert
129
+
130
+ ### TLS/SSL setting
131
+ # Client private key file (for client certificate)
132
+ attr_accessor :ssl_client_key
133
+
134
+ ### Proxy setting
135
+ # HTTP Proxy settings
136
+ attr_accessor :proxy
137
+
138
+ # Set this to customize parameters encoder of array parameter.
139
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
140
+ #
141
+ # @see The params_encoder option of Faraday. Related source code:
142
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
143
+ attr_accessor :params_encoder
144
+
145
+
146
+ attr_accessor :inject_format
147
+
148
+ attr_accessor :force_ending_format
149
+
150
+ def initialize
151
+ @scheme = 'https'
152
+ @host = 'api.cdp.coinbase.com'
153
+ @base_path = '/platform'
154
+ @server_index = nil
155
+ @server_operation_index = {}
156
+ @server_variables = {}
157
+ @server_operation_variables = {}
158
+ @api_key = {}
159
+ @api_key_prefix = {}
160
+ @client_side_validation = true
161
+ @ssl_verify = true
162
+ @ssl_verify_mode = nil
163
+ @ssl_ca_file = nil
164
+ @ssl_client_cert = nil
165
+ @ssl_client_key = nil
166
+ @middlewares = Hash.new { |h, k| h[k] = [] }
167
+ @configure_connection_blocks = []
168
+ @timeout = 60
169
+ # return data as binary instead of file
170
+ @return_binary_data = false
171
+ @params_encoder = nil
172
+ @debugging = false
173
+ @inject_format = false
174
+ @force_ending_format = false
175
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
176
+
177
+ yield(self) if block_given?
178
+ end
179
+
180
+ # The default Configuration object.
181
+ def self.default
182
+ @@default ||= Configuration.new
183
+ end
184
+
185
+ def configure
186
+ yield(self) if block_given?
187
+ end
188
+
189
+ def scheme=(scheme)
190
+ # remove :// from scheme
191
+ @scheme = scheme.sub(/:\/\//, '')
192
+ end
193
+
194
+ def host=(host)
195
+ # remove http(s):// and anything after a slash
196
+ @host = host.sub(/https?:\/\//, '').split('/').first
197
+ end
198
+
199
+ def base_path=(base_path)
200
+ # Add leading and trailing slashes to base_path
201
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
202
+ @base_path = '' if @base_path == '/'
203
+ end
204
+
205
+ # Returns base URL for specified operation based on server settings
206
+ def base_url(operation = nil)
207
+ if operation_server_settings.key?(operation) then
208
+ index = server_operation_index.fetch(operation, server_index)
209
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
210
+ else
211
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
212
+ end
213
+ end
214
+
215
+ # Gets API key (with prefix if set).
216
+ # @param [String] param_name the parameter name of API key auth
217
+ def api_key_with_prefix(param_name, param_alias = nil)
218
+ key = @api_key[param_name]
219
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
220
+ if @api_key_prefix[param_name]
221
+ "#{@api_key_prefix[param_name]} #{key}"
222
+ else
223
+ key
224
+ end
225
+ end
226
+
227
+ # Gets access_token using access_token_getter or uses the static access_token
228
+ def access_token_with_refresh
229
+ return access_token if access_token_getter.nil?
230
+ access_token_getter.call
231
+ end
232
+
233
+ # Gets Basic Auth token string
234
+ def basic_auth_token
235
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
236
+ end
237
+
238
+ # Returns Auth Settings hash for api client.
239
+ def auth_settings
240
+ {
241
+ }
242
+ end
243
+
244
+ # Returns an array of Server setting
245
+ def server_settings
246
+ [
247
+ {
248
+ url: "https://api.cdp.coinbase.com/platform",
249
+ description: "No description provided",
250
+ }
251
+ ]
252
+ end
253
+
254
+ def operation_server_settings
255
+ {
256
+ }
257
+ end
258
+
259
+ # Returns URL based on server settings
260
+ #
261
+ # @param index array index of the server settings
262
+ # @param variables hash of variable and the corresponding value
263
+ def server_url(index, variables = {}, servers = nil)
264
+ servers = server_settings if servers == nil
265
+
266
+ # check array index out of bound
267
+ if (index.nil? || index < 0 || index >= servers.size)
268
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
269
+ end
270
+
271
+ server = servers[index]
272
+ url = server[:url]
273
+
274
+ return url unless server.key? :variables
275
+
276
+ # go through variable and assign a value
277
+ server[:variables].each do |name, variable|
278
+ if variables.key?(name)
279
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
280
+ url.gsub! "{" + name.to_s + "}", variables[name]
281
+ else
282
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
283
+ end
284
+ else
285
+ # use default value
286
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
287
+ end
288
+ end
289
+
290
+ url
291
+ end
292
+
293
+ # Configure Faraday connection directly.
294
+ #
295
+ # ```
296
+ # c.configure_faraday_connection do |conn|
297
+ # conn.use Faraday::HttpCache, shared_cache: false, logger: logger
298
+ # conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
299
+ # logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
300
+ # end
301
+ # end
302
+ #
303
+ # c.configure_faraday_connection do |conn|
304
+ # conn.adapter :typhoeus
305
+ # end
306
+ # ```
307
+ #
308
+ # @param block [Proc] `#call`able object that takes one arg, the connection
309
+ def configure_faraday_connection(&block)
310
+ @configure_connection_blocks << block
311
+ end
312
+
313
+ def configure_connection(conn)
314
+ @configure_connection_blocks.each do |block|
315
+ block.call(conn)
316
+ end
317
+ end
318
+
319
+ # Adds middleware to the stack
320
+ def use(*middleware)
321
+ set_faraday_middleware(:use, *middleware)
322
+ end
323
+
324
+ # Adds request middleware to the stack
325
+ def request(*middleware)
326
+ set_faraday_middleware(:request, *middleware)
327
+ end
328
+
329
+ # Adds response middleware to the stack
330
+ def response(*middleware)
331
+ set_faraday_middleware(:response, *middleware)
332
+ end
333
+
334
+ # Adds Faraday middleware setting information to the stack
335
+ #
336
+ # @example Use the `set_faraday_middleware` method to set middleware information
337
+ # config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
338
+ # config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
339
+ # config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
340
+ # config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
341
+ # config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
342
+ # config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
343
+ #
344
+ # @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
345
+ def set_faraday_middleware(operation, key, *args, &block)
346
+ unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
347
+ fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
348
+ " :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
349
+ end
350
+
351
+ @middlewares[operation] << [key, args, block]
352
+ end
353
+ ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
354
+
355
+ # Set up middleware on the connection
356
+ def configure_middleware(connection)
357
+ return if @middlewares.empty?
358
+
359
+ [:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
360
+ next unless @middlewares.key?(operation)
361
+
362
+ @middlewares[operation].each do |key, args, block|
363
+ connection.builder.send(operation, key, *args, &block)
364
+ end
365
+ end
366
+
367
+ if @middlewares.key?(:delete)
368
+ @middlewares[:delete].each do |key, _args, _block|
369
+ connection.builder.delete(key)
370
+ end
371
+ end
372
+ end
373
+
374
+ end
375
+ end
@@ -0,0 +1,273 @@
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 Address
18
+ # The ID of the wallet that owns the address
19
+ attr_accessor :wallet_id
20
+
21
+ # The ID of the blockchain network
22
+ attr_accessor :network_id
23
+
24
+ # The public key from which the address is derived.
25
+ attr_accessor :public_key
26
+
27
+ # The onchain address derived on the server-side.
28
+ attr_accessor :address_id
29
+
30
+ # Attribute mapping from ruby-style variable name to JSON key.
31
+ def self.attribute_map
32
+ {
33
+ :'wallet_id' => :'wallet_id',
34
+ :'network_id' => :'network_id',
35
+ :'public_key' => :'public_key',
36
+ :'address_id' => :'address_id'
37
+ }
38
+ end
39
+
40
+ # Returns all the JSON keys this model knows about
41
+ def self.acceptable_attributes
42
+ attribute_map.values
43
+ end
44
+
45
+ # Attribute type mapping.
46
+ def self.openapi_types
47
+ {
48
+ :'wallet_id' => :'String',
49
+ :'network_id' => :'String',
50
+ :'public_key' => :'String',
51
+ :'address_id' => :'String'
52
+ }
53
+ end
54
+
55
+ # List of attributes with nullable: true
56
+ def self.openapi_nullable
57
+ Set.new([
58
+ ])
59
+ end
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ if (!attributes.is_a?(Hash))
65
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Coinbase::Client::Address` initialize method"
66
+ end
67
+
68
+ # check to see if the attribute exists and convert string to symbol for hash key
69
+ attributes = attributes.each_with_object({}) { |(k, v), h|
70
+ if (!self.class.attribute_map.key?(k.to_sym))
71
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Coinbase::Client::Address`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
72
+ end
73
+ h[k.to_sym] = v
74
+ }
75
+
76
+ if attributes.key?(:'wallet_id')
77
+ self.wallet_id = attributes[:'wallet_id']
78
+ else
79
+ self.wallet_id = nil
80
+ end
81
+
82
+ if attributes.key?(:'network_id')
83
+ self.network_id = attributes[:'network_id']
84
+ else
85
+ self.network_id = nil
86
+ end
87
+
88
+ if attributes.key?(:'public_key')
89
+ self.public_key = attributes[:'public_key']
90
+ else
91
+ self.public_key = nil
92
+ end
93
+
94
+ if attributes.key?(:'address_id')
95
+ self.address_id = attributes[:'address_id']
96
+ else
97
+ self.address_id = nil
98
+ end
99
+ end
100
+
101
+ # Show invalid properties with the reasons. Usually used together with valid?
102
+ # @return Array for valid properties with the reasons
103
+ def list_invalid_properties
104
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
105
+ invalid_properties = Array.new
106
+ if @wallet_id.nil?
107
+ invalid_properties.push('invalid value for "wallet_id", wallet_id cannot be nil.')
108
+ end
109
+
110
+ if @network_id.nil?
111
+ invalid_properties.push('invalid value for "network_id", network_id cannot be nil.')
112
+ end
113
+
114
+ if @public_key.nil?
115
+ invalid_properties.push('invalid value for "public_key", public_key cannot be nil.')
116
+ end
117
+
118
+ if @address_id.nil?
119
+ invalid_properties.push('invalid value for "address_id", address_id cannot be nil.')
120
+ end
121
+
122
+ invalid_properties
123
+ end
124
+
125
+ # Check to see if the all the properties in the model are valid
126
+ # @return true if the model is valid
127
+ def valid?
128
+ warn '[DEPRECATED] the `valid?` method is obsolete'
129
+ return false if @wallet_id.nil?
130
+ return false if @network_id.nil?
131
+ return false if @public_key.nil?
132
+ return false if @address_id.nil?
133
+ true
134
+ end
135
+
136
+ # Checks equality by comparing each attribute.
137
+ # @param [Object] Object to be compared
138
+ def ==(o)
139
+ return true if self.equal?(o)
140
+ self.class == o.class &&
141
+ wallet_id == o.wallet_id &&
142
+ network_id == o.network_id &&
143
+ public_key == o.public_key &&
144
+ address_id == o.address_id
145
+ end
146
+
147
+ # @see the `==` method
148
+ # @param [Object] Object to be compared
149
+ def eql?(o)
150
+ self == o
151
+ end
152
+
153
+ # Calculates hash code according to all attributes.
154
+ # @return [Integer] Hash code
155
+ def hash
156
+ [wallet_id, network_id, public_key, address_id].hash
157
+ end
158
+
159
+ # Builds the object from hash
160
+ # @param [Hash] attributes Model attributes in the form of hash
161
+ # @return [Object] Returns the model itself
162
+ def self.build_from_hash(attributes)
163
+ return nil unless attributes.is_a?(Hash)
164
+ attributes = attributes.transform_keys(&:to_sym)
165
+ transformed_hash = {}
166
+ openapi_types.each_pair do |key, type|
167
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
168
+ transformed_hash["#{key}"] = nil
169
+ elsif type =~ /\AArray<(.*)>/i
170
+ # check to ensure the input is an array given that the attribute
171
+ # is documented as an array but the input is not
172
+ if attributes[attribute_map[key]].is_a?(Array)
173
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
174
+ end
175
+ elsif !attributes[attribute_map[key]].nil?
176
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
177
+ end
178
+ end
179
+ new(transformed_hash)
180
+ end
181
+
182
+ # Deserializes the data based on type
183
+ # @param string type Data type
184
+ # @param string value Value to be deserialized
185
+ # @return [Object] Deserialized data
186
+ def self._deserialize(type, value)
187
+ case type.to_sym
188
+ when :Time
189
+ Time.parse(value)
190
+ when :Date
191
+ Date.parse(value)
192
+ when :String
193
+ value.to_s
194
+ when :Integer
195
+ value.to_i
196
+ when :Float
197
+ value.to_f
198
+ when :Boolean
199
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
200
+ true
201
+ else
202
+ false
203
+ end
204
+ when :Object
205
+ # generic object (usually a Hash), return directly
206
+ value
207
+ when /\AArray<(?<inner_type>.+)>\z/
208
+ inner_type = Regexp.last_match[:inner_type]
209
+ value.map { |v| _deserialize(inner_type, v) }
210
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
211
+ k_type = Regexp.last_match[:k_type]
212
+ v_type = Regexp.last_match[:v_type]
213
+ {}.tap do |hash|
214
+ value.each do |k, v|
215
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
216
+ end
217
+ end
218
+ else # model
219
+ # models (e.g. Pet) or oneOf
220
+ klass = Coinbase::Client.const_get(type)
221
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
222
+ end
223
+ end
224
+
225
+ # Returns the string representation of the object
226
+ # @return [String] String presentation of the object
227
+ def to_s
228
+ to_hash.to_s
229
+ end
230
+
231
+ # to_body is an alias to to_hash (backward compatibility)
232
+ # @return [Hash] Returns the object in the form of hash
233
+ def to_body
234
+ to_hash
235
+ end
236
+
237
+ # Returns the object in the form of hash
238
+ # @return [Hash] Returns the object in the form of hash
239
+ def to_hash
240
+ hash = {}
241
+ self.class.attribute_map.each_pair do |attr, param|
242
+ value = self.send(attr)
243
+ if value.nil?
244
+ is_nullable = self.class.openapi_nullable.include?(attr)
245
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
246
+ end
247
+
248
+ hash[param] = _to_hash(value)
249
+ end
250
+ hash
251
+ end
252
+
253
+ # Outputs non-array value in the form of hash
254
+ # For object, use to_hash. Otherwise, just return the value
255
+ # @param [Object] value Any valid value
256
+ # @return [Hash] Returns the value in the form of hash
257
+ def _to_hash(value)
258
+ if value.is_a?(Array)
259
+ value.compact.map { |v| _to_hash(v) }
260
+ elsif value.is_a?(Hash)
261
+ {}.tap do |hash|
262
+ value.each { |k, v| hash[k] = _to_hash(v) }
263
+ end
264
+ elsif value.respond_to? :to_hash
265
+ value.to_hash
266
+ else
267
+ value
268
+ end
269
+ end
270
+
271
+ end
272
+
273
+ end