patch_ruby 1.10.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,326 @@
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: developers@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Patch
17
+ class CreateVehicleEstimateRequest
18
+ attr_accessor :distance_m
19
+
20
+ attr_accessor :make
21
+
22
+ attr_accessor :model
23
+
24
+ attr_accessor :year
25
+
26
+ attr_accessor :project_id
27
+
28
+ attr_accessor :create_order
29
+
30
+ # Attribute mapping from ruby-style variable name to JSON key.
31
+ def self.attribute_map
32
+ {
33
+ :'distance_m' => :'distance_m',
34
+ :'make' => :'make',
35
+ :'model' => :'model',
36
+ :'year' => :'year',
37
+ :'project_id' => :'project_id',
38
+ :'create_order' => :'create_order'
39
+ }
40
+ end
41
+
42
+ # Returns all the JSON keys this model knows about
43
+ def self.acceptable_attributes
44
+ attribute_map.values
45
+ end
46
+
47
+ # Attribute type mapping.
48
+ def self.openapi_types
49
+ {
50
+ :'distance_m' => :'Integer',
51
+ :'make' => :'String',
52
+ :'model' => :'String',
53
+ :'year' => :'Integer',
54
+ :'project_id' => :'String',
55
+ :'create_order' => :'Boolean'
56
+ }
57
+ end
58
+
59
+ # List of attributes with nullable: true
60
+ def self.openapi_nullable
61
+ Set.new([
62
+ :'make',
63
+ :'model',
64
+ :'year',
65
+ :'project_id',
66
+ :'create_order'
67
+ ])
68
+ end
69
+
70
+
71
+ # Allows models with corresponding API classes to delegate API operations to those API classes
72
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
73
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
74
+ def self.method_missing(message, *args, &block)
75
+ if Object.const_defined?('Patch::CreateVehicleEstimateRequestsApi::OPERATIONS') && Patch::CreateVehicleEstimateRequestsApi::OPERATIONS.include?(message)
76
+ Patch::CreateVehicleEstimateRequestsApi.new.send(message, *args)
77
+ else
78
+ super
79
+ end
80
+ end
81
+
82
+ # Initializes the object
83
+ # @param [Hash] attributes Model attributes in the form of hash
84
+ def initialize(attributes = {})
85
+ if (!attributes.is_a?(Hash))
86
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateVehicleEstimateRequest` initialize method"
87
+ end
88
+
89
+ # check to see if the attribute exists and convert string to symbol for hash key
90
+ attributes = attributes.each_with_object({}) { |(k, v), h|
91
+ if (!self.class.attribute_map.key?(k.to_sym))
92
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateVehicleEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
93
+ end
94
+ h[k.to_sym] = v
95
+ }
96
+
97
+ if attributes.key?(:'distance_m')
98
+ self.distance_m = attributes[:'distance_m']
99
+ end
100
+
101
+ if attributes.key?(:'make')
102
+ self.make = attributes[:'make']
103
+ end
104
+
105
+ if attributes.key?(:'model')
106
+ self.model = attributes[:'model']
107
+ end
108
+
109
+ if attributes.key?(:'year')
110
+ self.year = attributes[:'year']
111
+ end
112
+
113
+ if attributes.key?(:'project_id')
114
+ self.project_id = attributes[:'project_id']
115
+ end
116
+
117
+ if attributes.key?(:'create_order')
118
+ self.create_order = attributes[:'create_order']
119
+ end
120
+ end
121
+
122
+ # Show invalid properties with the reasons. Usually used together with valid?
123
+ # @return Array for valid properties with the reasons
124
+ def list_invalid_properties
125
+ invalid_properties = Array.new
126
+ if @distance_m.nil?
127
+ invalid_properties.push('invalid value for "distance_m", distance_m cannot be nil.')
128
+ end
129
+
130
+ if @distance_m > 400000000
131
+ invalid_properties.push('invalid value for "distance_m", must be smaller than or equal to 400000000.')
132
+ end
133
+
134
+ if @distance_m < 0
135
+ invalid_properties.push('invalid value for "distance_m", must be greater than or equal to 0.')
136
+ end
137
+
138
+ if !@year.nil? && @year < 1900
139
+ invalid_properties.push('invalid value for "year", must be greater than or equal to 1900.')
140
+ end
141
+
142
+ invalid_properties
143
+ end
144
+
145
+ # Check to see if the all the properties in the model are valid
146
+ # @return true if the model is valid
147
+ def valid?
148
+ return false if @distance_m.nil?
149
+ return false if @distance_m > 400000000
150
+ return false if @distance_m < 0
151
+ return false if !@year.nil? && @year < 1900
152
+ true
153
+ end
154
+
155
+ # Custom attribute writer method with validation
156
+ # @param [Object] distance_m Value to be assigned
157
+ def distance_m=(distance_m)
158
+ if distance_m.nil?
159
+ fail ArgumentError, 'distance_m cannot be nil'
160
+ end
161
+
162
+ if distance_m > 400000000
163
+ fail ArgumentError, 'invalid value for "distance_m", must be smaller than or equal to 400000000.'
164
+ end
165
+
166
+ if distance_m < 0
167
+ fail ArgumentError, 'invalid value for "distance_m", must be greater than or equal to 0.'
168
+ end
169
+
170
+ @distance_m = distance_m
171
+ end
172
+
173
+ # Custom attribute writer method with validation
174
+ # @param [Object] year Value to be assigned
175
+ def year=(year)
176
+ if !year.nil? && year < 1900
177
+ fail ArgumentError, 'invalid value for "year", must be greater than or equal to 1900.'
178
+ end
179
+
180
+ @year = year
181
+ end
182
+
183
+ # Checks equality by comparing each attribute.
184
+ # @param [Object] Object to be compared
185
+ def ==(o)
186
+ return true if self.equal?(o)
187
+ self.class == o.class &&
188
+ distance_m == o.distance_m &&
189
+ make == o.make &&
190
+ model == o.model &&
191
+ year == o.year &&
192
+ project_id == o.project_id &&
193
+ create_order == o.create_order
194
+ end
195
+
196
+ # @see the `==` method
197
+ # @param [Object] Object to be compared
198
+ def eql?(o)
199
+ self == o
200
+ end
201
+
202
+ # Calculates hash code according to all attributes.
203
+ # @return [Integer] Hash code
204
+ def hash
205
+ [distance_m, make, model, year, project_id, create_order].hash
206
+ end
207
+
208
+ # Builds the object from hash
209
+ # @param [Hash] attributes Model attributes in the form of hash
210
+ # @return [Object] Returns the model itself
211
+ def self.build_from_hash(attributes)
212
+ new.build_from_hash(attributes)
213
+ end
214
+
215
+ # Builds the object from hash
216
+ # @param [Hash] attributes Model attributes in the form of hash
217
+ # @return [Object] Returns the model itself
218
+ def build_from_hash(attributes)
219
+ return nil unless attributes.is_a?(Hash)
220
+ self.class.openapi_types.each_pair do |key, type|
221
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
222
+ self.send("#{key}=", nil)
223
+ elsif type =~ /\AArray<(.*)>/i
224
+ # check to ensure the input is an array given that the attribute
225
+ # is documented as an array but the input is not
226
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
227
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
228
+ end
229
+ elsif !attributes[self.class.attribute_map[key]].nil?
230
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
231
+ end
232
+ end
233
+
234
+ self
235
+ end
236
+
237
+ # Deserializes the data based on type
238
+ # @param string type Data type
239
+ # @param string value Value to be deserialized
240
+ # @return [Object] Deserialized data
241
+ def _deserialize(type, value)
242
+ case type.to_sym
243
+ when :Time
244
+ Time.parse(value)
245
+ when :Date
246
+ Date.parse(value)
247
+ when :String
248
+ value.to_s
249
+ when :Integer
250
+ value.to_i
251
+ when :Float
252
+ value.to_f
253
+ when :Boolean
254
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
255
+ true
256
+ else
257
+ false
258
+ end
259
+ when :Object
260
+ # generic object (usually a Hash), return directly
261
+ value
262
+ when /\AArray<(?<inner_type>.+)>\z/
263
+ inner_type = Regexp.last_match[:inner_type]
264
+ value.map { |v| _deserialize(inner_type, v) }
265
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
266
+ k_type = Regexp.last_match[:k_type]
267
+ v_type = Regexp.last_match[:v_type]
268
+ {}.tap do |hash|
269
+ value.each do |k, v|
270
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
271
+ end
272
+ end
273
+ else # model
274
+ # models (e.g. Pet) or oneOf
275
+ klass = Patch.const_get(type)
276
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
277
+ end
278
+ end
279
+
280
+ # Returns the string representation of the object
281
+ # @return [String] String presentation of the object
282
+ def to_s
283
+ to_hash.to_s
284
+ end
285
+
286
+ # to_body is an alias to to_hash (backward compatibility)
287
+ # @return [Hash] Returns the object in the form of hash
288
+ def to_body
289
+ to_hash
290
+ end
291
+
292
+ # Returns the object in the form of hash
293
+ # @return [Hash] Returns the object in the form of hash
294
+ def to_hash
295
+ hash = {}
296
+ self.class.attribute_map.each_pair do |attr, param|
297
+ value = self.send(attr)
298
+ if value.nil?
299
+ is_nullable = self.class.openapi_nullable.include?(attr)
300
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
301
+ end
302
+
303
+ hash[param] = _to_hash(value)
304
+ end
305
+ hash
306
+ end
307
+
308
+ # Outputs non-array value in the form of hash
309
+ # For object, use to_hash. Otherwise, just return the value
310
+ # @param [Object] value Any valid value
311
+ # @return [Hash] Returns the value in the form of hash
312
+ def _to_hash(value)
313
+ if value.is_a?(Array)
314
+ value.compact.map { |v| _to_hash(v) }
315
+ elsif value.is_a?(Hash)
316
+ {}.tap do |hash|
317
+ value.each { |k, v| hash[k] = _to_hash(v) }
318
+ end
319
+ elsif value.respond_to? :to_hash
320
+ value.to_hash
321
+ else
322
+ value
323
+ end
324
+ end
325
+ end
326
+ end
@@ -11,5 +11,5 @@ OpenAPI Generator version: 5.2.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.10.0'
14
+ VERSION = '1.11.1'
15
15
  end
data/lib/patch_ruby.rb CHANGED
@@ -20,9 +20,13 @@ require 'patch_ruby/configuration'
20
20
  require 'patch_ruby/models/allocation'
21
21
  require 'patch_ruby/models/create_bitcoin_estimate_request'
22
22
  require 'patch_ruby/models/create_ethereum_estimate_request'
23
+ require 'patch_ruby/models/create_flight_estimate_request'
23
24
  require 'patch_ruby/models/create_mass_estimate_request'
24
25
  require 'patch_ruby/models/create_order_request'
25
26
  require 'patch_ruby/models/create_preference_request'
27
+ require 'patch_ruby/models/create_shipping_estimate_request'
28
+ require 'patch_ruby/models/create_success_response'
29
+ require 'patch_ruby/models/create_vehicle_estimate_request'
26
30
  require 'patch_ruby/models/error_response'
27
31
  require 'patch_ruby/models/estimate'
28
32
  require 'patch_ruby/models/estimate_list_response'
data/patch_ruby.gemspec CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
 
39
39
  # Start custom
40
40
  s.add_development_dependency 'factory_bot', '~> 6.2'
41
+ s.add_development_dependency 'pry'
41
42
  # End custom
42
43
 
43
44
  end
@@ -30,6 +30,21 @@ RSpec.describe 'Estimates Integration' do
30
30
  expect(flight_estimate.data.mass_g).to eq 1_000_622
31
31
  end
32
32
 
33
+ it 'supports creating flight estimates with origin and destination' do
34
+ flight_estimate = Patch::Estimate.create_flight_estimate(
35
+ origin_airport: "SFO",
36
+ destination_airport: "LAX"
37
+ )
38
+
39
+ flight_estimate_longer = Patch::Estimate.create_flight_estimate(
40
+ origin_airport: "SFO",
41
+ destination_airport: "JFK"
42
+ )
43
+
44
+ expect(flight_estimate.data.type).to eq 'flight'
45
+ expect(flight_estimate_longer.data.mass_g).to be > 2 * flight_estimate.data.mass_g
46
+ end
47
+
33
48
  it 'supports creating vehicle estimates' do
34
49
  distance_m = 10_000
35
50
  make = "Toyota"
@@ -74,8 +89,9 @@ RSpec.describe 'Estimates Integration' do
74
89
  expect(create_estimate_response.data.mass_g).to eq 12_431
75
90
  end
76
91
 
92
+
77
93
  it 'supports creating bitcoin estimates with partial information' do
78
- bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate({ create_order: false })
94
+ bitcoin_estimate = Patch::Estimate.create_bitcoin_estimate({})
79
95
 
80
96
  expect(bitcoin_estimate.data.type).to eq 'bitcoin'
81
97
  expect(bitcoin_estimate.data.mass_g).to be >= 2_000
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,7 @@ require 'patch_ruby'
15
15
  # Start custom
16
16
  require 'constants'
17
17
  require 'factory_bot'
18
+ require 'pry'
18
19
  # End custom
19
20
 
20
21
  # Require shared spec examples
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patch_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patch Technology
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-30 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -64,6 +64,20 @@ dependencies:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '6.2'
67
+ - !ruby/object:Gem::Dependency
68
+ name: pry
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
67
81
  description: Ruby wrapper for the Patch API
68
82
  email:
69
83
  - developers@usepatch.com
@@ -89,9 +103,13 @@ files:
89
103
  - lib/patch_ruby/models/allocation.rb
90
104
  - lib/patch_ruby/models/create_bitcoin_estimate_request.rb
91
105
  - lib/patch_ruby/models/create_ethereum_estimate_request.rb
106
+ - lib/patch_ruby/models/create_flight_estimate_request.rb
92
107
  - lib/patch_ruby/models/create_mass_estimate_request.rb
93
108
  - lib/patch_ruby/models/create_order_request.rb
94
109
  - lib/patch_ruby/models/create_preference_request.rb
110
+ - lib/patch_ruby/models/create_shipping_estimate_request.rb
111
+ - lib/patch_ruby/models/create_success_response.rb
112
+ - lib/patch_ruby/models/create_vehicle_estimate_request.rb
95
113
  - lib/patch_ruby/models/error_response.rb
96
114
  - lib/patch_ruby/models/estimate.rb
97
115
  - lib/patch_ruby/models/estimate_list_response.rb
@@ -186,52 +204,52 @@ specification_version: 4
186
204
  summary: Ruby wrapper for the Patch API
187
205
  test_files:
188
206
  - spec/api/orders_api_spec.rb
189
- - spec/api/preferences_api_spec.rb
190
207
  - spec/api/projects_api_spec.rb
208
+ - spec/api/preferences_api_spec.rb
191
209
  - spec/api/estimates_api_spec.rb
192
210
  - spec/api_client_spec.rb
193
211
  - spec/configuration_spec.rb
194
212
  - spec/constants.rb
195
- - spec/factories/estimate_list_responses.rb
196
- - spec/factories/allocations.rb
213
+ - spec/factories/preferences.rb
197
214
  - spec/factories/create_order_requests.rb
198
- - spec/factories/preference_responses.rb
199
- - spec/factories/meta_index_objects.rb
215
+ - spec/factories/order_list_responses.rb
216
+ - spec/factories/projects.rb
217
+ - spec/factories/estimate_list_responses.rb
200
218
  - spec/factories/create_preference_requests.rb
219
+ - spec/factories/preference_responses.rb
220
+ - spec/factories/error_responses.rb
201
221
  - spec/factories/estimates.rb
202
- - spec/factories/preferences.rb
222
+ - spec/factories/order_responses.rb
203
223
  - spec/factories/create_mass_estimate_requests.rb
204
- - spec/factories/project_list_responses.rb
205
- - spec/factories/error_responses.rb
206
- - spec/factories/orders.rb
207
- - spec/factories/project_responses.rb
208
224
  - spec/factories/preference_list_responses.rb
209
- - spec/factories/order_list_responses.rb
210
- - spec/factories/projects.rb
211
- - spec/factories/order_responses.rb
212
225
  - spec/factories/estimate_responses.rb
213
- - spec/integration/estimates_spec.rb
214
- - spec/integration/orders_spec.rb
226
+ - spec/factories/meta_index_objects.rb
227
+ - spec/factories/project_responses.rb
228
+ - spec/factories/orders.rb
229
+ - spec/factories/project_list_responses.rb
230
+ - spec/factories/allocations.rb
215
231
  - spec/integration/projects_spec.rb
216
232
  - spec/integration/preferences_spec.rb
217
- - spec/models/project_list_response_spec.rb
218
- - spec/models/meta_index_object_spec.rb
219
- - spec/models/create_preference_request_spec.rb
220
- - spec/models/order_list_response_spec.rb
233
+ - spec/integration/estimates_spec.rb
234
+ - spec/integration/orders_spec.rb
235
+ - spec/models/error_response_spec.rb
236
+ - spec/models/create_order_request_spec.rb
221
237
  - spec/models/create_mass_estimate_request_spec.rb
222
- - spec/models/preference_spec.rb
223
- - spec/models/order_response_spec.rb
224
238
  - spec/models/preference_list_response_spec.rb
225
- - spec/models/estimate_spec.rb
226
239
  - spec/models/project_response_spec.rb
240
+ - spec/models/estimate_spec.rb
241
+ - spec/models/project_list_response_spec.rb
242
+ - spec/models/preference_spec.rb
243
+ - spec/models/order_response_spec.rb
244
+ - spec/models/estimate_list_response_spec.rb
245
+ - spec/models/order_list_response_spec.rb
246
+ - spec/models/create_preference_request_spec.rb
247
+ - spec/models/meta_index_object_spec.rb
248
+ - spec/models/order_spec.rb
249
+ - spec/models/preference_response_spec.rb
227
250
  - spec/models/estimate_response_spec.rb
228
- - spec/models/error_response_spec.rb
229
251
  - spec/models/project_spec.rb
230
- - spec/models/preference_response_spec.rb
231
- - spec/models/create_order_request_spec.rb
232
- - spec/models/order_spec.rb
233
252
  - spec/models/allocation_spec.rb
234
- - spec/models/estimate_list_response_spec.rb
235
253
  - spec/patch_ruby_spec.rb
236
254
  - spec/spec_helper.rb
237
255
  - spec/support/shared/generated_classes.rb