patch_ruby 1.19.0 → 1.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a90772be1e6d26b5b7ffef9d2f06f344a650e1c285f350dface3df5e019d3cf4
4
- data.tar.gz: 96e12b69d309e6083a1e0e10dcd2e66b44f6d86fa6c1c27bd407d4bac388a069
3
+ metadata.gz: 0eedef11df722bf4d3312666ad7fbfb2e965a4c8da613c41bfbaa960008c2f2d
4
+ data.tar.gz: 71128b74af6e96fc9743d36f63c7fdf6265f68a91b88cfb76730ae811cfcb867
5
5
  SHA512:
6
- metadata.gz: 7c1d0d76f771cdda09b4694697544007e14484462167846527917a3a28f9d327c70af5e4f24f8e2312c61cebe1927b9a8080f7a73cc9f85018483a8a664021db
7
- data.tar.gz: c4a2539ad216e42349dede7c98fdd4512f519d1b0820c2235e356d4a7772154007941bec55402a1383e8b8456664e1493ddb53341d8cfde60617b6e18198a784
6
+ metadata.gz: 6f5c0bf775d6cfae626fcd983957aaffb1fe8eb1de1b1b75f3a8aee53f6bdb5dfc0901d74e442ab324147e7970e6d673686735572d9c9be97c39c08c3fb48547
7
+ data.tar.gz: 06d6ff806473a398bbbdff44b0a232428311507f3d22c7140badaf6eaf1512d0d8a660f54efcba39b6147e770cb1b1ad783821c068b5a7581a653eca14bd0a76
data/CHANGELOG.md CHANGED
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.22.0] - 2022-05-16
9
+
10
+ ### Added
11
+
12
+ - Adds support for the `accept_language` option on `projects`, to add support for the `Accept-Language` header.
13
+
14
+ ## [1.21.0] - 2022-05-03
15
+
16
+ ### Added
17
+
18
+ - Adds optional `total_price` and `currency` field to `order` creation
19
+ - Adds optional `amount` and `unit` field to `order` creation
20
+ - Adds inventory to `project` responses
21
+ - Adds inventory to `order` responses
22
+
23
+ ### Changed
24
+
25
+ - Deprecates `mass_g` and `total_price_cents_usd` fields for create `order` requests
26
+ - Deprecates `average_price_per_tonne_cents_usd` and `remaining_mass_g` from `project` responses
27
+ - Deprecates `price_cents_usd`, `patch_fee_cents_usd`, and `mass_g` from `order` responses
28
+
29
+ ## [1.20.0] - 2022-04-18
30
+
31
+ ### Added
32
+
33
+ - Adds optional `vintage_year` field to `order` creation
34
+
8
35
  ## [1.19.0] - 2022-04-05
9
36
 
10
37
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_ruby (1.19.0)
4
+ patch_ruby (1.22.0)
5
5
  typhoeus (~> 1.0, >= 1.0.1)
6
6
 
7
7
  GEM
@@ -73,6 +73,8 @@ PLATFORMS
73
73
  arm64-darwin-20
74
74
  arm64-darwin-21
75
75
  x86_64-darwin-20
76
+ x86_64-darwin-21
77
+ x86_64-linux
76
78
 
77
79
  DEPENDENCIES
78
80
  factory_bot (~> 6.2)
data/README.md CHANGED
@@ -51,9 +51,9 @@ end
51
51
 
52
52
  ### Orders
53
53
 
54
- In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
54
+ In Patch, orders represent a purchase of carbon offsets or negative emissions by amount. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
55
55
 
56
- You can also create an order with a maximum desired price, and we'll allocate enough mass to
56
+ You can also create an order with a maximum desired price, and we'll allocate enough to
57
57
  fulfill the order for you.
58
58
 
59
59
  [API Reference](https://docs.patch.io/#/?id=orders)
@@ -62,23 +62,25 @@ fulfill the order for you.
62
62
 
63
63
  ```ruby
64
64
  # Create an order - you can create an order
65
- # providing either mass_g or total_price_cents_usd, but not both
65
+ # providing either amount (and unit) or total_price (and currency), but not both
66
66
 
67
- # Create order with mass
68
- mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
69
- Patch::Order.create_order(mass_g: mass)
67
+ # Create order with amount
68
+ amount = 1_000_000 # Pass in the amount in unit specified
69
+ unit = "g"
70
+ Patch::Order.create_order(amount: amount, unit: unit)
70
71
 
71
- # Create an order with maximum total price
72
- total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
73
- Patch::Order.create_order(total_price_cents_usd: total_price_cents_usd)
72
+ # Create an order with total price
73
+ total_price = 5_00 # Pass in the total price in smallest currency unit (ie cents for USD).
74
+ currency = "USD"
75
+ Patch::Order.create_order(total_price: total_price, currency: currency)
74
76
 
75
77
  ## You can also specify a project-id field (optional) to be used instead of the preferred one
76
78
  project_id = 'pro_test_1234' # Pass in the project's ID
77
- Patch::Order.create_order(mass_g: mass, project_id: project_id)
79
+ Patch::Order.create_order(amount: amount, unit: unit, project_id: project_id)
78
80
 
79
81
  ## Orders also accept a metadata field (optional)
80
82
  metadata = {user: "john doe"}
81
- Patch::Order.create_order(mass_g: mass, metadata: metadata)
83
+ Patch::Order.create_order(amount: amount, unit: unit, metadata: metadata)
82
84
 
83
85
  # Retrieve an order
84
86
  order_id = 'ord_test_1234' # Pass in the order's id
@@ -187,6 +189,15 @@ Patch::Project.retrieve_projects(type: type)
187
189
  # Retrieve a list of projects with at least 100 grams of available offsets
188
190
  minimum_available_mass = 100
189
191
  Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)
192
+
193
+ # Retrieve a project in a different language
194
+ # See http://docs.patch.test:3000/#/internationalization for more information and support
195
+ project_id = 'pro_test_1234'
196
+ Patch::Project.retrieve_project(project_id, accept_language: 'fr')
197
+
198
+ # Retrieve a list of projects in a different language
199
+ # See http://docs.patch.test:3000/#/internationalization for more information and support
200
+ Patch::Project.retrieve_projects(accept_language: 'fr')
190
201
  ```
191
202
  ## Contributing
192
203
 
@@ -28,6 +28,7 @@ module Patch
28
28
  # Retrieves a project available on Patch's platform.
29
29
  # @param id [String]
30
30
  # @param [Hash] opts the optional parameters
31
+ # @option opts [String] :accept_language
31
32
  # @return [ProjectResponse]
32
33
  def retrieve_project(id, opts = {})
33
34
 
@@ -39,6 +40,7 @@ module Patch
39
40
  # Retrieves a project available on Patch's platform.
40
41
  # @param id [String]
41
42
  # @param [Hash] opts the optional parameters
43
+ # @option opts [String] :accept_language
42
44
  # @return [Array<(ProjectResponse, Integer, Hash)>] ProjectResponse data, response status code and response headers
43
45
  def retrieve_project_with_http_info(id, opts = {})
44
46
  if @api_client.config.debugging
@@ -58,6 +60,7 @@ module Patch
58
60
  header_params = opts[:header_params] || {}
59
61
  # HTTP header 'Accept' (if needed)
60
62
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
63
+ header_params[:'Accept-Language'] = opts[:'accept_language'] if !opts[:'accept_language'].nil?
61
64
 
62
65
  # form parameters
63
66
  form_params = opts[:form_params] || {}
@@ -95,6 +98,7 @@ module Patch
95
98
  # @option opts [String] :country
96
99
  # @option opts [String] :type
97
100
  # @option opts [Integer] :minimum_available_mass
101
+ # @option opts [String] :accept_language
98
102
  # @return [ProjectListResponse]
99
103
  def retrieve_projects(opts = {})
100
104
 
@@ -109,6 +113,7 @@ module Patch
109
113
  # @option opts [String] :country
110
114
  # @option opts [String] :type
111
115
  # @option opts [Integer] :minimum_available_mass
116
+ # @option opts [String] :accept_language
112
117
  # @return [Array<(ProjectListResponse, Integer, Hash)>] ProjectListResponse data, response status code and response headers
113
118
  def retrieve_projects_with_http_info(opts = {})
114
119
  if @api_client.config.debugging
@@ -128,6 +133,7 @@ module Patch
128
133
  header_params = opts[:header_params] || {}
129
134
  # HTTP header 'Accept' (if needed)
130
135
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
136
+ header_params[:'Accept-Language'] = opts[:'accept_language'] if !opts[:'accept_language'].nil?
131
137
 
132
138
  # form parameters
133
139
  form_params = opts[:form_params] || {}
@@ -31,7 +31,7 @@ module Patch
31
31
  # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
32
  def initialize(config = Configuration.default)
33
33
  @config = config
34
- @user_agent = "patch-ruby/1.19.0"
34
+ @user_agent = "patch-ruby/1.22.0"
35
35
  @default_headers = {
36
36
  'Content-Type' => 'application/json',
37
37
  'User-Agent' => @user_agent
@@ -25,6 +25,16 @@ module Patch
25
25
 
26
26
  attr_accessor :state
27
27
 
28
+ attr_accessor :vintage_year
29
+
30
+ attr_accessor :total_price
31
+
32
+ attr_accessor :currency
33
+
34
+ attr_accessor :amount
35
+
36
+ attr_accessor :unit
37
+
28
38
  class EnumAttributeValidator
29
39
  attr_reader :datatype
30
40
  attr_reader :allowable_values
@@ -54,7 +64,12 @@ module Patch
54
64
  :'total_price_cents_usd' => :'total_price_cents_usd',
55
65
  :'project_id' => :'project_id',
56
66
  :'metadata' => :'metadata',
57
- :'state' => :'state'
67
+ :'state' => :'state',
68
+ :'vintage_year' => :'vintage_year',
69
+ :'total_price' => :'total_price',
70
+ :'currency' => :'currency',
71
+ :'amount' => :'amount',
72
+ :'unit' => :'unit'
58
73
  }
59
74
  end
60
75
 
@@ -70,13 +85,28 @@ module Patch
70
85
  :'total_price_cents_usd' => :'Integer',
71
86
  :'project_id' => :'String',
72
87
  :'metadata' => :'Object',
73
- :'state' => :'String'
88
+ :'state' => :'String',
89
+ :'vintage_year' => :'Integer',
90
+ :'total_price' => :'Integer',
91
+ :'currency' => :'String',
92
+ :'amount' => :'Integer',
93
+ :'unit' => :'String'
74
94
  }
75
95
  end
76
96
 
77
97
  # List of attributes with nullable: true
78
98
  def self.openapi_nullable
79
99
  Set.new([
100
+ :'mass_g',
101
+ :'total_price_cents_usd',
102
+ :'project_id',
103
+ :'metadata',
104
+ :'state',
105
+ :'vintage_year',
106
+ :'total_price',
107
+ :'currency',
108
+ :'amount',
109
+ :'unit'
80
110
  ])
81
111
  end
82
112
 
@@ -126,6 +156,26 @@ module Patch
126
156
  if attributes.key?(:'state')
127
157
  self.state = attributes[:'state']
128
158
  end
159
+
160
+ if attributes.key?(:'vintage_year')
161
+ self.vintage_year = attributes[:'vintage_year']
162
+ end
163
+
164
+ if attributes.key?(:'total_price')
165
+ self.total_price = attributes[:'total_price']
166
+ end
167
+
168
+ if attributes.key?(:'currency')
169
+ self.currency = attributes[:'currency']
170
+ end
171
+
172
+ if attributes.key?(:'amount')
173
+ self.amount = attributes[:'amount']
174
+ end
175
+
176
+ if attributes.key?(:'unit')
177
+ self.unit = attributes[:'unit']
178
+ end
129
179
  end
130
180
 
131
181
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -144,6 +194,26 @@ module Patch
144
194
  invalid_properties.push('invalid value for "total_price_cents_usd", must be greater than or equal to 1.')
145
195
  end
146
196
 
197
+ if !@vintage_year.nil? && @vintage_year > 2100
198
+ invalid_properties.push('invalid value for "vintage_year", must be smaller than or equal to 2100.')
199
+ end
200
+
201
+ if !@vintage_year.nil? && @vintage_year < 1900
202
+ invalid_properties.push('invalid value for "vintage_year", must be greater than or equal to 1900.')
203
+ end
204
+
205
+ if !@total_price.nil? && @total_price < 1
206
+ invalid_properties.push('invalid value for "total_price", must be greater than or equal to 1.')
207
+ end
208
+
209
+ if !@amount.nil? && @amount > 100000000000
210
+ invalid_properties.push('invalid value for "amount", must be smaller than or equal to 100000000000.')
211
+ end
212
+
213
+ if !@amount.nil? && @amount < 0
214
+ invalid_properties.push('invalid value for "amount", must be greater than or equal to 0.')
215
+ end
216
+
147
217
  invalid_properties
148
218
  end
149
219
 
@@ -155,6 +225,13 @@ module Patch
155
225
  return false if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
156
226
  state_validator = EnumAttributeValidator.new('String', ["draft", "placed"])
157
227
  return false unless state_validator.valid?(@state)
228
+ return false if !@vintage_year.nil? && @vintage_year > 2100
229
+ return false if !@vintage_year.nil? && @vintage_year < 1900
230
+ return false if !@total_price.nil? && @total_price < 1
231
+ return false if !@amount.nil? && @amount > 100000000000
232
+ return false if !@amount.nil? && @amount < 0
233
+ unit_validator = EnumAttributeValidator.new('String', ["g", "Wh"])
234
+ return false unless unit_validator.valid?(@unit)
158
235
  true
159
236
  end
160
237
 
@@ -192,6 +269,54 @@ module Patch
192
269
  @state = state
193
270
  end
194
271
 
272
+ # Custom attribute writer method with validation
273
+ # @param [Object] vintage_year Value to be assigned
274
+ def vintage_year=(vintage_year)
275
+ if !vintage_year.nil? && vintage_year > 2100
276
+ fail ArgumentError, 'invalid value for "vintage_year", must be smaller than or equal to 2100.'
277
+ end
278
+
279
+ if !vintage_year.nil? && vintage_year < 1900
280
+ fail ArgumentError, 'invalid value for "vintage_year", must be greater than or equal to 1900.'
281
+ end
282
+
283
+ @vintage_year = vintage_year
284
+ end
285
+
286
+ # Custom attribute writer method with validation
287
+ # @param [Object] total_price Value to be assigned
288
+ def total_price=(total_price)
289
+ if !total_price.nil? && total_price < 1
290
+ fail ArgumentError, 'invalid value for "total_price", must be greater than or equal to 1.'
291
+ end
292
+
293
+ @total_price = total_price
294
+ end
295
+
296
+ # Custom attribute writer method with validation
297
+ # @param [Object] amount Value to be assigned
298
+ def amount=(amount)
299
+ if !amount.nil? && amount > 100000000000
300
+ fail ArgumentError, 'invalid value for "amount", must be smaller than or equal to 100000000000.'
301
+ end
302
+
303
+ if !amount.nil? && amount < 0
304
+ fail ArgumentError, 'invalid value for "amount", must be greater than or equal to 0.'
305
+ end
306
+
307
+ @amount = amount
308
+ end
309
+
310
+ # Custom attribute writer method checking allowed values (enum).
311
+ # @param [Object] unit Object to be assigned
312
+ def unit=(unit)
313
+ validator = EnumAttributeValidator.new('String', ["g", "Wh"])
314
+ unless validator.valid?(unit)
315
+ fail ArgumentError, "invalid value for \"unit\", must be one of #{validator.allowable_values}."
316
+ end
317
+ @unit = unit
318
+ end
319
+
195
320
  # Checks equality by comparing each attribute.
196
321
  # @param [Object] Object to be compared
197
322
  def ==(o)
@@ -201,7 +326,12 @@ module Patch
201
326
  total_price_cents_usd == o.total_price_cents_usd &&
202
327
  project_id == o.project_id &&
203
328
  metadata == o.metadata &&
204
- state == o.state
329
+ state == o.state &&
330
+ vintage_year == o.vintage_year &&
331
+ total_price == o.total_price &&
332
+ currency == o.currency &&
333
+ amount == o.amount &&
334
+ unit == o.unit
205
335
  end
206
336
 
207
337
  # @see the `==` method
@@ -213,7 +343,7 @@ module Patch
213
343
  # Calculates hash code according to all attributes.
214
344
  # @return [Integer] Hash code
215
345
  def hash
216
- [mass_g, total_price_cents_usd, project_id, metadata, state].hash
346
+ [mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year, total_price, currency, amount, unit].hash
217
347
  end
218
348
 
219
349
  # Builds the object from hash
@@ -0,0 +1,294 @@
1
+ =begin
2
+ #Patch API V1
3
+
4
+ #The core API used to integrate with Patch's service
5
+
6
+ The version of the OpenAPI document: v1
7
+ Contact: engineering@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Patch
17
+ class Inventory
18
+ # The year in which the climate impacts of the project occurred, or will occur.
19
+ attr_accessor :vintage_year
20
+
21
+ # The amount available for this vintage year.
22
+ attr_accessor :amount_available
23
+
24
+ # The price per tonne (1,000,000 g) or MWh (1,000,000 Wh) of inventory. Prices are always represented in the smallest currency unit (ie cents for USD).
25
+ attr_accessor :price
26
+
27
+ # The currency code for `price`.
28
+ attr_accessor :currency
29
+
30
+ # The unit of measurement (ie \"g\" or \"Wh\") for `amount_available`.
31
+ attr_accessor :unit
32
+
33
+ # Attribute mapping from ruby-style variable name to JSON key.
34
+ def self.attribute_map
35
+ {
36
+ :'vintage_year' => :'vintage_year',
37
+ :'amount_available' => :'amount_available',
38
+ :'price' => :'price',
39
+ :'currency' => :'currency',
40
+ :'unit' => :'unit'
41
+ }
42
+ end
43
+
44
+ # Returns all the JSON keys this model knows about
45
+ def self.acceptable_attributes
46
+ attribute_map.values
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.openapi_types
51
+ {
52
+ :'vintage_year' => :'Integer',
53
+ :'amount_available' => :'Integer',
54
+ :'price' => :'Integer',
55
+ :'currency' => :'String',
56
+ :'unit' => :'String'
57
+ }
58
+ end
59
+
60
+ # List of attributes with nullable: true
61
+ def self.openapi_nullable
62
+ Set.new([
63
+ ])
64
+ end
65
+
66
+
67
+ # Allows models with corresponding API classes to delegate API operations to those API classes
68
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
69
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
70
+ def self.method_missing(message, *args, &block)
71
+ if Object.const_defined?('Patch::InventorysApi::OPERATIONS') && Patch::InventorysApi::OPERATIONS.include?(message)
72
+ Patch::InventorysApi.new.send(message, *args)
73
+ else
74
+ super
75
+ end
76
+ end
77
+
78
+ # Initializes the object
79
+ # @param [Hash] attributes Model attributes in the form of hash
80
+ def initialize(attributes = {})
81
+ if (!attributes.is_a?(Hash))
82
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::Inventory` initialize method"
83
+ end
84
+
85
+ # check to see if the attribute exists and convert string to symbol for hash key
86
+ attributes = attributes.each_with_object({}) { |(k, v), h|
87
+ if (!self.class.attribute_map.key?(k.to_sym))
88
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::Inventory`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
89
+ end
90
+ h[k.to_sym] = v
91
+ }
92
+
93
+ if attributes.key?(:'vintage_year')
94
+ self.vintage_year = attributes[:'vintage_year']
95
+ end
96
+
97
+ if attributes.key?(:'amount_available')
98
+ self.amount_available = attributes[:'amount_available']
99
+ end
100
+
101
+ if attributes.key?(:'price')
102
+ self.price = attributes[:'price']
103
+ end
104
+
105
+ if attributes.key?(:'currency')
106
+ self.currency = attributes[:'currency']
107
+ end
108
+
109
+ if attributes.key?(:'unit')
110
+ self.unit = attributes[:'unit']
111
+ end
112
+ end
113
+
114
+ # Show invalid properties with the reasons. Usually used together with valid?
115
+ # @return Array for valid properties with the reasons
116
+ def list_invalid_properties
117
+ invalid_properties = Array.new
118
+ if @vintage_year.nil?
119
+ invalid_properties.push('invalid value for "vintage_year", vintage_year cannot be nil.')
120
+ end
121
+
122
+ if @amount_available.nil?
123
+ invalid_properties.push('invalid value for "amount_available", amount_available cannot be nil.')
124
+ end
125
+
126
+ if @price.nil?
127
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
128
+ end
129
+
130
+ if @currency.nil?
131
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
132
+ end
133
+
134
+ if @unit.nil?
135
+ invalid_properties.push('invalid value for "unit", unit cannot be nil.')
136
+ end
137
+
138
+ invalid_properties
139
+ end
140
+
141
+ # Check to see if the all the properties in the model are valid
142
+ # @return true if the model is valid
143
+ def valid?
144
+ return false if @vintage_year.nil?
145
+ return false if @amount_available.nil?
146
+ return false if @price.nil?
147
+ return false if @currency.nil?
148
+ return false if @unit.nil?
149
+ true
150
+ end
151
+
152
+ # Checks equality by comparing each attribute.
153
+ # @param [Object] Object to be compared
154
+ def ==(o)
155
+ return true if self.equal?(o)
156
+ self.class == o.class &&
157
+ vintage_year == o.vintage_year &&
158
+ amount_available == o.amount_available &&
159
+ price == o.price &&
160
+ currency == o.currency &&
161
+ unit == o.unit
162
+ end
163
+
164
+ # @see the `==` method
165
+ # @param [Object] Object to be compared
166
+ def eql?(o)
167
+ self == o
168
+ end
169
+
170
+ # Calculates hash code according to all attributes.
171
+ # @return [Integer] Hash code
172
+ def hash
173
+ [vintage_year, amount_available, price, currency, unit].hash
174
+ end
175
+
176
+ # Builds the object from hash
177
+ # @param [Hash] attributes Model attributes in the form of hash
178
+ # @return [Object] Returns the model itself
179
+ def self.build_from_hash(attributes)
180
+ new.build_from_hash(attributes)
181
+ end
182
+
183
+ # Builds the object from hash
184
+ # @param [Hash] attributes Model attributes in the form of hash
185
+ # @return [Object] Returns the model itself
186
+ def build_from_hash(attributes)
187
+ return nil unless attributes.is_a?(Hash)
188
+ self.class.openapi_types.each_pair do |key, type|
189
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
190
+ self.send("#{key}=", nil)
191
+ elsif type =~ /\AArray<(.*)>/i
192
+ # check to ensure the input is an array given that the attribute
193
+ # is documented as an array but the input is not
194
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
195
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
196
+ end
197
+ elsif !attributes[self.class.attribute_map[key]].nil?
198
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
199
+ end
200
+ end
201
+
202
+ self
203
+ end
204
+
205
+ # Deserializes the data based on type
206
+ # @param string type Data type
207
+ # @param string value Value to be deserialized
208
+ # @return [Object] Deserialized data
209
+ def _deserialize(type, value)
210
+ case type.to_sym
211
+ when :Time
212
+ Time.parse(value)
213
+ when :Date
214
+ Date.parse(value)
215
+ when :String
216
+ value.to_s
217
+ when :Integer
218
+ value.to_i
219
+ when :Float
220
+ value.to_f
221
+ when :Boolean
222
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
223
+ true
224
+ else
225
+ false
226
+ end
227
+ when :Object
228
+ # generic object (usually a Hash), return directly
229
+ value
230
+ when /\AArray<(?<inner_type>.+)>\z/
231
+ inner_type = Regexp.last_match[:inner_type]
232
+ value.map { |v| _deserialize(inner_type, v) }
233
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
234
+ k_type = Regexp.last_match[:k_type]
235
+ v_type = Regexp.last_match[:v_type]
236
+ {}.tap do |hash|
237
+ value.each do |k, v|
238
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
239
+ end
240
+ end
241
+ else # model
242
+ # models (e.g. Pet) or oneOf
243
+ klass = Patch.const_get(type)
244
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
245
+ end
246
+ end
247
+
248
+ # Returns the string representation of the object
249
+ # @return [String] String presentation of the object
250
+ def to_s
251
+ to_hash.to_s
252
+ end
253
+
254
+ # to_body is an alias to to_hash (backward compatibility)
255
+ # @return [Hash] Returns the object in the form of hash
256
+ def to_body
257
+ to_hash
258
+ end
259
+
260
+ # Returns the object in the form of hash
261
+ # @return [Hash] Returns the object in the form of hash
262
+ def to_hash
263
+ hash = {}
264
+ self.class.attribute_map.each_pair do |attr, param|
265
+ value = self.send(attr)
266
+ if value.nil?
267
+ is_nullable = self.class.openapi_nullable.include?(attr)
268
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
269
+ end
270
+
271
+ hash[param] = _to_hash(value)
272
+ end
273
+ hash
274
+ end
275
+
276
+ # Outputs non-array value in the form of hash
277
+ # For object, use to_hash. Otherwise, just return the value
278
+ # @param [Object] value Any valid value
279
+ # @return [Hash] Returns the value in the form of hash
280
+ def _to_hash(value)
281
+ if value.is_a?(Array)
282
+ value.compact.map { |v| _to_hash(v) }
283
+ elsif value.is_a?(Hash)
284
+ {}.tap do |hash|
285
+ value.each { |k, v| hash[k] = _to_hash(v) }
286
+ end
287
+ elsif value.respond_to? :to_hash
288
+ value.to_hash
289
+ else
290
+ value
291
+ end
292
+ end
293
+ end
294
+ end