patch_ruby 1.20.0 → 1.23.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,22 +21,37 @@ module Patch
21
21
  # The timestamp at which the order was created
22
22
  attr_accessor :created_at
23
23
 
24
- # The amount of carbon offsets in grams purchased through this order.
24
+ # DEPRECATED, use `amount` and `unit` fields instead. The amount of carbon offsets in grams purchased through this order.
25
25
  attr_accessor :mass_g
26
26
 
27
- # A boolean indicating if this order is a production or test mode order.
27
+ # A boolean indicating if this order is a production or demo mode order.
28
28
  attr_accessor :production
29
29
 
30
30
  # The current state of the order.
31
31
  attr_accessor :state
32
32
 
33
+ # The amount in `unit`s purchased through this order.
34
+ attr_accessor :amount
35
+
36
+ # The unit of measurement (ie \"g\" or \"Wh\") for the `amount` ordered.
37
+ attr_accessor :unit
38
+
39
+ # The total price for the `amount` ordered. Prices are always represented in the smallest currency unit (ie cents for USD).
40
+ attr_accessor :price
41
+
42
+ # The Patch Fee for this order. Patch Fee is always represented in the smallest currency unit (ie cents for USD).
43
+ attr_accessor :patch_fee
44
+
45
+ # The currency code for the `price` and `patch_fee`.
46
+ attr_accessor :currency
47
+
33
48
  # DEPRECATED. Indicates if the order has been fully allocated to projects.
34
49
  attr_accessor :allocation_state
35
50
 
36
- # The total price in cents USD of the carbon offsets purchased through this order.
51
+ # DEPRECATED, use the `price` and `currency` fields instead. The total price in cents USD of the carbon offsets purchased through this order.
37
52
  attr_accessor :price_cents_usd
38
53
 
39
- # The Patch Fee in cents USD for this order.
54
+ # DEPRECATED, use the `patch_fee` and `currency` fields instead. The Patch Fee in cents USD for this order.
40
55
  attr_accessor :patch_fee_cents_usd
41
56
 
42
57
  # DEPRECATED. An array containing the inventory allocations for this order.
@@ -48,6 +63,11 @@ module Patch
48
63
  # An optional JSON object containing metadata for this order.
49
64
  attr_accessor :metadata
50
65
 
66
+ # An array containing the inventory allocated for this order. Inventory is grouped by project, vintage year, and price.
67
+ attr_accessor :inventory
68
+
69
+ attr_accessor :issued_to
70
+
51
71
  class EnumAttributeValidator
52
72
  attr_reader :datatype
53
73
  attr_reader :allowable_values
@@ -78,12 +98,19 @@ module Patch
78
98
  :'mass_g' => :'mass_g',
79
99
  :'production' => :'production',
80
100
  :'state' => :'state',
101
+ :'amount' => :'amount',
102
+ :'unit' => :'unit',
103
+ :'price' => :'price',
104
+ :'patch_fee' => :'patch_fee',
105
+ :'currency' => :'currency',
81
106
  :'allocation_state' => :'allocation_state',
82
107
  :'price_cents_usd' => :'price_cents_usd',
83
108
  :'patch_fee_cents_usd' => :'patch_fee_cents_usd',
84
109
  :'allocations' => :'allocations',
85
110
  :'registry_url' => :'registry_url',
86
- :'metadata' => :'metadata'
111
+ :'metadata' => :'metadata',
112
+ :'inventory' => :'inventory',
113
+ :'issued_to' => :'issued_to'
87
114
  }
88
115
  end
89
116
 
@@ -100,12 +127,19 @@ module Patch
100
127
  :'mass_g' => :'Integer',
101
128
  :'production' => :'Boolean',
102
129
  :'state' => :'String',
130
+ :'amount' => :'Integer',
131
+ :'unit' => :'String',
132
+ :'price' => :'Integer',
133
+ :'patch_fee' => :'Integer',
134
+ :'currency' => :'String',
103
135
  :'allocation_state' => :'String',
104
136
  :'price_cents_usd' => :'Integer',
105
137
  :'patch_fee_cents_usd' => :'Integer',
106
138
  :'allocations' => :'Array<Allocation>',
107
139
  :'registry_url' => :'String',
108
- :'metadata' => :'Object'
140
+ :'metadata' => :'Object',
141
+ :'inventory' => :'Array<OrderInventory>',
142
+ :'issued_to' => :'IssuedTo'
109
143
  }
110
144
  end
111
145
 
@@ -164,6 +198,26 @@ module Patch
164
198
  self.state = attributes[:'state']
165
199
  end
166
200
 
201
+ if attributes.key?(:'amount')
202
+ self.amount = attributes[:'amount']
203
+ end
204
+
205
+ if attributes.key?(:'unit')
206
+ self.unit = attributes[:'unit']
207
+ end
208
+
209
+ if attributes.key?(:'price')
210
+ self.price = attributes[:'price']
211
+ end
212
+
213
+ if attributes.key?(:'patch_fee')
214
+ self.patch_fee = attributes[:'patch_fee']
215
+ end
216
+
217
+ if attributes.key?(:'currency')
218
+ self.currency = attributes[:'currency']
219
+ end
220
+
167
221
  if attributes.key?(:'allocation_state')
168
222
  self.allocation_state = attributes[:'allocation_state']
169
223
  end
@@ -189,6 +243,16 @@ module Patch
189
243
  if attributes.key?(:'metadata')
190
244
  self.metadata = attributes[:'metadata']
191
245
  end
246
+
247
+ if attributes.key?(:'inventory')
248
+ if (value = attributes[:'inventory']).is_a?(Array)
249
+ self.inventory = value
250
+ end
251
+ end
252
+
253
+ if attributes.key?(:'issued_to')
254
+ self.issued_to = attributes[:'issued_to']
255
+ end
192
256
  end
193
257
 
194
258
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -219,6 +283,34 @@ module Patch
219
283
  invalid_properties.push('invalid value for "state", state cannot be nil.')
220
284
  end
221
285
 
286
+ if @amount.nil?
287
+ invalid_properties.push('invalid value for "amount", amount cannot be nil.')
288
+ end
289
+
290
+ if @amount > 100000000000
291
+ invalid_properties.push('invalid value for "amount", must be smaller than or equal to 100000000000.')
292
+ end
293
+
294
+ if @amount < 0
295
+ invalid_properties.push('invalid value for "amount", must be greater than or equal to 0.')
296
+ end
297
+
298
+ if @unit.nil?
299
+ invalid_properties.push('invalid value for "unit", unit cannot be nil.')
300
+ end
301
+
302
+ if @price.nil?
303
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
304
+ end
305
+
306
+ if @patch_fee.nil?
307
+ invalid_properties.push('invalid value for "patch_fee", patch_fee cannot be nil.')
308
+ end
309
+
310
+ if @currency.nil?
311
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
312
+ end
313
+
222
314
  if @allocation_state.nil?
223
315
  invalid_properties.push('invalid value for "allocation_state", allocation_state cannot be nil.')
224
316
  end
@@ -241,6 +333,13 @@ module Patch
241
333
  return false if @state.nil?
242
334
  state_validator = EnumAttributeValidator.new('String', ["draft", "placed", "processing", "complete", "cancelled"])
243
335
  return false unless state_validator.valid?(@state)
336
+ return false if @amount.nil?
337
+ return false if @amount > 100000000000
338
+ return false if @amount < 0
339
+ return false if @unit.nil?
340
+ return false if @price.nil?
341
+ return false if @patch_fee.nil?
342
+ return false if @currency.nil?
244
343
  return false if @allocation_state.nil?
245
344
  allocation_state_validator = EnumAttributeValidator.new('String', ["pending", "allocated"])
246
345
  return false unless allocation_state_validator.valid?(@allocation_state)
@@ -276,6 +375,24 @@ module Patch
276
375
  @state = state
277
376
  end
278
377
 
378
+ # Custom attribute writer method with validation
379
+ # @param [Object] amount Value to be assigned
380
+ def amount=(amount)
381
+ if amount.nil?
382
+ fail ArgumentError, 'amount cannot be nil'
383
+ end
384
+
385
+ if amount > 100000000000
386
+ fail ArgumentError, 'invalid value for "amount", must be smaller than or equal to 100000000000.'
387
+ end
388
+
389
+ if amount < 0
390
+ fail ArgumentError, 'invalid value for "amount", must be greater than or equal to 0.'
391
+ end
392
+
393
+ @amount = amount
394
+ end
395
+
279
396
  # Custom attribute writer method checking allowed values (enum).
280
397
  # @param [Object] allocation_state Object to be assigned
281
398
  def allocation_state=(allocation_state)
@@ -296,12 +413,19 @@ module Patch
296
413
  mass_g == o.mass_g &&
297
414
  production == o.production &&
298
415
  state == o.state &&
416
+ amount == o.amount &&
417
+ unit == o.unit &&
418
+ price == o.price &&
419
+ patch_fee == o.patch_fee &&
420
+ currency == o.currency &&
299
421
  allocation_state == o.allocation_state &&
300
422
  price_cents_usd == o.price_cents_usd &&
301
423
  patch_fee_cents_usd == o.patch_fee_cents_usd &&
302
424
  allocations == o.allocations &&
303
425
  registry_url == o.registry_url &&
304
- metadata == o.metadata
426
+ metadata == o.metadata &&
427
+ inventory == o.inventory &&
428
+ issued_to == o.issued_to
305
429
  end
306
430
 
307
431
  # @see the `==` method
@@ -313,7 +437,7 @@ module Patch
313
437
  # Calculates hash code according to all attributes.
314
438
  # @return [Integer] Hash code
315
439
  def hash
316
- [id, created_at, mass_g, production, state, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, registry_url, metadata].hash
440
+ [id, created_at, mass_g, production, state, amount, unit, price, patch_fee, currency, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, registry_url, metadata, inventory, issued_to].hash
317
441
  end
318
442
 
319
443
  # Builds the object from hash
@@ -0,0 +1,312 @@
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 OrderInventory
18
+ # An object containing information about the project associated with the inventory allocated.
19
+ attr_accessor :project
20
+
21
+ # The year in which the climate impacts of the project occurred, or will occur.
22
+ attr_accessor :vintage_year
23
+
24
+ # The amount ordered for the given project and vintage year.
25
+ attr_accessor :amount
26
+
27
+ # The unit of measurement (ie \"g\" or \"Wh\") for the `amount` ordered for the given project and vintage year.
28
+ attr_accessor :unit
29
+
30
+ # The price for the given amount ordered for the given project and vintage year. Does not include any Patch fee. Prices are always represented in the smallest currency unit (ie cents for USD).
31
+ attr_accessor :price
32
+
33
+ # The currency code for the `price`.
34
+ attr_accessor :currency
35
+
36
+ # Attribute mapping from ruby-style variable name to JSON key.
37
+ def self.attribute_map
38
+ {
39
+ :'project' => :'project',
40
+ :'vintage_year' => :'vintage_year',
41
+ :'amount' => :'amount',
42
+ :'unit' => :'unit',
43
+ :'price' => :'price',
44
+ :'currency' => :'currency'
45
+ }
46
+ end
47
+
48
+ # Returns all the JSON keys this model knows about
49
+ def self.acceptable_attributes
50
+ attribute_map.values
51
+ end
52
+
53
+ # Attribute type mapping.
54
+ def self.openapi_types
55
+ {
56
+ :'project' => :'OrderInventoryProject',
57
+ :'vintage_year' => :'Integer',
58
+ :'amount' => :'Integer',
59
+ :'unit' => :'String',
60
+ :'price' => :'Integer',
61
+ :'currency' => :'String'
62
+ }
63
+ end
64
+
65
+ # List of attributes with nullable: true
66
+ def self.openapi_nullable
67
+ Set.new([
68
+ ])
69
+ end
70
+
71
+
72
+ # Allows models with corresponding API classes to delegate API operations to those API classes
73
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
74
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
75
+ def self.method_missing(message, *args, &block)
76
+ if Object.const_defined?('Patch::OrderInventorysApi::OPERATIONS') && Patch::OrderInventorysApi::OPERATIONS.include?(message)
77
+ Patch::OrderInventorysApi.new.send(message, *args)
78
+ else
79
+ super
80
+ end
81
+ end
82
+
83
+ # Initializes the object
84
+ # @param [Hash] attributes Model attributes in the form of hash
85
+ def initialize(attributes = {})
86
+ if (!attributes.is_a?(Hash))
87
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::OrderInventory` initialize method"
88
+ end
89
+
90
+ # check to see if the attribute exists and convert string to symbol for hash key
91
+ attributes = attributes.each_with_object({}) { |(k, v), h|
92
+ if (!self.class.attribute_map.key?(k.to_sym))
93
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::OrderInventory`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
94
+ end
95
+ h[k.to_sym] = v
96
+ }
97
+
98
+ if attributes.key?(:'project')
99
+ if (value = attributes[:'project']).is_a?(Hash)
100
+ self.project = value
101
+ end
102
+ self.project = attributes[:'project']
103
+ end
104
+
105
+ if attributes.key?(:'vintage_year')
106
+ self.vintage_year = attributes[:'vintage_year']
107
+ end
108
+
109
+ if attributes.key?(:'amount')
110
+ self.amount = attributes[:'amount']
111
+ end
112
+
113
+ if attributes.key?(:'unit')
114
+ self.unit = attributes[:'unit']
115
+ end
116
+
117
+ if attributes.key?(:'price')
118
+ self.price = attributes[:'price']
119
+ end
120
+
121
+ if attributes.key?(:'currency')
122
+ self.currency = attributes[:'currency']
123
+ end
124
+ end
125
+
126
+ # Show invalid properties with the reasons. Usually used together with valid?
127
+ # @return Array for valid properties with the reasons
128
+ def list_invalid_properties
129
+ invalid_properties = Array.new
130
+ if @project.nil?
131
+ invalid_properties.push('invalid value for "project", project cannot be nil.')
132
+ end
133
+
134
+ if @vintage_year.nil?
135
+ invalid_properties.push('invalid value for "vintage_year", vintage_year cannot be nil.')
136
+ end
137
+
138
+ if @amount.nil?
139
+ invalid_properties.push('invalid value for "amount", amount cannot be nil.')
140
+ end
141
+
142
+ if @unit.nil?
143
+ invalid_properties.push('invalid value for "unit", unit cannot be nil.')
144
+ end
145
+
146
+ if @price.nil?
147
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
148
+ end
149
+
150
+ if @currency.nil?
151
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
152
+ end
153
+
154
+ invalid_properties
155
+ end
156
+
157
+ # Check to see if the all the properties in the model are valid
158
+ # @return true if the model is valid
159
+ def valid?
160
+ return false if @project.nil?
161
+ return false if @vintage_year.nil?
162
+ return false if @amount.nil?
163
+ return false if @unit.nil?
164
+ return false if @price.nil?
165
+ return false if @currency.nil?
166
+ true
167
+ end
168
+
169
+ # Checks equality by comparing each attribute.
170
+ # @param [Object] Object to be compared
171
+ def ==(o)
172
+ return true if self.equal?(o)
173
+ self.class == o.class &&
174
+ project == o.project &&
175
+ vintage_year == o.vintage_year &&
176
+ amount == o.amount &&
177
+ unit == o.unit &&
178
+ price == o.price &&
179
+ currency == o.currency
180
+ end
181
+
182
+ # @see the `==` method
183
+ # @param [Object] Object to be compared
184
+ def eql?(o)
185
+ self == o
186
+ end
187
+
188
+ # Calculates hash code according to all attributes.
189
+ # @return [Integer] Hash code
190
+ def hash
191
+ [project, vintage_year, amount, unit, price, currency].hash
192
+ end
193
+
194
+ # Builds the object from hash
195
+ # @param [Hash] attributes Model attributes in the form of hash
196
+ # @return [Object] Returns the model itself
197
+ def self.build_from_hash(attributes)
198
+ new.build_from_hash(attributes)
199
+ end
200
+
201
+ # Builds the object from hash
202
+ # @param [Hash] attributes Model attributes in the form of hash
203
+ # @return [Object] Returns the model itself
204
+ def build_from_hash(attributes)
205
+ return nil unless attributes.is_a?(Hash)
206
+ self.class.openapi_types.each_pair do |key, type|
207
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
208
+ self.send("#{key}=", nil)
209
+ elsif type =~ /\AArray<(.*)>/i
210
+ # check to ensure the input is an array given that the attribute
211
+ # is documented as an array but the input is not
212
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
213
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
214
+ end
215
+ elsif !attributes[self.class.attribute_map[key]].nil?
216
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
217
+ end
218
+ end
219
+
220
+ self
221
+ end
222
+
223
+ # Deserializes the data based on type
224
+ # @param string type Data type
225
+ # @param string value Value to be deserialized
226
+ # @return [Object] Deserialized data
227
+ def _deserialize(type, value)
228
+ case type.to_sym
229
+ when :Time
230
+ Time.parse(value)
231
+ when :Date
232
+ Date.parse(value)
233
+ when :String
234
+ value.to_s
235
+ when :Integer
236
+ value.to_i
237
+ when :Float
238
+ value.to_f
239
+ when :Boolean
240
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
241
+ true
242
+ else
243
+ false
244
+ end
245
+ when :Object
246
+ # generic object (usually a Hash), return directly
247
+ value
248
+ when /\AArray<(?<inner_type>.+)>\z/
249
+ inner_type = Regexp.last_match[:inner_type]
250
+ value.map { |v| _deserialize(inner_type, v) }
251
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
252
+ k_type = Regexp.last_match[:k_type]
253
+ v_type = Regexp.last_match[:v_type]
254
+ {}.tap do |hash|
255
+ value.each do |k, v|
256
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
257
+ end
258
+ end
259
+ else # model
260
+ # models (e.g. Pet) or oneOf
261
+ klass = Patch.const_get(type)
262
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
263
+ end
264
+ end
265
+
266
+ # Returns the string representation of the object
267
+ # @return [String] String presentation of the object
268
+ def to_s
269
+ to_hash.to_s
270
+ end
271
+
272
+ # to_body is an alias to to_hash (backward compatibility)
273
+ # @return [Hash] Returns the object in the form of hash
274
+ def to_body
275
+ to_hash
276
+ end
277
+
278
+ # Returns the object in the form of hash
279
+ # @return [Hash] Returns the object in the form of hash
280
+ def to_hash
281
+ hash = {}
282
+ self.class.attribute_map.each_pair do |attr, param|
283
+ value = self.send(attr)
284
+ if value.nil?
285
+ is_nullable = self.class.openapi_nullable.include?(attr)
286
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
287
+ end
288
+
289
+ hash[param] = _to_hash(value)
290
+ end
291
+ hash
292
+ end
293
+
294
+ # Outputs non-array value in the form of hash
295
+ # For object, use to_hash. Otherwise, just return the value
296
+ # @param [Object] value Any valid value
297
+ # @return [Hash] Returns the value in the form of hash
298
+ def _to_hash(value)
299
+ if value.is_a?(Array)
300
+ value.compact.map { |v| _to_hash(v) }
301
+ elsif value.is_a?(Hash)
302
+ {}.tap do |hash|
303
+ value.each { |k, v| hash[k] = _to_hash(v) }
304
+ end
305
+ elsif value.respond_to? :to_hash
306
+ value.to_hash
307
+ else
308
+ value
309
+ end
310
+ end
311
+ end
312
+ end