patch_ruby 1.20.0 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ 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
27
  # A boolean indicating if this order is a production or test mode order.
@@ -30,13 +30,28 @@ module Patch
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,9 @@ 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
+
51
69
  class EnumAttributeValidator
52
70
  attr_reader :datatype
53
71
  attr_reader :allowable_values
@@ -78,12 +96,18 @@ module Patch
78
96
  :'mass_g' => :'mass_g',
79
97
  :'production' => :'production',
80
98
  :'state' => :'state',
99
+ :'amount' => :'amount',
100
+ :'unit' => :'unit',
101
+ :'price' => :'price',
102
+ :'patch_fee' => :'patch_fee',
103
+ :'currency' => :'currency',
81
104
  :'allocation_state' => :'allocation_state',
82
105
  :'price_cents_usd' => :'price_cents_usd',
83
106
  :'patch_fee_cents_usd' => :'patch_fee_cents_usd',
84
107
  :'allocations' => :'allocations',
85
108
  :'registry_url' => :'registry_url',
86
- :'metadata' => :'metadata'
109
+ :'metadata' => :'metadata',
110
+ :'inventory' => :'inventory'
87
111
  }
88
112
  end
89
113
 
@@ -100,12 +124,18 @@ module Patch
100
124
  :'mass_g' => :'Integer',
101
125
  :'production' => :'Boolean',
102
126
  :'state' => :'String',
127
+ :'amount' => :'Integer',
128
+ :'unit' => :'String',
129
+ :'price' => :'Integer',
130
+ :'patch_fee' => :'Integer',
131
+ :'currency' => :'String',
103
132
  :'allocation_state' => :'String',
104
133
  :'price_cents_usd' => :'Integer',
105
134
  :'patch_fee_cents_usd' => :'Integer',
106
135
  :'allocations' => :'Array<Allocation>',
107
136
  :'registry_url' => :'String',
108
- :'metadata' => :'Object'
137
+ :'metadata' => :'Object',
138
+ :'inventory' => :'Array<OrderInventory>'
109
139
  }
110
140
  end
111
141
 
@@ -164,6 +194,26 @@ module Patch
164
194
  self.state = attributes[:'state']
165
195
  end
166
196
 
197
+ if attributes.key?(:'amount')
198
+ self.amount = attributes[:'amount']
199
+ end
200
+
201
+ if attributes.key?(:'unit')
202
+ self.unit = attributes[:'unit']
203
+ end
204
+
205
+ if attributes.key?(:'price')
206
+ self.price = attributes[:'price']
207
+ end
208
+
209
+ if attributes.key?(:'patch_fee')
210
+ self.patch_fee = attributes[:'patch_fee']
211
+ end
212
+
213
+ if attributes.key?(:'currency')
214
+ self.currency = attributes[:'currency']
215
+ end
216
+
167
217
  if attributes.key?(:'allocation_state')
168
218
  self.allocation_state = attributes[:'allocation_state']
169
219
  end
@@ -189,6 +239,12 @@ module Patch
189
239
  if attributes.key?(:'metadata')
190
240
  self.metadata = attributes[:'metadata']
191
241
  end
242
+
243
+ if attributes.key?(:'inventory')
244
+ if (value = attributes[:'inventory']).is_a?(Array)
245
+ self.inventory = value
246
+ end
247
+ end
192
248
  end
193
249
 
194
250
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -219,6 +275,34 @@ module Patch
219
275
  invalid_properties.push('invalid value for "state", state cannot be nil.')
220
276
  end
221
277
 
278
+ if @amount.nil?
279
+ invalid_properties.push('invalid value for "amount", amount cannot be nil.')
280
+ end
281
+
282
+ if @amount > 100000000000
283
+ invalid_properties.push('invalid value for "amount", must be smaller than or equal to 100000000000.')
284
+ end
285
+
286
+ if @amount < 0
287
+ invalid_properties.push('invalid value for "amount", must be greater than or equal to 0.')
288
+ end
289
+
290
+ if @unit.nil?
291
+ invalid_properties.push('invalid value for "unit", unit cannot be nil.')
292
+ end
293
+
294
+ if @price.nil?
295
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
296
+ end
297
+
298
+ if @patch_fee.nil?
299
+ invalid_properties.push('invalid value for "patch_fee", patch_fee cannot be nil.')
300
+ end
301
+
302
+ if @currency.nil?
303
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
304
+ end
305
+
222
306
  if @allocation_state.nil?
223
307
  invalid_properties.push('invalid value for "allocation_state", allocation_state cannot be nil.')
224
308
  end
@@ -241,6 +325,13 @@ module Patch
241
325
  return false if @state.nil?
242
326
  state_validator = EnumAttributeValidator.new('String', ["draft", "placed", "processing", "complete", "cancelled"])
243
327
  return false unless state_validator.valid?(@state)
328
+ return false if @amount.nil?
329
+ return false if @amount > 100000000000
330
+ return false if @amount < 0
331
+ return false if @unit.nil?
332
+ return false if @price.nil?
333
+ return false if @patch_fee.nil?
334
+ return false if @currency.nil?
244
335
  return false if @allocation_state.nil?
245
336
  allocation_state_validator = EnumAttributeValidator.new('String', ["pending", "allocated"])
246
337
  return false unless allocation_state_validator.valid?(@allocation_state)
@@ -276,6 +367,24 @@ module Patch
276
367
  @state = state
277
368
  end
278
369
 
370
+ # Custom attribute writer method with validation
371
+ # @param [Object] amount Value to be assigned
372
+ def amount=(amount)
373
+ if amount.nil?
374
+ fail ArgumentError, 'amount cannot be nil'
375
+ end
376
+
377
+ if amount > 100000000000
378
+ fail ArgumentError, 'invalid value for "amount", must be smaller than or equal to 100000000000.'
379
+ end
380
+
381
+ if amount < 0
382
+ fail ArgumentError, 'invalid value for "amount", must be greater than or equal to 0.'
383
+ end
384
+
385
+ @amount = amount
386
+ end
387
+
279
388
  # Custom attribute writer method checking allowed values (enum).
280
389
  # @param [Object] allocation_state Object to be assigned
281
390
  def allocation_state=(allocation_state)
@@ -296,12 +405,18 @@ module Patch
296
405
  mass_g == o.mass_g &&
297
406
  production == o.production &&
298
407
  state == o.state &&
408
+ amount == o.amount &&
409
+ unit == o.unit &&
410
+ price == o.price &&
411
+ patch_fee == o.patch_fee &&
412
+ currency == o.currency &&
299
413
  allocation_state == o.allocation_state &&
300
414
  price_cents_usd == o.price_cents_usd &&
301
415
  patch_fee_cents_usd == o.patch_fee_cents_usd &&
302
416
  allocations == o.allocations &&
303
417
  registry_url == o.registry_url &&
304
- metadata == o.metadata
418
+ metadata == o.metadata &&
419
+ inventory == o.inventory
305
420
  end
306
421
 
307
422
  # @see the `==` method
@@ -313,7 +428,7 @@ module Patch
313
428
  # Calculates hash code according to all attributes.
314
429
  # @return [Integer] Hash code
315
430
  def hash
316
- [id, created_at, mass_g, production, state, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, registry_url, metadata].hash
431
+ [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].hash
317
432
  end
318
433
 
319
434
  # 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