patch_ruby 1.9.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +40 -44
  5. data/Makefile +2 -2
  6. data/lib/patch_ruby/api/estimates_api.rb +33 -25
  7. data/lib/patch_ruby/api/orders_api.rb +21 -16
  8. data/lib/patch_ruby/api/preferences_api.rb +17 -13
  9. data/lib/patch_ruby/api/projects_api.rb +9 -7
  10. data/lib/patch_ruby/api_client.rb +51 -49
  11. data/lib/patch_ruby/api_error.rb +1 -1
  12. data/lib/patch_ruby/configuration.rb +38 -9
  13. data/lib/patch_ruby/models/allocation.rb +21 -11
  14. data/lib/patch_ruby/models/create_bitcoin_estimate_request.rb +25 -19
  15. data/lib/patch_ruby/models/create_ethereum_estimate_request.rb +26 -21
  16. data/lib/patch_ruby/models/create_flight_estimate_request.rb +323 -0
  17. data/lib/patch_ruby/models/create_mass_estimate_request.rb +22 -13
  18. data/lib/patch_ruby/models/create_order_request.rb +21 -11
  19. data/lib/patch_ruby/models/create_preference_request.rb +21 -11
  20. data/lib/patch_ruby/models/create_shipping_estimate_request.rb +371 -0
  21. data/lib/patch_ruby/models/create_success_response.rb +247 -0
  22. data/lib/patch_ruby/models/create_vehicle_estimate_request.rb +326 -0
  23. data/lib/patch_ruby/models/error_response.rb +22 -13
  24. data/lib/patch_ruby/models/estimate.rb +22 -13
  25. data/lib/patch_ruby/models/estimate_list_response.rb +22 -13
  26. data/lib/patch_ruby/models/estimate_response.rb +22 -13
  27. data/lib/patch_ruby/models/meta_index_object.rb +23 -15
  28. data/lib/patch_ruby/models/order.rb +23 -15
  29. data/lib/patch_ruby/models/order_list_response.rb +22 -13
  30. data/lib/patch_ruby/models/order_response.rb +22 -13
  31. data/lib/patch_ruby/models/photo.rb +21 -11
  32. data/lib/patch_ruby/models/preference.rb +21 -11
  33. data/lib/patch_ruby/models/preference_list_response.rb +22 -13
  34. data/lib/patch_ruby/models/preference_response.rb +22 -13
  35. data/lib/patch_ruby/models/project.rb +24 -17
  36. data/lib/patch_ruby/models/project_list_response.rb +22 -13
  37. data/lib/patch_ruby/models/project_response.rb +22 -13
  38. data/lib/patch_ruby/models/sdg.rb +21 -11
  39. data/lib/patch_ruby/models/standard.rb +21 -11
  40. data/lib/patch_ruby/version.rb +2 -2
  41. data/lib/patch_ruby.rb +5 -1
  42. data/patch_ruby.gemspec +8 -3
  43. data/spec/api_client_spec.rb +34 -13
  44. data/spec/configuration_spec.rb +1 -1
  45. data/spec/integration/estimates_spec.rb +17 -1
  46. data/spec/integration/preferences_spec.rb +1 -1
  47. data/spec/models/create_mass_estimate_request_spec.rb +1 -1
  48. data/spec/models/error_response_spec.rb +1 -1
  49. data/spec/models/estimate_list_response_spec.rb +1 -1
  50. data/spec/models/estimate_response_spec.rb +1 -1
  51. data/spec/models/estimate_spec.rb +1 -1
  52. data/spec/models/meta_index_object_spec.rb +1 -1
  53. data/spec/models/order_list_response_spec.rb +1 -1
  54. data/spec/models/order_response_spec.rb +1 -1
  55. data/spec/models/order_spec.rb +1 -1
  56. data/spec/models/preference_list_response_spec.rb +1 -1
  57. data/spec/models/preference_response_spec.rb +1 -1
  58. data/spec/models/project_list_response_spec.rb +1 -1
  59. data/spec/models/project_response_spec.rb +1 -1
  60. data/spec/models/project_spec.rb +1 -1
  61. data/spec/spec_helper.rb +69 -61
  62. metadata +56 -58
  63. data/lib/patch_ruby/.api_client.rb.un~ +0 -0
  64. data/lib/patch_ruby/.configuration.rb.un~ +0 -0
  65. data/lib/patch_ruby/.version.rb.un~ +0 -0
  66. data/lib/patch_ruby/api/.orders_api.rb.un~ +0 -0
  67. data/lib/patch_ruby/models/.create_ethereum_estimate_request.rb.un~ +0 -0
  68. data/spec/.spec_helper.rb.un~ +0 -0
  69. data/spec/integration/.estimates_spec.rb.un~ +0 -0
  70. data/spec/integration/.orders_spec.rb.un~ +0 -0
  71. data/spec/integration/.preferences_spec.rb.un~ +0 -0
  72. data/spec/integration/.projects_spec.rb.un~ +0 -0
@@ -6,11 +6,12 @@
6
6
  The version of the OpenAPI document: v1
7
7
  Contact: developers@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ OpenAPI Generator version: 5.2.1
10
10
 
11
11
  =end
12
12
 
13
13
  require 'date'
14
+ require 'time'
14
15
 
15
16
  module Patch
16
17
  class Sdg
@@ -36,6 +37,11 @@ module Patch
36
37
  }
37
38
  end
38
39
 
40
+ # Returns all the JSON keys this model knows about
41
+ def self.acceptable_attributes
42
+ attribute_map.values
43
+ end
44
+
39
45
  # Attribute type mapping.
40
46
  def self.openapi_types
41
47
  {
@@ -46,13 +52,13 @@ module Patch
46
52
  }
47
53
  end
48
54
 
49
- # Set with nullable attributes.
55
+ # List of attributes with nullable: true
50
56
  def self.openapi_nullable
51
- nullable_properties = Set.new
52
-
53
- nullable_properties
57
+ Set.new([
58
+ ])
54
59
  end
55
60
 
61
+
56
62
  # Allows models with corresponding API classes to delegate API operations to those API classes
57
63
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
58
64
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -165,7 +171,9 @@ module Patch
165
171
  def build_from_hash(attributes)
166
172
  return nil unless attributes.is_a?(Hash)
167
173
  self.class.openapi_types.each_pair do |key, type|
168
- if type =~ /\AArray<(.*)>/i
174
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
175
+ self.send("#{key}=", nil)
176
+ elsif type =~ /\AArray<(.*)>/i
169
177
  # check to ensure the input is an array given that the attribute
170
178
  # is documented as an array but the input is not
171
179
  if attributes[self.class.attribute_map[key]].is_a?(Array)
@@ -173,7 +181,7 @@ module Patch
173
181
  end
174
182
  elsif !attributes[self.class.attribute_map[key]].nil?
175
183
  self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
176
- end # or else data not found in attributes(hash), not an issue as the data can be optional
184
+ end
177
185
  end
178
186
 
179
187
  self
@@ -185,8 +193,8 @@ module Patch
185
193
  # @return [Object] Deserialized data
186
194
  def _deserialize(type, value)
187
195
  case type.to_sym
188
- when :DateTime
189
- DateTime.parse(value)
196
+ when :Time
197
+ Time.parse(value)
190
198
  when :Date
191
199
  Date.parse(value)
192
200
  when :String
@@ -216,7 +224,9 @@ module Patch
216
224
  end
217
225
  end
218
226
  else # model
219
- Patch.const_get(type).build_from_hash(value)
227
+ # models (e.g. Pet) or oneOf
228
+ klass = Patch.const_get(type)
229
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
220
230
  end
221
231
  end
222
232
 
@@ -242,7 +252,7 @@ module Patch
242
252
  is_nullable = self.class.openapi_nullable.include?(attr)
243
253
  next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
244
254
  end
245
-
255
+
246
256
  hash[param] = _to_hash(value)
247
257
  end
248
258
  hash
@@ -6,11 +6,12 @@
6
6
  The version of the OpenAPI document: v1
7
7
  Contact: developers@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ OpenAPI Generator version: 5.2.1
10
10
 
11
11
  =end
12
12
 
13
13
  require 'date'
14
+ require 'time'
14
15
 
15
16
  module Patch
16
17
  class Standard
@@ -32,6 +33,11 @@ module Patch
32
33
  }
33
34
  end
34
35
 
36
+ # Returns all the JSON keys this model knows about
37
+ def self.acceptable_attributes
38
+ attribute_map.values
39
+ end
40
+
35
41
  # Attribute type mapping.
36
42
  def self.openapi_types
37
43
  {
@@ -41,13 +47,13 @@ module Patch
41
47
  }
42
48
  end
43
49
 
44
- # Set with nullable attributes.
50
+ # List of attributes with nullable: true
45
51
  def self.openapi_nullable
46
- nullable_properties = Set.new
47
-
48
- nullable_properties
52
+ Set.new([
53
+ ])
49
54
  end
50
55
 
56
+
51
57
  # Allows models with corresponding API classes to delegate API operations to those API classes
52
58
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
53
59
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -150,7 +156,9 @@ module Patch
150
156
  def build_from_hash(attributes)
151
157
  return nil unless attributes.is_a?(Hash)
152
158
  self.class.openapi_types.each_pair do |key, type|
153
- if type =~ /\AArray<(.*)>/i
159
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
160
+ self.send("#{key}=", nil)
161
+ elsif type =~ /\AArray<(.*)>/i
154
162
  # check to ensure the input is an array given that the attribute
155
163
  # is documented as an array but the input is not
156
164
  if attributes[self.class.attribute_map[key]].is_a?(Array)
@@ -158,7 +166,7 @@ module Patch
158
166
  end
159
167
  elsif !attributes[self.class.attribute_map[key]].nil?
160
168
  self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
161
- end # or else data not found in attributes(hash), not an issue as the data can be optional
169
+ end
162
170
  end
163
171
 
164
172
  self
@@ -170,8 +178,8 @@ module Patch
170
178
  # @return [Object] Deserialized data
171
179
  def _deserialize(type, value)
172
180
  case type.to_sym
173
- when :DateTime
174
- DateTime.parse(value)
181
+ when :Time
182
+ Time.parse(value)
175
183
  when :Date
176
184
  Date.parse(value)
177
185
  when :String
@@ -201,7 +209,9 @@ module Patch
201
209
  end
202
210
  end
203
211
  else # model
204
- Patch.const_get(type).build_from_hash(value)
212
+ # models (e.g. Pet) or oneOf
213
+ klass = Patch.const_get(type)
214
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
205
215
  end
206
216
  end
207
217
 
@@ -227,7 +237,7 @@ module Patch
227
237
  is_nullable = self.class.openapi_nullable.include?(attr)
228
238
  next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
229
239
  end
230
-
240
+
231
241
  hash[param] = _to_hash(value)
232
242
  end
233
243
  hash
@@ -6,10 +6,10 @@
6
6
  The version of the OpenAPI document: v1
7
7
  Contact: developers@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ OpenAPI Generator version: 5.2.1
10
10
 
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.9.0'
14
+ VERSION = '1.11.0'
15
15
  end
data/lib/patch_ruby.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: v1
7
7
  Contact: developers@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ OpenAPI Generator version: 5.2.1
10
10
 
11
11
  =end
12
12
 
@@ -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
@@ -8,7 +8,7 @@
8
8
  The version of the OpenAPI document: v1
9
9
  Contact: developers@usepatch.com
10
10
  Generated by: https://openapi-generator.tech
11
- OpenAPI Generator version: 4.3.1
11
+ OpenAPI Generator version: 5.2.1
12
12
 
13
13
  =end
14
14
 
@@ -24,11 +24,10 @@ Gem::Specification.new do |s|
24
24
  s.homepage = "https://www.patch.io"
25
25
  s.summary = "Ruby wrapper for the Patch API"
26
26
  s.description = "Ruby wrapper for the Patch API"
27
- s.license = 'MIT'
27
+ s.license = "MIT"
28
28
  s.required_ruby_version = ">= 1.9"
29
29
 
30
30
  s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
31
- s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
32
31
 
33
32
  s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
34
33
 
@@ -36,4 +35,10 @@ Gem::Specification.new do |s|
36
35
  s.test_files = `find spec/*`.split("\n")
37
36
  s.executables = []
38
37
  s.require_paths = ["lib"]
38
+
39
+ # Start custom
40
+ s.add_development_dependency 'factory_bot', '~> 6.2'
41
+ s.add_development_dependency 'pry'
42
+ # End custom
43
+
39
44
  end
@@ -6,26 +6,47 @@
6
6
  The version of the OpenAPI document: v1
7
7
  Contact: developers@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ OpenAPI Generator version: 5.2.1
10
10
 
11
11
  =end
12
12
 
13
+ require 'spec_helper'
14
+
13
15
  describe Patch::ApiClient do
14
16
  context 'initialization' do
15
- context 'base_path' do
16
- it "prepends a slash to base_path" do
17
- Patch.configure { |c| c.base_path = 'v4/dog' }
18
- expect(Patch::Configuration.default.base_path).to eq('/v4/dog')
19
- end
20
-
21
- it "doesn't prepend a slash if one is already there" do
22
- Patch.configure { |c| c.base_path = '/v4/dog' }
23
- expect(Patch::Configuration.default.base_path).to eq('/v4/dog')
17
+ context 'URL stuff' do
18
+ context 'host' do
19
+ it 'removes http from host' do
20
+ Patch.configure { |c| c.host = 'http://example.com' }
21
+ expect(Patch::Configuration.default.host).to eq('example.com')
22
+ end
23
+
24
+ it 'removes https from host' do
25
+ Patch.configure { |c| c.host = 'https://wookiee.com' }
26
+ expect(Patch::ApiClient.default.config.host).to eq('wookiee.com')
27
+ end
28
+
29
+ it 'removes trailing path from host' do
30
+ Patch.configure { |c| c.host = 'hobo.com/v4' }
31
+ expect(Patch::Configuration.default.host).to eq('hobo.com')
32
+ end
24
33
  end
25
34
 
26
- it "ends up as a blank string if nil" do
27
- Patch.configure { |c| c.base_path = nil }
28
- expect(Patch::Configuration.default.base_path).to eq('')
35
+ context 'base_path' do
36
+ it "prepends a slash to base_path" do
37
+ Patch.configure { |c| c.base_path = 'v4/dog' }
38
+ expect(Patch::Configuration.default.base_path).to eq('/v4/dog')
39
+ end
40
+
41
+ it "doesn't prepend a slash if one is already there" do
42
+ Patch.configure { |c| c.base_path = '/v4/dog' }
43
+ expect(Patch::Configuration.default.base_path).to eq('/v4/dog')
44
+ end
45
+
46
+ it "ends up as a blank string if nil" do
47
+ Patch.configure { |c| c.base_path = nil }
48
+ expect(Patch::Configuration.default.base_path).to eq('')
49
+ end
29
50
  end
30
51
  end
31
52
  end
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: v1
7
7
  Contact: developers@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ OpenAPI Generator version: 5.2.1
10
10
 
11
11
  =end
12
12
 
@@ -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
@@ -7,7 +7,7 @@ RSpec.describe 'Preferences Integration' do
7
7
  begin
8
8
  create_preference_response = Patch::Preference.create_preference(project_id: project_id)
9
9
  preference_id = create_preference_response.data.id
10
- rescue => Patch::ApiError
10
+ rescue Patch::ApiError => e
11
11
  preference_id = Patch::Preference.retrieve_preferences().data.first.id
12
12
  end
13
13
 
@@ -30,7 +30,7 @@ describe 'CreateMassEstimateRequest' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g } }
33
- let(:nullable_properties) { Set.new(["create_order"]) }
33
+ let(:nullable_properties) { Set.new([:create_order]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of CreateMassEstimateRequest' do
@@ -30,7 +30,7 @@ describe 'ErrorResponse' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } }
33
- let(:nullable_properties) { Set.new(["data"]) }
33
+ let(:nullable_properties) { Set.new([:data]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of ErrorResponse' do
@@ -30,7 +30,7 @@ describe 'EstimateListResponse' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } }
33
- let(:nullable_properties) { Set.new(["error"]) }
33
+ let(:nullable_properties) { Set.new([:error]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of EstimateListResponse' do
@@ -30,7 +30,7 @@ describe 'EstimateResponse' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } }
33
- let(:nullable_properties) { Set.new(["error"]) }
33
+ let(:nullable_properties) { Set.new([:error]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of EstimateResponse' do
@@ -30,7 +30,7 @@ describe 'Estimate' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { id: @instance.id, order: @instance.order.to_hash, production: @instance.production, type: @instance.type } }
33
- let(:nullable_properties) { Set.new(["order"]) }
33
+ let(:nullable_properties) { Set.new([:order]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of Estimate' do
@@ -30,7 +30,7 @@ describe 'MetaIndexObject' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { next_page: @instance.next_page, prev_page: @instance.prev_page } }
33
- let(:nullable_properties) { Set.new(["next_page", "prev_page"]) }
33
+ let(:nullable_properties) { Set.new([:next_page, :prev_page]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of MetaIndexObject' do
@@ -30,7 +30,7 @@ describe 'OrderListResponse' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } }
33
- let(:nullable_properties) { Set.new(["error"]) }
33
+ let(:nullable_properties) { Set.new([:error]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of OrderListResponse' do
@@ -30,7 +30,7 @@ describe 'OrderResponse' do
30
30
  it_behaves_like "a generated class" do
31
31
  let(:instance) { @instance }
32
32
  let(:instance_hash) { { success: @instance.success, error: @instance.error, data: @instance.data } }
33
- let(:nullable_properties) { Set.new(["error"]) }
33
+ let(:nullable_properties) { Set.new([:error]) }
34
34
  end
35
35
 
36
36
  describe 'test an instance of OrderResponse' do