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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/README.md +32 -2
- data/lib/patch_ruby/api/estimates_api.rb +287 -7
- data/lib/patch_ruby/api/orders_api.rb +11 -4
- data/lib/patch_ruby/api/projects_api.rb +2 -2
- data/lib/patch_ruby/api_client.rb +1 -1
- data/lib/patch_ruby/models/allocation.rb +1 -1
- data/lib/patch_ruby/models/create_air_shipping_estimate_request.rb +374 -0
- data/lib/patch_ruby/models/create_order_request.rb +16 -7
- data/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb +404 -0
- data/lib/patch_ruby/models/create_road_shipping_estimate_request.rb +507 -0
- data/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb +461 -0
- data/lib/patch_ruby/models/estimate.rb +1 -1
- data/lib/patch_ruby/models/order.rb +20 -7
- data/lib/patch_ruby/models/order_issued_to.rb +242 -0
- data/lib/patch_ruby/models/place_order_request.rb +228 -0
- data/lib/patch_ruby/models/project.rb +2 -2
- data/lib/patch_ruby/version.rb +1 -1
- data/lib/patch_ruby.rb +6 -0
- data/spec/integration/estimates_spec.rb +151 -0
- data/spec/integration/orders_spec.rb +34 -0
- data/spec/integration/projects_spec.rb +2 -2
- metadata +31 -25
@@ -0,0 +1,404 @@
|
|
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 CreateRailShippingEstimateRequest
|
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 :fuel_type
|
31
|
+
|
32
|
+
attr_accessor :freight_mass_g
|
33
|
+
|
34
|
+
attr_accessor :emissions_scope
|
35
|
+
|
36
|
+
attr_accessor :project_id
|
37
|
+
|
38
|
+
attr_accessor :create_order
|
39
|
+
|
40
|
+
class EnumAttributeValidator
|
41
|
+
attr_reader :datatype
|
42
|
+
attr_reader :allowable_values
|
43
|
+
|
44
|
+
def initialize(datatype, allowable_values)
|
45
|
+
@allowable_values = allowable_values.map do |value|
|
46
|
+
case datatype.to_s
|
47
|
+
when /Integer/i
|
48
|
+
value.to_i
|
49
|
+
when /Float/i
|
50
|
+
value.to_f
|
51
|
+
else
|
52
|
+
value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid?(value)
|
58
|
+
!value || allowable_values.include?(value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
63
|
+
def self.attribute_map
|
64
|
+
{
|
65
|
+
:'destination_country_code' => :'destination_country_code',
|
66
|
+
:'destination_locode' => :'destination_locode',
|
67
|
+
:'destination_postal_code' => :'destination_postal_code',
|
68
|
+
:'origin_country_code' => :'origin_country_code',
|
69
|
+
:'origin_locode' => :'origin_locode',
|
70
|
+
:'origin_postal_code' => :'origin_postal_code',
|
71
|
+
:'fuel_type' => :'fuel_type',
|
72
|
+
:'freight_mass_g' => :'freight_mass_g',
|
73
|
+
:'emissions_scope' => :'emissions_scope',
|
74
|
+
:'project_id' => :'project_id',
|
75
|
+
:'create_order' => :'create_order'
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns all the JSON keys this model knows about
|
80
|
+
def self.acceptable_attributes
|
81
|
+
attribute_map.values
|
82
|
+
end
|
83
|
+
|
84
|
+
# Attribute type mapping.
|
85
|
+
def self.openapi_types
|
86
|
+
{
|
87
|
+
:'destination_country_code' => :'String',
|
88
|
+
:'destination_locode' => :'String',
|
89
|
+
:'destination_postal_code' => :'String',
|
90
|
+
:'origin_country_code' => :'String',
|
91
|
+
:'origin_locode' => :'String',
|
92
|
+
:'origin_postal_code' => :'String',
|
93
|
+
:'fuel_type' => :'String',
|
94
|
+
:'freight_mass_g' => :'Integer',
|
95
|
+
:'emissions_scope' => :'String',
|
96
|
+
:'project_id' => :'String',
|
97
|
+
:'create_order' => :'Boolean'
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
# List of attributes with nullable: true
|
102
|
+
def self.openapi_nullable
|
103
|
+
Set.new([
|
104
|
+
:'destination_country_code',
|
105
|
+
:'destination_locode',
|
106
|
+
:'destination_postal_code',
|
107
|
+
:'origin_country_code',
|
108
|
+
:'origin_locode',
|
109
|
+
:'origin_postal_code',
|
110
|
+
:'fuel_type',
|
111
|
+
:'emissions_scope',
|
112
|
+
:'project_id',
|
113
|
+
:'create_order'
|
114
|
+
])
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
# Allows models with corresponding API classes to delegate API operations to those API classes
|
119
|
+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
|
120
|
+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
|
121
|
+
def self.method_missing(message, *args, &block)
|
122
|
+
if Object.const_defined?('Patch::CreateRailShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateRailShippingEstimateRequestsApi::OPERATIONS.include?(message)
|
123
|
+
Patch::CreateRailShippingEstimateRequestsApi.new.send(message, *args)
|
124
|
+
else
|
125
|
+
super
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Initializes the object
|
130
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
131
|
+
def initialize(attributes = {})
|
132
|
+
if (!attributes.is_a?(Hash))
|
133
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateRailShippingEstimateRequest` initialize method"
|
134
|
+
end
|
135
|
+
|
136
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
137
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
138
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
139
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateRailShippingEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
140
|
+
end
|
141
|
+
h[k.to_sym] = v
|
142
|
+
}
|
143
|
+
|
144
|
+
if attributes.key?(:'destination_country_code')
|
145
|
+
self.destination_country_code = attributes[:'destination_country_code']
|
146
|
+
end
|
147
|
+
|
148
|
+
if attributes.key?(:'destination_locode')
|
149
|
+
self.destination_locode = attributes[:'destination_locode']
|
150
|
+
end
|
151
|
+
|
152
|
+
if attributes.key?(:'destination_postal_code')
|
153
|
+
self.destination_postal_code = attributes[:'destination_postal_code']
|
154
|
+
end
|
155
|
+
|
156
|
+
if attributes.key?(:'origin_country_code')
|
157
|
+
self.origin_country_code = attributes[:'origin_country_code']
|
158
|
+
end
|
159
|
+
|
160
|
+
if attributes.key?(:'origin_locode')
|
161
|
+
self.origin_locode = attributes[:'origin_locode']
|
162
|
+
end
|
163
|
+
|
164
|
+
if attributes.key?(:'origin_postal_code')
|
165
|
+
self.origin_postal_code = attributes[:'origin_postal_code']
|
166
|
+
end
|
167
|
+
|
168
|
+
if attributes.key?(:'fuel_type')
|
169
|
+
self.fuel_type = attributes[:'fuel_type']
|
170
|
+
else
|
171
|
+
self.fuel_type = 'default'
|
172
|
+
end
|
173
|
+
|
174
|
+
if attributes.key?(:'freight_mass_g')
|
175
|
+
self.freight_mass_g = attributes[:'freight_mass_g']
|
176
|
+
end
|
177
|
+
|
178
|
+
if attributes.key?(:'emissions_scope')
|
179
|
+
self.emissions_scope = attributes[:'emissions_scope']
|
180
|
+
else
|
181
|
+
self.emissions_scope = 'wtw'
|
182
|
+
end
|
183
|
+
|
184
|
+
if attributes.key?(:'project_id')
|
185
|
+
self.project_id = attributes[:'project_id']
|
186
|
+
end
|
187
|
+
|
188
|
+
if attributes.key?(:'create_order')
|
189
|
+
self.create_order = attributes[:'create_order']
|
190
|
+
else
|
191
|
+
self.create_order = false
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
196
|
+
# @return Array for valid properties with the reasons
|
197
|
+
def list_invalid_properties
|
198
|
+
invalid_properties = Array.new
|
199
|
+
if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
|
200
|
+
invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.')
|
201
|
+
end
|
202
|
+
|
203
|
+
if !@freight_mass_g.nil? && @freight_mass_g < 0
|
204
|
+
invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.')
|
205
|
+
end
|
206
|
+
|
207
|
+
invalid_properties
|
208
|
+
end
|
209
|
+
|
210
|
+
# Check to see if the all the properties in the model are valid
|
211
|
+
# @return true if the model is valid
|
212
|
+
def valid?
|
213
|
+
fuel_type_validator = EnumAttributeValidator.new('String', ["default", "diesel", "elec"])
|
214
|
+
return false unless fuel_type_validator.valid?(@fuel_type)
|
215
|
+
return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
|
216
|
+
return false if !@freight_mass_g.nil? && @freight_mass_g < 0
|
217
|
+
emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
|
218
|
+
return false unless emissions_scope_validator.valid?(@emissions_scope)
|
219
|
+
true
|
220
|
+
end
|
221
|
+
|
222
|
+
# Custom attribute writer method checking allowed values (enum).
|
223
|
+
# @param [Object] fuel_type Object to be assigned
|
224
|
+
def fuel_type=(fuel_type)
|
225
|
+
validator = EnumAttributeValidator.new('String', ["default", "diesel", "elec"])
|
226
|
+
unless validator.valid?(fuel_type)
|
227
|
+
fail ArgumentError, "invalid value for \"fuel_type\", must be one of #{validator.allowable_values}."
|
228
|
+
end
|
229
|
+
@fuel_type = fuel_type
|
230
|
+
end
|
231
|
+
|
232
|
+
# Custom attribute writer method with validation
|
233
|
+
# @param [Object] freight_mass_g Value to be assigned
|
234
|
+
def freight_mass_g=(freight_mass_g)
|
235
|
+
if !freight_mass_g.nil? && freight_mass_g > 2000000000
|
236
|
+
fail ArgumentError, '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
|
+
fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.'
|
241
|
+
end
|
242
|
+
|
243
|
+
@freight_mass_g = freight_mass_g
|
244
|
+
end
|
245
|
+
|
246
|
+
# Custom attribute writer method checking allowed values (enum).
|
247
|
+
# @param [Object] emissions_scope Object to be assigned
|
248
|
+
def emissions_scope=(emissions_scope)
|
249
|
+
validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
|
250
|
+
unless validator.valid?(emissions_scope)
|
251
|
+
fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}."
|
252
|
+
end
|
253
|
+
@emissions_scope = emissions_scope
|
254
|
+
end
|
255
|
+
|
256
|
+
# Checks equality by comparing each attribute.
|
257
|
+
# @param [Object] Object to be compared
|
258
|
+
def ==(o)
|
259
|
+
return true if self.equal?(o)
|
260
|
+
self.class == o.class &&
|
261
|
+
destination_country_code == o.destination_country_code &&
|
262
|
+
destination_locode == o.destination_locode &&
|
263
|
+
destination_postal_code == o.destination_postal_code &&
|
264
|
+
origin_country_code == o.origin_country_code &&
|
265
|
+
origin_locode == o.origin_locode &&
|
266
|
+
origin_postal_code == o.origin_postal_code &&
|
267
|
+
fuel_type == o.fuel_type &&
|
268
|
+
freight_mass_g == o.freight_mass_g &&
|
269
|
+
emissions_scope == o.emissions_scope &&
|
270
|
+
project_id == o.project_id &&
|
271
|
+
create_order == o.create_order
|
272
|
+
end
|
273
|
+
|
274
|
+
# @see the `==` method
|
275
|
+
# @param [Object] Object to be compared
|
276
|
+
def eql?(o)
|
277
|
+
self == o
|
278
|
+
end
|
279
|
+
|
280
|
+
# Calculates hash code according to all attributes.
|
281
|
+
# @return [Integer] Hash code
|
282
|
+
def hash
|
283
|
+
[destination_country_code, destination_locode, destination_postal_code, origin_country_code, origin_locode, origin_postal_code, fuel_type, freight_mass_g, emissions_scope, project_id, create_order].hash
|
284
|
+
end
|
285
|
+
|
286
|
+
# Builds the object from hash
|
287
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
288
|
+
# @return [Object] Returns the model itself
|
289
|
+
def self.build_from_hash(attributes)
|
290
|
+
new.build_from_hash(attributes)
|
291
|
+
end
|
292
|
+
|
293
|
+
# Builds the object from hash
|
294
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
295
|
+
# @return [Object] Returns the model itself
|
296
|
+
def build_from_hash(attributes)
|
297
|
+
return nil unless attributes.is_a?(Hash)
|
298
|
+
self.class.openapi_types.each_pair do |key, type|
|
299
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
300
|
+
self.send("#{key}=", nil)
|
301
|
+
elsif type =~ /\AArray<(.*)>/i
|
302
|
+
# check to ensure the input is an array given that the attribute
|
303
|
+
# is documented as an array but the input is not
|
304
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
305
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
306
|
+
end
|
307
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
308
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
self
|
313
|
+
end
|
314
|
+
|
315
|
+
# Deserializes the data based on type
|
316
|
+
# @param string type Data type
|
317
|
+
# @param string value Value to be deserialized
|
318
|
+
# @return [Object] Deserialized data
|
319
|
+
def _deserialize(type, value)
|
320
|
+
case type.to_sym
|
321
|
+
when :Time
|
322
|
+
Time.parse(value)
|
323
|
+
when :Date
|
324
|
+
Date.parse(value)
|
325
|
+
when :String
|
326
|
+
value.to_s
|
327
|
+
when :Integer
|
328
|
+
value.to_i
|
329
|
+
when :Float
|
330
|
+
value.to_f
|
331
|
+
when :Boolean
|
332
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
333
|
+
true
|
334
|
+
else
|
335
|
+
false
|
336
|
+
end
|
337
|
+
when :Object
|
338
|
+
# generic object (usually a Hash), return directly
|
339
|
+
value
|
340
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
341
|
+
inner_type = Regexp.last_match[:inner_type]
|
342
|
+
value.map { |v| _deserialize(inner_type, v) }
|
343
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
344
|
+
k_type = Regexp.last_match[:k_type]
|
345
|
+
v_type = Regexp.last_match[:v_type]
|
346
|
+
{}.tap do |hash|
|
347
|
+
value.each do |k, v|
|
348
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
else # model
|
352
|
+
# models (e.g. Pet) or oneOf
|
353
|
+
klass = Patch.const_get(type)
|
354
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
# Returns the string representation of the object
|
359
|
+
# @return [String] String presentation of the object
|
360
|
+
def to_s
|
361
|
+
to_hash.to_s
|
362
|
+
end
|
363
|
+
|
364
|
+
# to_body is an alias to to_hash (backward compatibility)
|
365
|
+
# @return [Hash] Returns the object in the form of hash
|
366
|
+
def to_body
|
367
|
+
to_hash
|
368
|
+
end
|
369
|
+
|
370
|
+
# Returns the object in the form of hash
|
371
|
+
# @return [Hash] Returns the object in the form of hash
|
372
|
+
def to_hash
|
373
|
+
hash = {}
|
374
|
+
self.class.attribute_map.each_pair do |attr, param|
|
375
|
+
value = self.send(attr)
|
376
|
+
if value.nil?
|
377
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
378
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
379
|
+
end
|
380
|
+
|
381
|
+
hash[param] = _to_hash(value)
|
382
|
+
end
|
383
|
+
hash
|
384
|
+
end
|
385
|
+
|
386
|
+
# Outputs non-array value in the form of hash
|
387
|
+
# For object, use to_hash. Otherwise, just return the value
|
388
|
+
# @param [Object] value Any valid value
|
389
|
+
# @return [Hash] Returns the value in the form of hash
|
390
|
+
def _to_hash(value)
|
391
|
+
if value.is_a?(Array)
|
392
|
+
value.compact.map { |v| _to_hash(v) }
|
393
|
+
elsif value.is_a?(Hash)
|
394
|
+
{}.tap do |hash|
|
395
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
396
|
+
end
|
397
|
+
elsif value.respond_to? :to_hash
|
398
|
+
value.to_hash
|
399
|
+
else
|
400
|
+
value
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|