nft_storage 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +68 -0
  4. data/README.md +118 -0
  5. data/Rakefile +10 -0
  6. data/docs/Deal.md +36 -0
  7. data/docs/DeleteResponse.md +18 -0
  8. data/docs/ErrorResponse.md +20 -0
  9. data/docs/ErrorResponseError.md +20 -0
  10. data/docs/ForbiddenErrorResponse.md +20 -0
  11. data/docs/ForbiddenErrorResponseError.md +20 -0
  12. data/docs/GetResponse.md +20 -0
  13. data/docs/Links.md +22 -0
  14. data/docs/LinksFile.md +20 -0
  15. data/docs/ListResponse.md +20 -0
  16. data/docs/NFT.md +32 -0
  17. data/docs/NFTStorageAPI.md +289 -0
  18. data/docs/Pin.md +26 -0
  19. data/docs/PinStatus.md +15 -0
  20. data/docs/UnauthorizedErrorResponse.md +20 -0
  21. data/docs/UnauthorizedErrorResponseError.md +20 -0
  22. data/docs/UploadResponse.md +20 -0
  23. data/git_push.sh +58 -0
  24. data/lib/nft_storage/api/nft_storage_api.rb +282 -0
  25. data/lib/nft_storage/api_client.rb +390 -0
  26. data/lib/nft_storage/api_error.rb +57 -0
  27. data/lib/nft_storage/configuration.rb +278 -0
  28. data/lib/nft_storage/models/deal.rb +364 -0
  29. data/lib/nft_storage/models/delete_response.rb +218 -0
  30. data/lib/nft_storage/models/error_response.rb +229 -0
  31. data/lib/nft_storage/models/error_response_error.rb +227 -0
  32. data/lib/nft_storage/models/forbidden_error_response.rb +229 -0
  33. data/lib/nft_storage/models/forbidden_error_response_error.rb +263 -0
  34. data/lib/nft_storage/models/get_response.rb +229 -0
  35. data/lib/nft_storage/models/links.rb +238 -0
  36. data/lib/nft_storage/models/links_file.rb +227 -0
  37. data/lib/nft_storage/models/list_response.rb +231 -0
  38. data/lib/nft_storage/models/nft.rb +329 -0
  39. data/lib/nft_storage/models/pin.rb +256 -0
  40. data/lib/nft_storage/models/pin_status.rb +39 -0
  41. data/lib/nft_storage/models/unauthorized_error_response.rb +229 -0
  42. data/lib/nft_storage/models/unauthorized_error_response_error.rb +231 -0
  43. data/lib/nft_storage/models/upload_response.rb +229 -0
  44. data/lib/nft_storage/version.rb +15 -0
  45. data/lib/nft_storage.rb +56 -0
  46. data/nft_storage.gemspec +38 -0
  47. data/spec/api/nft_storage_api_spec.rb +83 -0
  48. data/spec/api_client_spec.rb +226 -0
  49. data/spec/configuration_spec.rb +42 -0
  50. data/spec/models/deal_spec.rb +96 -0
  51. data/spec/models/delete_response_spec.rb +34 -0
  52. data/spec/models/error_response_error_spec.rb +40 -0
  53. data/spec/models/error_response_spec.rb +40 -0
  54. data/spec/models/forbidden_error_response_error_spec.rb +44 -0
  55. data/spec/models/forbidden_error_response_spec.rb +40 -0
  56. data/spec/models/get_response_spec.rb +40 -0
  57. data/spec/models/links_file_spec.rb +40 -0
  58. data/spec/models/links_spec.rb +46 -0
  59. data/spec/models/list_response_spec.rb +40 -0
  60. data/spec/models/nft_spec.rb +80 -0
  61. data/spec/models/pin_spec.rb +58 -0
  62. data/spec/models/pin_status_spec.rb +28 -0
  63. data/spec/models/unauthorized_error_response_error_spec.rb +40 -0
  64. data/spec/models/unauthorized_error_response_spec.rb +40 -0
  65. data/spec/models/upload_response_spec.rb +40 -0
  66. data/spec/spec_helper.rb +111 -0
  67. metadata +168 -0
@@ -0,0 +1,57 @@
1
+ =begin
2
+ #NFT Storage API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.1.1-SNAPSHOT
10
+
11
+ =end
12
+
13
+ module NFTStorage
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ end
36
+ end
37
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,278 @@
1
+ =begin
2
+ #NFT Storage API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.1.1-SNAPSHOT
10
+
11
+ =end
12
+
13
+ module NFTStorage
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
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
66
+ # details will be logged with `logger.debug` (see the `logger` attribute).
67
+ # Default to false.
68
+ #
69
+ # @return [true, false]
70
+ attr_accessor :debugging
71
+
72
+ # Defines the logger used for debugging.
73
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
74
+ #
75
+ # @return [#debug]
76
+ attr_accessor :logger
77
+
78
+ # Defines the temporary folder to store downloaded files
79
+ # (for API endpoints that have file response).
80
+ # Default to use `Tempfile`.
81
+ #
82
+ # @return [String]
83
+ attr_accessor :temp_folder_path
84
+
85
+ # The time limit for HTTP request in seconds.
86
+ # Default to 0 (never times out).
87
+ attr_accessor :timeout
88
+
89
+ # Set this to false to skip client side validation in the operation.
90
+ # Default to true.
91
+ # @return [true, false]
92
+ attr_accessor :client_side_validation
93
+
94
+ ### TLS/SSL setting
95
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
96
+ # Default to true.
97
+ #
98
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
99
+ #
100
+ # @return [true, false]
101
+ attr_accessor :verify_ssl
102
+
103
+ ### TLS/SSL setting
104
+ # Set this to false to skip verifying SSL host name
105
+ # Default to true.
106
+ #
107
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
108
+ #
109
+ # @return [true, false]
110
+ attr_accessor :verify_ssl_host
111
+
112
+ ### TLS/SSL setting
113
+ # Set this to customize the certificate file to verify the peer.
114
+ #
115
+ # @return [String] the path to the certificate file
116
+ #
117
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
118
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
119
+ attr_accessor :ssl_ca_cert
120
+
121
+ ### TLS/SSL setting
122
+ # Client certificate file (for client certificate)
123
+ attr_accessor :cert_file
124
+
125
+ ### TLS/SSL setting
126
+ # Client private key file (for client certificate)
127
+ attr_accessor :key_file
128
+
129
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
130
+ # Default to nil.
131
+ #
132
+ # @see The params_encoding option of Ethon. Related source code:
133
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
134
+ attr_accessor :params_encoding
135
+
136
+ attr_accessor :inject_format
137
+
138
+ attr_accessor :force_ending_format
139
+
140
+ def initialize
141
+ @scheme = 'https'
142
+ @host = 'api.nft.storage'
143
+ @base_path = ''
144
+ @server_index = 0
145
+ @server_operation_index = {}
146
+ @server_variables = {}
147
+ @server_operation_variables = {}
148
+ @api_key = {}
149
+ @api_key_prefix = {}
150
+ @timeout = 0
151
+ @client_side_validation = true
152
+ @verify_ssl = true
153
+ @verify_ssl_host = true
154
+ @params_encoding = nil
155
+ @cert_file = nil
156
+ @key_file = nil
157
+ @debugging = false
158
+ @inject_format = false
159
+ @force_ending_format = false
160
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
161
+
162
+ yield(self) if block_given?
163
+ end
164
+
165
+ # The default Configuration object.
166
+ def self.default
167
+ @@default ||= Configuration.new
168
+ end
169
+
170
+ def configure
171
+ yield(self) if block_given?
172
+ end
173
+
174
+ def scheme=(scheme)
175
+ # remove :// from scheme
176
+ @scheme = scheme.sub(/:\/\//, '')
177
+ end
178
+
179
+ def host=(host)
180
+ # remove http(s):// and anything after a slash
181
+ @host = host.sub(/https?:\/\//, '').split('/').first
182
+ end
183
+
184
+ def base_path=(base_path)
185
+ # Add leading and trailing slashes to base_path
186
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
187
+ @base_path = '' if @base_path == '/'
188
+ end
189
+
190
+ # Returns base URL for specified operation based on server settings
191
+ def base_url(operation = nil)
192
+ index = server_operation_index.fetch(operation, server_index)
193
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
194
+
195
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
196
+ end
197
+
198
+ # Gets API key (with prefix if set).
199
+ # @param [String] param_name the parameter name of API key auth
200
+ def api_key_with_prefix(param_name, param_alias = nil)
201
+ key = @api_key[param_name]
202
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
203
+ if @api_key_prefix[param_name]
204
+ "#{@api_key_prefix[param_name]} #{key}"
205
+ else
206
+ key
207
+ end
208
+ end
209
+
210
+ # Gets Basic Auth token string
211
+ def basic_auth_token
212
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
213
+ end
214
+
215
+ # Returns Auth Settings hash for api client.
216
+ def auth_settings
217
+ {
218
+ 'bearerAuth' =>
219
+ {
220
+ type: 'bearer',
221
+ in: 'header',
222
+ format: 'JWT',
223
+ key: 'Authorization',
224
+ value: "Bearer #{access_token}"
225
+ },
226
+ }
227
+ end
228
+
229
+ # Returns an array of Server setting
230
+ def server_settings
231
+ [
232
+ {
233
+ url: "https://api.nft.storage",
234
+ description: "No description provided",
235
+ }
236
+ ]
237
+ end
238
+
239
+ def operation_server_settings
240
+ {
241
+ }
242
+ end
243
+
244
+ # Returns URL based on server settings
245
+ #
246
+ # @param index array index of the server settings
247
+ # @param variables hash of variable and the corresponding value
248
+ def server_url(index, variables = {}, servers = nil)
249
+ servers = server_settings if servers == nil
250
+
251
+ # check array index out of bound
252
+ if (index < 0 || index >= servers.size)
253
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
254
+ end
255
+
256
+ server = servers[index]
257
+ url = server[:url]
258
+
259
+ return url unless server.key? :variables
260
+
261
+ # go through variable and assign a value
262
+ server[:variables].each do |name, variable|
263
+ if variables.key?(name)
264
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
265
+ url.gsub! "{" + name.to_s + "}", variables[name]
266
+ else
267
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
268
+ end
269
+ else
270
+ # use default value
271
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
272
+ end
273
+ end
274
+
275
+ url
276
+ end
277
+ end
278
+ end
@@ -0,0 +1,364 @@
1
+ =begin
2
+ #NFT Storage API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.1.1-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module NFTStorage
17
+ class Deal
18
+ attr_accessor :batch_root_cid
19
+
20
+ # This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: YYYY-MM-DDTHH:MM:SSZ.
21
+ attr_accessor :last_change
22
+
23
+ # Miner ID
24
+ attr_accessor :miner
25
+
26
+ # Filecoin network for this Deal
27
+ attr_accessor :network
28
+
29
+ # Piece CID string
30
+ attr_accessor :piece_cid
31
+
32
+ # Deal status
33
+ attr_accessor :status
34
+
35
+ # Deal status description.
36
+ attr_accessor :status_text
37
+
38
+ # Identifier for the deal stored on chain.
39
+ attr_accessor :chain_deal_id
40
+
41
+ # This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: YYYY-MM-DDTHH:MM:SSZ.
42
+ attr_accessor :deal_activation
43
+
44
+ # This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: YYYY-MM-DDTHH:MM:SSZ.
45
+ attr_accessor :deal_expiration
46
+
47
+ class EnumAttributeValidator
48
+ attr_reader :datatype
49
+ attr_reader :allowable_values
50
+
51
+ def initialize(datatype, allowable_values)
52
+ @allowable_values = allowable_values.map do |value|
53
+ case datatype.to_s
54
+ when /Integer/i
55
+ value.to_i
56
+ when /Float/i
57
+ value.to_f
58
+ else
59
+ value
60
+ end
61
+ end
62
+ end
63
+
64
+ def valid?(value)
65
+ !value || allowable_values.include?(value)
66
+ end
67
+ end
68
+
69
+ # Attribute mapping from ruby-style variable name to JSON key.
70
+ def self.attribute_map
71
+ {
72
+ :'batch_root_cid' => :'batchRootCid',
73
+ :'last_change' => :'lastChange',
74
+ :'miner' => :'miner',
75
+ :'network' => :'network',
76
+ :'piece_cid' => :'pieceCid',
77
+ :'status' => :'status',
78
+ :'status_text' => :'statusText',
79
+ :'chain_deal_id' => :'chainDealID',
80
+ :'deal_activation' => :'dealActivation',
81
+ :'deal_expiration' => :'dealExpiration'
82
+ }
83
+ end
84
+
85
+ # Returns all the JSON keys this model knows about
86
+ def self.acceptable_attributes
87
+ attribute_map.values
88
+ end
89
+
90
+ # Attribute type mapping.
91
+ def self.openapi_types
92
+ {
93
+ :'batch_root_cid' => :'String',
94
+ :'last_change' => :'String',
95
+ :'miner' => :'String',
96
+ :'network' => :'String',
97
+ :'piece_cid' => :'String',
98
+ :'status' => :'String',
99
+ :'status_text' => :'String',
100
+ :'chain_deal_id' => :'Float',
101
+ :'deal_activation' => :'String',
102
+ :'deal_expiration' => :'String'
103
+ }
104
+ end
105
+
106
+ # List of attributes with nullable: true
107
+ def self.openapi_nullable
108
+ Set.new([
109
+ ])
110
+ end
111
+
112
+ # Initializes the object
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ def initialize(attributes = {})
115
+ if (!attributes.is_a?(Hash))
116
+ fail ArgumentError, "The input argument (attributes) must be a hash in `NFTStorage::Deal` initialize method"
117
+ end
118
+
119
+ # check to see if the attribute exists and convert string to symbol for hash key
120
+ attributes = attributes.each_with_object({}) { |(k, v), h|
121
+ if (!self.class.attribute_map.key?(k.to_sym))
122
+ fail ArgumentError, "`#{k}` is not a valid attribute in `NFTStorage::Deal`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
123
+ end
124
+ h[k.to_sym] = v
125
+ }
126
+
127
+ if attributes.key?(:'batch_root_cid')
128
+ self.batch_root_cid = attributes[:'batch_root_cid']
129
+ end
130
+
131
+ if attributes.key?(:'last_change')
132
+ self.last_change = attributes[:'last_change']
133
+ end
134
+
135
+ if attributes.key?(:'miner')
136
+ self.miner = attributes[:'miner']
137
+ end
138
+
139
+ if attributes.key?(:'network')
140
+ self.network = attributes[:'network']
141
+ end
142
+
143
+ if attributes.key?(:'piece_cid')
144
+ self.piece_cid = attributes[:'piece_cid']
145
+ end
146
+
147
+ if attributes.key?(:'status')
148
+ self.status = attributes[:'status']
149
+ end
150
+
151
+ if attributes.key?(:'status_text')
152
+ self.status_text = attributes[:'status_text']
153
+ end
154
+
155
+ if attributes.key?(:'chain_deal_id')
156
+ self.chain_deal_id = attributes[:'chain_deal_id']
157
+ end
158
+
159
+ if attributes.key?(:'deal_activation')
160
+ self.deal_activation = attributes[:'deal_activation']
161
+ end
162
+
163
+ if attributes.key?(:'deal_expiration')
164
+ self.deal_expiration = attributes[:'deal_expiration']
165
+ end
166
+ end
167
+
168
+ # Show invalid properties with the reasons. Usually used together with valid?
169
+ # @return Array for valid properties with the reasons
170
+ def list_invalid_properties
171
+ invalid_properties = Array.new
172
+ if @last_change.nil?
173
+ invalid_properties.push('invalid value for "last_change", last_change cannot be nil.')
174
+ end
175
+
176
+ if @status.nil?
177
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
178
+ end
179
+
180
+ invalid_properties
181
+ end
182
+
183
+ # Check to see if the all the properties in the model are valid
184
+ # @return true if the model is valid
185
+ def valid?
186
+ return false if @last_change.nil?
187
+ network_validator = EnumAttributeValidator.new('String', ["nerpanet", "mainnet"])
188
+ return false unless network_validator.valid?(@network)
189
+ return false if @status.nil?
190
+ status_validator = EnumAttributeValidator.new('String', ["queued", "proposing", "accepted", "failed", "active", "published", "terminated"])
191
+ return false unless status_validator.valid?(@status)
192
+ true
193
+ end
194
+
195
+ # Custom attribute writer method checking allowed values (enum).
196
+ # @param [Object] network Object to be assigned
197
+ def network=(network)
198
+ validator = EnumAttributeValidator.new('String', ["nerpanet", "mainnet"])
199
+ unless validator.valid?(network)
200
+ fail ArgumentError, "invalid value for \"network\", must be one of #{validator.allowable_values}."
201
+ end
202
+ @network = network
203
+ end
204
+
205
+ # Custom attribute writer method checking allowed values (enum).
206
+ # @param [Object] status Object to be assigned
207
+ def status=(status)
208
+ validator = EnumAttributeValidator.new('String', ["queued", "proposing", "accepted", "failed", "active", "published", "terminated"])
209
+ unless validator.valid?(status)
210
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
211
+ end
212
+ @status = status
213
+ end
214
+
215
+ # Checks equality by comparing each attribute.
216
+ # @param [Object] Object to be compared
217
+ def ==(o)
218
+ return true if self.equal?(o)
219
+ self.class == o.class &&
220
+ batch_root_cid == o.batch_root_cid &&
221
+ last_change == o.last_change &&
222
+ miner == o.miner &&
223
+ network == o.network &&
224
+ piece_cid == o.piece_cid &&
225
+ status == o.status &&
226
+ status_text == o.status_text &&
227
+ chain_deal_id == o.chain_deal_id &&
228
+ deal_activation == o.deal_activation &&
229
+ deal_expiration == o.deal_expiration
230
+ end
231
+
232
+ # @see the `==` method
233
+ # @param [Object] Object to be compared
234
+ def eql?(o)
235
+ self == o
236
+ end
237
+
238
+ # Calculates hash code according to all attributes.
239
+ # @return [Integer] Hash code
240
+ def hash
241
+ [batch_root_cid, last_change, miner, network, piece_cid, status, status_text, chain_deal_id, deal_activation, deal_expiration].hash
242
+ end
243
+
244
+ # Builds the object from hash
245
+ # @param [Hash] attributes Model attributes in the form of hash
246
+ # @return [Object] Returns the model itself
247
+ def self.build_from_hash(attributes)
248
+ new.build_from_hash(attributes)
249
+ end
250
+
251
+ # Builds the object from hash
252
+ # @param [Hash] attributes Model attributes in the form of hash
253
+ # @return [Object] Returns the model itself
254
+ def build_from_hash(attributes)
255
+ return nil unless attributes.is_a?(Hash)
256
+ self.class.openapi_types.each_pair do |key, type|
257
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
258
+ self.send("#{key}=", nil)
259
+ elsif type =~ /\AArray<(.*)>/i
260
+ # check to ensure the input is an array given that the attribute
261
+ # is documented as an array but the input is not
262
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
263
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
264
+ end
265
+ elsif !attributes[self.class.attribute_map[key]].nil?
266
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
267
+ end
268
+ end
269
+
270
+ self
271
+ end
272
+
273
+ # Deserializes the data based on type
274
+ # @param string type Data type
275
+ # @param string value Value to be deserialized
276
+ # @return [Object] Deserialized data
277
+ def _deserialize(type, value)
278
+ case type.to_sym
279
+ when :Time
280
+ Time.parse(value)
281
+ when :Date
282
+ Date.parse(value)
283
+ when :String
284
+ value.to_s
285
+ when :Integer
286
+ value.to_i
287
+ when :Float
288
+ value.to_f
289
+ when :Boolean
290
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
291
+ true
292
+ else
293
+ false
294
+ end
295
+ when :Object
296
+ # generic object (usually a Hash), return directly
297
+ value
298
+ when /\AArray<(?<inner_type>.+)>\z/
299
+ inner_type = Regexp.last_match[:inner_type]
300
+ value.map { |v| _deserialize(inner_type, v) }
301
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
302
+ k_type = Regexp.last_match[:k_type]
303
+ v_type = Regexp.last_match[:v_type]
304
+ {}.tap do |hash|
305
+ value.each do |k, v|
306
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
307
+ end
308
+ end
309
+ else # model
310
+ # models (e.g. Pet) or oneOf
311
+ klass = NFTStorage.const_get(type)
312
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
313
+ end
314
+ end
315
+
316
+ # Returns the string representation of the object
317
+ # @return [String] String presentation of the object
318
+ def to_s
319
+ to_hash.to_s
320
+ end
321
+
322
+ # to_body is an alias to to_hash (backward compatibility)
323
+ # @return [Hash] Returns the object in the form of hash
324
+ def to_body
325
+ to_hash
326
+ end
327
+
328
+ # Returns the object in the form of hash
329
+ # @return [Hash] Returns the object in the form of hash
330
+ def to_hash
331
+ hash = {}
332
+ self.class.attribute_map.each_pair do |attr, param|
333
+ value = self.send(attr)
334
+ if value.nil?
335
+ is_nullable = self.class.openapi_nullable.include?(attr)
336
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
337
+ end
338
+
339
+ hash[param] = _to_hash(value)
340
+ end
341
+ hash
342
+ end
343
+
344
+ # Outputs non-array value in the form of hash
345
+ # For object, use to_hash. Otherwise, just return the value
346
+ # @param [Object] value Any valid value
347
+ # @return [Hash] Returns the value in the form of hash
348
+ def _to_hash(value)
349
+ if value.is_a?(Array)
350
+ value.compact.map { |v| _to_hash(v) }
351
+ elsif value.is_a?(Hash)
352
+ {}.tap do |hash|
353
+ value.each { |k, v| hash[k] = _to_hash(v) }
354
+ end
355
+ elsif value.respond_to? :to_hash
356
+ value.to_hash
357
+ else
358
+ value
359
+ end
360
+ end
361
+
362
+ end
363
+
364
+ end