patch_ruby 1.2.4 → 1.5.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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -2
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +19 -3
  5. data/README.md +72 -8
  6. data/lib/patch_ruby.rb +1 -0
  7. data/lib/patch_ruby/api/estimates_api.rb +195 -0
  8. data/lib/patch_ruby/api/projects_api.rb +9 -0
  9. data/lib/patch_ruby/configuration.rb +2 -2
  10. data/lib/patch_ruby/models/allocation.rb +10 -0
  11. data/lib/patch_ruby/models/create_mass_estimate_request.rb +19 -1
  12. data/lib/patch_ruby/models/create_order_request.rb +7 -0
  13. data/lib/patch_ruby/models/create_preference_request.rb +7 -0
  14. data/lib/patch_ruby/models/error_response.rb +9 -0
  15. data/lib/patch_ruby/models/estimate.rb +24 -1
  16. data/lib/patch_ruby/models/estimate_list_response.rb +9 -0
  17. data/lib/patch_ruby/models/estimate_response.rb +9 -0
  18. data/lib/patch_ruby/models/meta_index_object.rb +11 -0
  19. data/lib/patch_ruby/models/order.rb +20 -0
  20. data/lib/patch_ruby/models/order_list_response.rb +9 -0
  21. data/lib/patch_ruby/models/order_response.rb +9 -0
  22. data/lib/patch_ruby/models/photo.rb +25 -4
  23. data/lib/patch_ruby/models/preference.rb +10 -0
  24. data/lib/patch_ruby/models/preference_list_response.rb +9 -0
  25. data/lib/patch_ruby/models/preference_response.rb +9 -0
  26. data/lib/patch_ruby/models/project.rb +40 -4
  27. data/lib/patch_ruby/models/project_list_response.rb +9 -0
  28. data/lib/patch_ruby/models/project_response.rb +9 -0
  29. data/lib/patch_ruby/models/sdg.rb +269 -0
  30. data/lib/patch_ruby/models/standard.rb +10 -0
  31. data/lib/patch_ruby/version.rb +1 -1
  32. data/patch_ruby.gemspec +1 -1
  33. data/spec/configuration_spec.rb +3 -3
  34. data/spec/factories/allocations.rb +7 -0
  35. data/spec/factories/create_mass_estimate_requests.rb +6 -0
  36. data/spec/factories/create_order_requests.rb +8 -0
  37. data/spec/factories/create_preference_requests.rb +5 -0
  38. data/spec/factories/error_responses.rb +7 -0
  39. data/spec/factories/estimate_list_responses.rb +8 -0
  40. data/spec/factories/estimate_responses.rb +7 -0
  41. data/spec/factories/estimates.rb +8 -0
  42. data/spec/factories/meta_index_objects.rb +6 -0
  43. data/spec/factories/order_list_responses.rb +8 -0
  44. data/spec/factories/order_responses.rb +7 -0
  45. data/spec/factories/orders.rb +12 -0
  46. data/spec/factories/preference_list_responses.rb +8 -0
  47. data/spec/factories/preference_responses.rb +7 -0
  48. data/spec/factories/preferences.rb +7 -0
  49. data/spec/factories/project_list_responses.rb +8 -0
  50. data/spec/factories/project_responses.rb +7 -0
  51. data/spec/factories/projects.rb +15 -0
  52. data/spec/integration/estimates_spec.rb +52 -8
  53. data/spec/integration/orders_spec.rb +2 -2
  54. data/spec/integration/preferences_spec.rb +6 -2
  55. data/spec/integration/projects_spec.rb +20 -0
  56. data/spec/models/allocation_spec.rb +8 -1
  57. data/spec/models/create_mass_estimate_request_spec.rb +7 -1
  58. data/spec/models/create_order_request_spec.rb +7 -1
  59. data/spec/models/create_preference_request_spec.rb +8 -1
  60. data/spec/models/error_response_spec.rb +7 -1
  61. data/spec/models/estimate_list_response_spec.rb +7 -1
  62. data/spec/models/estimate_response_spec.rb +7 -1
  63. data/spec/models/estimate_spec.rb +8 -1
  64. data/spec/models/meta_index_object_spec.rb +7 -1
  65. data/spec/models/order_list_response_spec.rb +7 -1
  66. data/spec/models/order_response_spec.rb +7 -1
  67. data/spec/models/order_spec.rb +18 -1
  68. data/spec/models/preference_list_response_spec.rb +7 -1
  69. data/spec/models/preference_response_spec.rb +7 -1
  70. data/spec/models/preference_spec.rb +7 -1
  71. data/spec/models/project_list_response_spec.rb +7 -1
  72. data/spec/models/project_response_spec.rb +7 -1
  73. data/spec/models/project_spec.rb +21 -1
  74. data/spec/patch_ruby_spec.rb +18 -0
  75. data/spec/spec_helper.rb +10 -0
  76. data/spec/support/shared/generated_classes.rb +13 -0
  77. metadata +58 -17
@@ -14,10 +14,13 @@ require 'date'
14
14
 
15
15
  module Patch
16
16
  class Standard
17
+ # The standard type.
17
18
  attr_accessor :type
18
19
 
20
+ # The acronym for the standard.
19
21
  attr_accessor :acronym
20
22
 
23
+ # The description of the standard.
21
24
  attr_accessor :description
22
25
 
23
26
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -38,6 +41,13 @@ module Patch
38
41
  }
39
42
  end
40
43
 
44
+ # Set with nullable attributes.
45
+ def self.openapi_nullable
46
+ nullable_properties = Set.new
47
+
48
+ nullable_properties
49
+ end
50
+
41
51
  # Allows models with corresponding API classes to delegate API operations to those API classes
42
52
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43
53
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.2.4'
14
+ VERSION = '1.5.1'
15
15
  end
data/patch_ruby.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.platform = Gem::Platform::RUBY
22
22
  s.authors = ["Patch Technology"]
23
23
  s.email = ["developers@usepatch.com"]
24
- s.homepage = "https://www.usepatch.com"
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
27
  s.license = 'MIT'
@@ -18,7 +18,7 @@ describe Patch::Configuration do
18
18
  before(:each) do
19
19
  # uncomment below to setup host and base_path
20
20
  # require 'URI'
21
- # uri = URI.parse("https://api.usepatch.com")
21
+ # uri = URI.parse("https://api.patch.io")
22
22
  # Patch.configure do |c|
23
23
  # c.host = uri.host
24
24
  # c.base_path = uri.path
@@ -28,14 +28,14 @@ describe Patch::Configuration do
28
28
  describe '#base_url' do
29
29
  it 'should have the default value' do
30
30
  # uncomment below to test default value of the base path
31
- # expect(config.base_url).to eq("https://api.usepatch.com")
31
+ # expect(config.base_url).to eq("https://api.patch.io")
32
32
  end
33
33
 
34
34
  it 'should remove trailing slashes' do
35
35
  [nil, '', '/', '//'].each do |base_path|
36
36
  config.base_path = base_path
37
37
  # uncomment below to test trailing slashes
38
- # expect(config.base_url).to eq("https://api.usepatch.com")
38
+ # expect(config.base_url).to eq("https://api.patch.io")
39
39
  end
40
40
  end
41
41
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :allocation, class: Patch::Allocation do
3
+ sequence(:id) { |n| n }
4
+ production { false }
5
+ mass_g { 100 }
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :create_mass_estimate_request, class: Patch::CreateMassEstimateRequest do
3
+ sequence(:project_id) { |n| n }
4
+ mass_g { 100 }
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :create_order_request, class: Patch::CreateOrderRequest do
3
+ sequence(:project_id) { |n| n }
4
+ mass_g { 100 }
5
+ total_price_cents_usd { 100 }
6
+ metadata { {} }
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :create_preference_request, class: Patch::CreatePreferenceRequest do
3
+ sequence(:project_id) { |n| n }
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :error_response, class: Patch::ErrorResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :estimate_list_response, class: Patch::EstimateListResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ meta { {} }
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :estimate_response, class: Patch::EstimateResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :estimate, class: Patch::Estimate do
3
+ sequence(:id) { |n| n }
4
+ association :order
5
+ production { false }
6
+ type { "mass" }
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :meta_index_object, class: Patch::MetaIndexObject do
3
+ sequence(:next_page) { |n| n + 1 }
4
+ sequence(:prev_page) { |n| n - 1 }
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :order_list_response, class: Patch::OrderListResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ meta { {} }
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :order_response, class: Patch::OrderResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ FactoryBot.define do
2
+ factory :order, class: Patch::Order do
3
+ sequence(:id) { |n| n }
4
+ mass_g { 1_000 }
5
+ production { false }
6
+ state { "draft" }
7
+ allocation_state { "pending" }
8
+ price_cents_usd { 500 }
9
+ patch_fee_cents_usd { 5 }
10
+ metadata { {} }
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :preference_list_response, class: Patch::PreferenceListResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ meta { {} }
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :preference_response, class: Patch::PreferenceResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :preference, class: Patch::Preference do
3
+ sequence(:id) { |n| n }
4
+ association :project
5
+ allocation_percentage { 1 }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :project_list_response, class: Patch::ProjectListResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ meta { {} }
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :project_response, class: Patch::ProjectResponse do
3
+ success { true }
4
+ error { {} }
5
+ data { {} }
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ FactoryBot.define do
2
+ factory :project, class: Patch::Project do
3
+ sequence(:id) { |n| n }
4
+ production { false }
5
+ name { "New Project" }
6
+ description { "New Descirption" }
7
+ type { "biomass" }
8
+ country { "DK" }
9
+ developer { "Danish Developer" }
10
+ photos { [] }
11
+ average_price_per_tonne_cents_usd { 120 }
12
+ remaining_mass_g { 1_000 }
13
+ standard { 'european_biochar_certificate' }
14
+ end
15
+ end
@@ -25,14 +25,58 @@ RSpec.describe 'Estimates Integration' do
25
25
  expect(estimates.length).not_to be_zero
26
26
  end
27
27
 
28
- it 'supports create with a project-id' do
29
- retrieve_projects_response = Patch::Project.retrieve_projects(page: 1)
30
- project_id = retrieve_projects_response.data.first.id
31
- create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100, project_id: project_id)
32
- estimate_id = create_estimate_response.data.id
28
+ it 'supports creating flight estimates' do
29
+ distance_m = 10_000_000
30
+ flight_estimate = Patch::Estimate.create_flight_estimate(
31
+ distance_m: distance_m,
32
+ create_order: false
33
+ )
34
+
35
+ expect(flight_estimate.data.type).to eq 'flight'
36
+ expect(flight_estimate.data.mass_g).to eq 1_031_697
37
+ end
38
+
39
+ it 'supports creating vehicle estimates' do
40
+ distance_m = 10_000
41
+ make = "Toyota"
42
+ model = "Corolla"
43
+ year = 2000
44
+
45
+ vehicle_estimate = Patch::Estimate.create_vehicle_estimate(
46
+ distance_m: distance_m,
47
+ make: make,
48
+ model: model,
49
+ year: year,
50
+ create_order: false
51
+ )
52
+
53
+ expect(vehicle_estimate.data.type).to eq 'vehicle'
54
+ expect(vehicle_estimate.data.mass_g).to eq 5_500
55
+ end
56
+
57
+ it 'supports creating vehicle estimates with partial information' do
58
+ distance_m = 10_000
59
+
60
+ vehicle_estimate = Patch::Estimate.create_vehicle_estimate(
61
+ distance_m: distance_m,
62
+ create_order: false
63
+ )
64
+
65
+ expect(vehicle_estimate.data.type).to eq 'vehicle'
66
+ expect(vehicle_estimate.data.mass_g).to eq 2_132
67
+ end
68
+
69
+ it 'supports creating shipping estimates' do
70
+ distance_m = 100_000_000
71
+ package_mass_g = 10_000
72
+ create_estimate_response = Patch::Estimate.create_shipping_estimate(
73
+ distance_m: distance_m,
74
+ package_mass_g: package_mass_g,
75
+ transportation_method: 'rail',
76
+ create_order: false
77
+ )
33
78
 
34
- expect(create_estimate_response.success).to eq true
35
- expect(create_estimate_response.data.order.id).not_to be_nil
36
- expect(create_estimate_response.data.order.mass_g).to eq(100)
79
+ expect(create_estimate_response.data.type).to eq 'shipping'
80
+ expect(create_estimate_response.data.mass_g).to eq 12_431
37
81
  end
38
82
  end
@@ -65,8 +65,8 @@ RSpec.describe 'Orders Integration' do
65
65
  order = create_order_response.data
66
66
 
67
67
  expect(order.id).not_to be_nil
68
- expect(order.mass_g).to eq(5_000_000)
69
- expect(order.price_cents_usd.to_i).to eq(500)
68
+ expect(order.mass_g).to eq(5_00_000)
69
+ expect(order.price_cents_usd).not_to be_empty
70
70
  expect(order.patch_fee_cents_usd).not_to be_empty
71
71
  expect(
72
72
  order.price_cents_usd.to_i + order.patch_fee_cents_usd.to_i
@@ -10,8 +10,12 @@ RSpec.describe 'Preferences Integration' do
10
10
  expect(retrieve_projects_response.data.length).not_to be_zero
11
11
  project_id = retrieve_projects_response.data.first.id
12
12
 
13
- create_preference_response = Patch::Preference.create_preference(project_id: project_id)
14
- preference_id = create_preference_response.data.id
13
+ begin
14
+ create_preference_response = Patch::Preference.create_preference(project_id: project_id)
15
+ preference_id = create_preference_response.data.id
16
+ rescue => Patch::ApiError
17
+ preference_id = Patch::Preference.retrieve_preferences().data.first.id
18
+ end
15
19
 
16
20
  retrieve_preference_response = Patch::Preference.retrieve_preference(preference_id)
17
21
  expect(retrieve_preference_response.data.id).to eq preference_id
@@ -22,6 +22,26 @@ RSpec.describe 'Projects Integration' do
22
22
  expect(retrieve_project_response.data.id).to eq project_id
23
23
  end
24
24
 
25
+ it 'supports filtering projects' do
26
+ country = 'US'
27
+ projects = Patch::Project.retrieve_projects(country: country)
28
+ projects.data.map do |project|
29
+ expect(project.country).to eq country
30
+ end
31
+
32
+ type = 'dac'
33
+ projects = Patch::Project.retrieve_projects(type: type)
34
+ projects.data.map do |project|
35
+ expect(project.type).to eq type
36
+ end
37
+
38
+ minimum_available_mass = 100
39
+ projects = Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)
40
+ projects.data.map do |project|
41
+ expect(project.remaining_mass_g >= minimum_available_mass).to be true
42
+ end
43
+ end
44
+
25
45
  describe 'returned fields' do
26
46
  before do
27
47
  @project = Patch::Project.retrieve_projects(page: 1).data.first
@@ -20,18 +20,25 @@ require 'date'
20
20
  describe 'Allocation' do
21
21
  before do
22
22
  # run before each test
23
- @instance = Patch::Allocation.new
23
+ @instance = build(:allocation)
24
24
  end
25
25
 
26
26
  after do
27
27
  # run after each test
28
28
  end
29
29
 
30
+ it_behaves_like "a generated class" do
31
+ let(:instance) { @instance }
32
+ let(:instance_hash) { { id: @instance.id, mass_g: @instance.mass_g, production: @instance.production } }
33
+ let(:nullable_properties) { Set.new }
34
+ end
35
+
30
36
  describe 'test an instance of Allocation' do
31
37
  it 'should create an instance of Allocation' do
32
38
  expect(@instance).to be_instance_of(Patch::Allocation)
33
39
  end
34
40
  end
41
+
35
42
  describe 'test attribute "id"' do
36
43
  it 'should work' do
37
44
  # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
@@ -20,13 +20,19 @@ require 'date'
20
20
  describe 'CreateMassEstimateRequest' do
21
21
  before do
22
22
  # run before each test
23
- @instance = Patch::CreateMassEstimateRequest.new
23
+ @instance = build(:create_mass_estimate_request)
24
24
  end
25
25
 
26
26
  after do
27
27
  # run after each test
28
28
  end
29
29
 
30
+ it_behaves_like "a generated class" do
31
+ let(:instance) { @instance }
32
+ let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g } }
33
+ let(:nullable_properties) { Set.new(["create_order"]) }
34
+ end
35
+
30
36
  describe 'test an instance of CreateMassEstimateRequest' do
31
37
  it 'should create an instance of CreateMassEstimateRequest' do
32
38
  expect(@instance).to be_instance_of(Patch::CreateMassEstimateRequest)
@@ -20,13 +20,19 @@ require 'date'
20
20
  describe 'CreateOrderRequest' do
21
21
  before do
22
22
  # run before each test
23
- @instance = Patch::CreateOrderRequest.new
23
+ @instance = build(:create_order_request)
24
24
  end
25
25
 
26
26
  after do
27
27
  # run after each test
28
28
  end
29
29
 
30
+ it_behaves_like "a generated class" do
31
+ let(:instance) { @instance }
32
+ let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g, total_price_cents_usd: @instance.total_price_cents_usd, metadata: @instance.metadata } }
33
+ let(:nullable_properties) { Set.new }
34
+ end
35
+
30
36
  describe 'test an instance of CreateOrderRequest' do
31
37
  it 'should create an instance of CreateOrderRequest' do
32
38
  expect(@instance).to be_instance_of(Patch::CreateOrderRequest)