patch_ruby 1.22.0 → 1.24.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,507 @@
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 CreateRoadShippingEstimateRequest
18
+ attr_accessor :destination_country_code
19
+
20
+ attr_accessor :destination_locode
21
+
22
+ attr_accessor :destination_postal_code
23
+
24
+ attr_accessor :origin_country_code
25
+
26
+ attr_accessor :origin_locode
27
+
28
+ attr_accessor :origin_postal_code
29
+
30
+ attr_accessor :cargo_type
31
+
32
+ attr_accessor :container_size_code
33
+
34
+ attr_accessor :emissions_scope
35
+
36
+ attr_accessor :freight_mass_g
37
+
38
+ attr_accessor :fuel_type
39
+
40
+ attr_accessor :number_of_containers
41
+
42
+ attr_accessor :truck_weight_t
43
+
44
+ attr_accessor :project_id
45
+
46
+ attr_accessor :create_order
47
+
48
+ class EnumAttributeValidator
49
+ attr_reader :datatype
50
+ attr_reader :allowable_values
51
+
52
+ def initialize(datatype, allowable_values)
53
+ @allowable_values = allowable_values.map do |value|
54
+ case datatype.to_s
55
+ when /Integer/i
56
+ value.to_i
57
+ when /Float/i
58
+ value.to_f
59
+ else
60
+ value
61
+ end
62
+ end
63
+ end
64
+
65
+ def valid?(value)
66
+ !value || allowable_values.include?(value)
67
+ end
68
+ end
69
+
70
+ # Attribute mapping from ruby-style variable name to JSON key.
71
+ def self.attribute_map
72
+ {
73
+ :'destination_country_code' => :'destination_country_code',
74
+ :'destination_locode' => :'destination_locode',
75
+ :'destination_postal_code' => :'destination_postal_code',
76
+ :'origin_country_code' => :'origin_country_code',
77
+ :'origin_locode' => :'origin_locode',
78
+ :'origin_postal_code' => :'origin_postal_code',
79
+ :'cargo_type' => :'cargo_type',
80
+ :'container_size_code' => :'container_size_code',
81
+ :'emissions_scope' => :'emissions_scope',
82
+ :'freight_mass_g' => :'freight_mass_g',
83
+ :'fuel_type' => :'fuel_type',
84
+ :'number_of_containers' => :'number_of_containers',
85
+ :'truck_weight_t' => :'truck_weight_t',
86
+ :'project_id' => :'project_id',
87
+ :'create_order' => :'create_order'
88
+ }
89
+ end
90
+
91
+ # Returns all the JSON keys this model knows about
92
+ def self.acceptable_attributes
93
+ attribute_map.values
94
+ end
95
+
96
+ # Attribute type mapping.
97
+ def self.openapi_types
98
+ {
99
+ :'destination_country_code' => :'String',
100
+ :'destination_locode' => :'String',
101
+ :'destination_postal_code' => :'String',
102
+ :'origin_country_code' => :'String',
103
+ :'origin_locode' => :'String',
104
+ :'origin_postal_code' => :'String',
105
+ :'cargo_type' => :'String',
106
+ :'container_size_code' => :'String',
107
+ :'emissions_scope' => :'String',
108
+ :'freight_mass_g' => :'Integer',
109
+ :'fuel_type' => :'String',
110
+ :'number_of_containers' => :'Integer',
111
+ :'truck_weight_t' => :'Integer',
112
+ :'project_id' => :'String',
113
+ :'create_order' => :'Boolean'
114
+ }
115
+ end
116
+
117
+ # List of attributes with nullable: true
118
+ def self.openapi_nullable
119
+ Set.new([
120
+ :'destination_country_code',
121
+ :'destination_locode',
122
+ :'destination_postal_code',
123
+ :'origin_country_code',
124
+ :'origin_locode',
125
+ :'origin_postal_code',
126
+ :'emissions_scope',
127
+ :'fuel_type',
128
+ :'number_of_containers',
129
+ :'truck_weight_t',
130
+ :'project_id',
131
+ :'create_order'
132
+ ])
133
+ end
134
+
135
+
136
+ # Allows models with corresponding API classes to delegate API operations to those API classes
137
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
138
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
139
+ def self.method_missing(message, *args, &block)
140
+ if Object.const_defined?('Patch::CreateRoadShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateRoadShippingEstimateRequestsApi::OPERATIONS.include?(message)
141
+ Patch::CreateRoadShippingEstimateRequestsApi.new.send(message, *args)
142
+ else
143
+ super
144
+ end
145
+ end
146
+
147
+ # Initializes the object
148
+ # @param [Hash] attributes Model attributes in the form of hash
149
+ def initialize(attributes = {})
150
+ if (!attributes.is_a?(Hash))
151
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateRoadShippingEstimateRequest` initialize method"
152
+ end
153
+
154
+ # check to see if the attribute exists and convert string to symbol for hash key
155
+ attributes = attributes.each_with_object({}) { |(k, v), h|
156
+ if (!self.class.attribute_map.key?(k.to_sym))
157
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateRoadShippingEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
158
+ end
159
+ h[k.to_sym] = v
160
+ }
161
+
162
+ if attributes.key?(:'destination_country_code')
163
+ self.destination_country_code = attributes[:'destination_country_code']
164
+ end
165
+
166
+ if attributes.key?(:'destination_locode')
167
+ self.destination_locode = attributes[:'destination_locode']
168
+ end
169
+
170
+ if attributes.key?(:'destination_postal_code')
171
+ self.destination_postal_code = attributes[:'destination_postal_code']
172
+ end
173
+
174
+ if attributes.key?(:'origin_country_code')
175
+ self.origin_country_code = attributes[:'origin_country_code']
176
+ end
177
+
178
+ if attributes.key?(:'origin_locode')
179
+ self.origin_locode = attributes[:'origin_locode']
180
+ end
181
+
182
+ if attributes.key?(:'origin_postal_code')
183
+ self.origin_postal_code = attributes[:'origin_postal_code']
184
+ end
185
+
186
+ if attributes.key?(:'cargo_type')
187
+ self.cargo_type = attributes[:'cargo_type']
188
+ else
189
+ self.cargo_type = 'average_mixed'
190
+ end
191
+
192
+ if attributes.key?(:'container_size_code')
193
+ self.container_size_code = attributes[:'container_size_code']
194
+ end
195
+
196
+ if attributes.key?(:'emissions_scope')
197
+ self.emissions_scope = attributes[:'emissions_scope']
198
+ else
199
+ self.emissions_scope = 'wtw'
200
+ end
201
+
202
+ if attributes.key?(:'freight_mass_g')
203
+ self.freight_mass_g = attributes[:'freight_mass_g']
204
+ end
205
+
206
+ if attributes.key?(:'fuel_type')
207
+ self.fuel_type = attributes[:'fuel_type']
208
+ else
209
+ self.fuel_type = 'diesel'
210
+ end
211
+
212
+ if attributes.key?(:'number_of_containers')
213
+ self.number_of_containers = attributes[:'number_of_containers']
214
+ end
215
+
216
+ if attributes.key?(:'truck_weight_t')
217
+ self.truck_weight_t = attributes[:'truck_weight_t']
218
+ end
219
+
220
+ if attributes.key?(:'project_id')
221
+ self.project_id = attributes[:'project_id']
222
+ end
223
+
224
+ if attributes.key?(:'create_order')
225
+ self.create_order = attributes[:'create_order']
226
+ else
227
+ self.create_order = false
228
+ end
229
+ end
230
+
231
+ # Show invalid properties with the reasons. Usually used together with valid?
232
+ # @return Array for valid properties with the reasons
233
+ def list_invalid_properties
234
+ invalid_properties = Array.new
235
+ if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
236
+ invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.')
237
+ end
238
+
239
+ if !@freight_mass_g.nil? && @freight_mass_g < 0
240
+ invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.')
241
+ end
242
+
243
+ if !@number_of_containers.nil? && @number_of_containers < 0
244
+ invalid_properties.push('invalid value for "number_of_containers", must be greater than or equal to 0.')
245
+ end
246
+
247
+ if !@truck_weight_t.nil? && @truck_weight_t > 60
248
+ invalid_properties.push('invalid value for "truck_weight_t", must be smaller than or equal to 60.')
249
+ end
250
+
251
+ if !@truck_weight_t.nil? && @truck_weight_t < 0
252
+ invalid_properties.push('invalid value for "truck_weight_t", must be greater than or equal to 0.')
253
+ end
254
+
255
+ invalid_properties
256
+ end
257
+
258
+ # Check to see if the all the properties in the model are valid
259
+ # @return true if the model is valid
260
+ def valid?
261
+ cargo_type_validator = EnumAttributeValidator.new('String', ["average_mixed", "container"])
262
+ return false unless cargo_type_validator.valid?(@cargo_type)
263
+ container_size_code_validator = EnumAttributeValidator.new('String', ["20GP", "40GP", "22G1", "42G1", "40HC", "45G1"])
264
+ return false unless container_size_code_validator.valid?(@container_size_code)
265
+ emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
266
+ return false unless emissions_scope_validator.valid?(@emissions_scope)
267
+ return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
268
+ return false if !@freight_mass_g.nil? && @freight_mass_g < 0
269
+ fuel_type_validator = EnumAttributeValidator.new('String', ["cng", "diesel", "lng", "petrol"])
270
+ return false unless fuel_type_validator.valid?(@fuel_type)
271
+ return false if !@number_of_containers.nil? && @number_of_containers < 0
272
+ return false if !@truck_weight_t.nil? && @truck_weight_t > 60
273
+ return false if !@truck_weight_t.nil? && @truck_weight_t < 0
274
+ true
275
+ end
276
+
277
+ # Custom attribute writer method checking allowed values (enum).
278
+ # @param [Object] cargo_type Object to be assigned
279
+ def cargo_type=(cargo_type)
280
+ validator = EnumAttributeValidator.new('String', ["average_mixed", "container"])
281
+ unless validator.valid?(cargo_type)
282
+ fail ArgumentError, "invalid value for \"cargo_type\", must be one of #{validator.allowable_values}."
283
+ end
284
+ @cargo_type = cargo_type
285
+ end
286
+
287
+ # Custom attribute writer method checking allowed values (enum).
288
+ # @param [Object] container_size_code Object to be assigned
289
+ def container_size_code=(container_size_code)
290
+ validator = EnumAttributeValidator.new('String', ["20GP", "40GP", "22G1", "42G1", "40HC", "45G1"])
291
+ unless validator.valid?(container_size_code)
292
+ fail ArgumentError, "invalid value for \"container_size_code\", must be one of #{validator.allowable_values}."
293
+ end
294
+ @container_size_code = container_size_code
295
+ end
296
+
297
+ # Custom attribute writer method checking allowed values (enum).
298
+ # @param [Object] emissions_scope Object to be assigned
299
+ def emissions_scope=(emissions_scope)
300
+ validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
301
+ unless validator.valid?(emissions_scope)
302
+ fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}."
303
+ end
304
+ @emissions_scope = emissions_scope
305
+ end
306
+
307
+ # Custom attribute writer method with validation
308
+ # @param [Object] freight_mass_g Value to be assigned
309
+ def freight_mass_g=(freight_mass_g)
310
+ if !freight_mass_g.nil? && freight_mass_g > 2000000000
311
+ fail ArgumentError, 'invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.'
312
+ end
313
+
314
+ if !freight_mass_g.nil? && freight_mass_g < 0
315
+ fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.'
316
+ end
317
+
318
+ @freight_mass_g = freight_mass_g
319
+ end
320
+
321
+ # Custom attribute writer method checking allowed values (enum).
322
+ # @param [Object] fuel_type Object to be assigned
323
+ def fuel_type=(fuel_type)
324
+ validator = EnumAttributeValidator.new('String', ["cng", "diesel", "lng", "petrol"])
325
+ unless validator.valid?(fuel_type)
326
+ fail ArgumentError, "invalid value for \"fuel_type\", must be one of #{validator.allowable_values}."
327
+ end
328
+ @fuel_type = fuel_type
329
+ end
330
+
331
+ # Custom attribute writer method with validation
332
+ # @param [Object] number_of_containers Value to be assigned
333
+ def number_of_containers=(number_of_containers)
334
+ if !number_of_containers.nil? && number_of_containers < 0
335
+ fail ArgumentError, 'invalid value for "number_of_containers", must be greater than or equal to 0.'
336
+ end
337
+
338
+ @number_of_containers = number_of_containers
339
+ end
340
+
341
+ # Custom attribute writer method with validation
342
+ # @param [Object] truck_weight_t Value to be assigned
343
+ def truck_weight_t=(truck_weight_t)
344
+ if !truck_weight_t.nil? && truck_weight_t > 60
345
+ fail ArgumentError, 'invalid value for "truck_weight_t", must be smaller than or equal to 60.'
346
+ end
347
+
348
+ if !truck_weight_t.nil? && truck_weight_t < 0
349
+ fail ArgumentError, 'invalid value for "truck_weight_t", must be greater than or equal to 0.'
350
+ end
351
+
352
+ @truck_weight_t = truck_weight_t
353
+ end
354
+
355
+ # Checks equality by comparing each attribute.
356
+ # @param [Object] Object to be compared
357
+ def ==(o)
358
+ return true if self.equal?(o)
359
+ self.class == o.class &&
360
+ destination_country_code == o.destination_country_code &&
361
+ destination_locode == o.destination_locode &&
362
+ destination_postal_code == o.destination_postal_code &&
363
+ origin_country_code == o.origin_country_code &&
364
+ origin_locode == o.origin_locode &&
365
+ origin_postal_code == o.origin_postal_code &&
366
+ cargo_type == o.cargo_type &&
367
+ container_size_code == o.container_size_code &&
368
+ emissions_scope == o.emissions_scope &&
369
+ freight_mass_g == o.freight_mass_g &&
370
+ fuel_type == o.fuel_type &&
371
+ number_of_containers == o.number_of_containers &&
372
+ truck_weight_t == o.truck_weight_t &&
373
+ project_id == o.project_id &&
374
+ create_order == o.create_order
375
+ end
376
+
377
+ # @see the `==` method
378
+ # @param [Object] Object to be compared
379
+ def eql?(o)
380
+ self == o
381
+ end
382
+
383
+ # Calculates hash code according to all attributes.
384
+ # @return [Integer] Hash code
385
+ def hash
386
+ [destination_country_code, destination_locode, destination_postal_code, origin_country_code, origin_locode, origin_postal_code, cargo_type, container_size_code, emissions_scope, freight_mass_g, fuel_type, number_of_containers, truck_weight_t, project_id, create_order].hash
387
+ end
388
+
389
+ # Builds the object from hash
390
+ # @param [Hash] attributes Model attributes in the form of hash
391
+ # @return [Object] Returns the model itself
392
+ def self.build_from_hash(attributes)
393
+ new.build_from_hash(attributes)
394
+ end
395
+
396
+ # Builds the object from hash
397
+ # @param [Hash] attributes Model attributes in the form of hash
398
+ # @return [Object] Returns the model itself
399
+ def build_from_hash(attributes)
400
+ return nil unless attributes.is_a?(Hash)
401
+ self.class.openapi_types.each_pair do |key, type|
402
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
403
+ self.send("#{key}=", nil)
404
+ elsif type =~ /\AArray<(.*)>/i
405
+ # check to ensure the input is an array given that the attribute
406
+ # is documented as an array but the input is not
407
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
408
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
409
+ end
410
+ elsif !attributes[self.class.attribute_map[key]].nil?
411
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
412
+ end
413
+ end
414
+
415
+ self
416
+ end
417
+
418
+ # Deserializes the data based on type
419
+ # @param string type Data type
420
+ # @param string value Value to be deserialized
421
+ # @return [Object] Deserialized data
422
+ def _deserialize(type, value)
423
+ case type.to_sym
424
+ when :Time
425
+ Time.parse(value)
426
+ when :Date
427
+ Date.parse(value)
428
+ when :String
429
+ value.to_s
430
+ when :Integer
431
+ value.to_i
432
+ when :Float
433
+ value.to_f
434
+ when :Boolean
435
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
436
+ true
437
+ else
438
+ false
439
+ end
440
+ when :Object
441
+ # generic object (usually a Hash), return directly
442
+ value
443
+ when /\AArray<(?<inner_type>.+)>\z/
444
+ inner_type = Regexp.last_match[:inner_type]
445
+ value.map { |v| _deserialize(inner_type, v) }
446
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
447
+ k_type = Regexp.last_match[:k_type]
448
+ v_type = Regexp.last_match[:v_type]
449
+ {}.tap do |hash|
450
+ value.each do |k, v|
451
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
452
+ end
453
+ end
454
+ else # model
455
+ # models (e.g. Pet) or oneOf
456
+ klass = Patch.const_get(type)
457
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
458
+ end
459
+ end
460
+
461
+ # Returns the string representation of the object
462
+ # @return [String] String presentation of the object
463
+ def to_s
464
+ to_hash.to_s
465
+ end
466
+
467
+ # to_body is an alias to to_hash (backward compatibility)
468
+ # @return [Hash] Returns the object in the form of hash
469
+ def to_body
470
+ to_hash
471
+ end
472
+
473
+ # Returns the object in the form of hash
474
+ # @return [Hash] Returns the object in the form of hash
475
+ def to_hash
476
+ hash = {}
477
+ self.class.attribute_map.each_pair do |attr, param|
478
+ value = self.send(attr)
479
+ if value.nil?
480
+ is_nullable = self.class.openapi_nullable.include?(attr)
481
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
482
+ end
483
+
484
+ hash[param] = _to_hash(value)
485
+ end
486
+ hash
487
+ end
488
+
489
+ # Outputs non-array value in the form of hash
490
+ # For object, use to_hash. Otherwise, just return the value
491
+ # @param [Object] value Any valid value
492
+ # @return [Hash] Returns the value in the form of hash
493
+ def _to_hash(value)
494
+ if value.is_a?(Array)
495
+ value.compact.map { |v| _to_hash(v) }
496
+ elsif value.is_a?(Hash)
497
+ {}.tap do |hash|
498
+ value.each { |k, v| hash[k] = _to_hash(v) }
499
+ end
500
+ elsif value.respond_to? :to_hash
501
+ value.to_hash
502
+ else
503
+ value
504
+ end
505
+ end
506
+ end
507
+ end