patch_ruby 1.18.0 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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