patch_ruby 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +18 -2
- data/Makefile +10 -0
- data/README.md +48 -9
- data/lib/patch_ruby.rb +2 -0
- data/lib/patch_ruby/api/estimates_api.rb +195 -0
- data/lib/patch_ruby/models/allocation.rb +10 -0
- data/lib/patch_ruby/models/create_mass_estimate_request.rb +47 -1
- data/lib/patch_ruby/models/create_order_request.rb +54 -4
- data/lib/patch_ruby/models/create_preference_request.rb +7 -0
- data/lib/patch_ruby/models/error_response.rb +9 -0
- data/lib/patch_ruby/models/estimate.rb +24 -1
- data/lib/patch_ruby/models/estimate_list_response.rb +9 -0
- data/lib/patch_ruby/models/estimate_response.rb +9 -0
- data/lib/patch_ruby/models/meta_index_object.rb +11 -0
- data/lib/patch_ruby/models/order.rb +58 -1
- data/lib/patch_ruby/models/order_list_response.rb +9 -0
- data/lib/patch_ruby/models/order_response.rb +9 -0
- data/lib/patch_ruby/models/photo.rb +237 -0
- data/lib/patch_ruby/models/preference.rb +10 -0
- data/lib/patch_ruby/models/preference_list_response.rb +9 -0
- data/lib/patch_ruby/models/preference_response.rb +9 -0
- data/lib/patch_ruby/models/project.rb +74 -4
- data/lib/patch_ruby/models/project_list_response.rb +9 -0
- data/lib/patch_ruby/models/project_response.rb +9 -0
- data/lib/patch_ruby/models/standard.rb +254 -0
- data/lib/patch_ruby/version.rb +1 -1
- data/spec/constants.rb +3 -0
- data/spec/factories/allocations.rb +7 -0
- data/spec/factories/create_mass_estimate_requests.rb +6 -0
- data/spec/factories/create_order_requests.rb +8 -0
- data/spec/factories/create_preference_requests.rb +5 -0
- data/spec/factories/error_responses.rb +7 -0
- data/spec/factories/estimate_list_responses.rb +8 -0
- data/spec/factories/estimate_responses.rb +7 -0
- data/spec/factories/estimates.rb +8 -0
- data/spec/factories/meta_index_objects.rb +6 -0
- data/spec/factories/order_list_responses.rb +8 -0
- data/spec/factories/order_responses.rb +7 -0
- data/spec/factories/orders.rb +12 -0
- data/spec/factories/preference_list_responses.rb +8 -0
- data/spec/factories/preference_responses.rb +7 -0
- data/spec/factories/preferences.rb +7 -0
- data/spec/factories/project_list_responses.rb +8 -0
- data/spec/factories/project_responses.rb +7 -0
- data/spec/factories/projects.rb +15 -0
- data/spec/integration/estimates_spec.rb +41 -9
- data/spec/integration/orders_spec.rb +42 -5
- data/spec/integration/preferences_spec.rb +7 -3
- data/spec/integration/projects_spec.rb +19 -1
- data/spec/models/allocation_spec.rb +8 -1
- data/spec/models/create_mass_estimate_request_spec.rb +7 -1
- data/spec/models/create_order_request_spec.rb +7 -1
- data/spec/models/create_preference_request_spec.rb +8 -1
- data/spec/models/error_response_spec.rb +7 -1
- data/spec/models/estimate_list_response_spec.rb +7 -1
- data/spec/models/estimate_response_spec.rb +7 -1
- data/spec/models/estimate_spec.rb +8 -1
- data/spec/models/meta_index_object_spec.rb +7 -1
- data/spec/models/order_list_response_spec.rb +7 -1
- data/spec/models/order_response_spec.rb +7 -1
- data/spec/models/order_spec.rb +18 -1
- data/spec/models/preference_list_response_spec.rb +7 -1
- data/spec/models/preference_response_spec.rb +7 -1
- data/spec/models/preference_spec.rb +7 -1
- data/spec/models/project_list_response_spec.rb +7 -1
- data/spec/models/project_response_spec.rb +7 -1
- data/spec/models/project_spec.rb +21 -1
- data/spec/spec_helper.rb +11 -0
- data/spec/support/shared/generated_classes.rb +13 -0
- metadata +60 -17
@@ -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
|
@@ -1,7 +1,7 @@
|
|
1
1
|
RSpec.describe 'Estimates Integration' do
|
2
2
|
before do
|
3
3
|
Patch.configure do |config|
|
4
|
-
config.access_token = ENV['
|
4
|
+
config.access_token = ENV['SANDBOX_API_KEY']
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -25,14 +25,46 @@ RSpec.describe 'Estimates Integration' do
|
|
25
25
|
expect(estimates.length).not_to be_zero
|
26
26
|
end
|
27
27
|
|
28
|
-
it 'supports
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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_032_000
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'supports creating vehicle estimates' do
|
40
|
+
distance_m = 10_000
|
41
|
+
make = "Toyota"
|
42
|
+
model = "Prius"
|
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 2_132
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'supports creating shipping estimates' do
|
58
|
+
distance_m = 100_000_000
|
59
|
+
package_mass_g = 10_000
|
60
|
+
create_estimate_response = Patch::Estimate.create_shipping_estimate(
|
61
|
+
distance_m: distance_m,
|
62
|
+
package_mass_g: package_mass_g,
|
63
|
+
transportation_method: 'rail',
|
64
|
+
create_order: false
|
65
|
+
)
|
33
66
|
|
34
|
-
expect(create_estimate_response.
|
35
|
-
expect(create_estimate_response.data.
|
36
|
-
expect(create_estimate_response.data.order.mass_g).to eq(100)
|
67
|
+
expect(create_estimate_response.data.type).to eq 'shipping'
|
68
|
+
expect(create_estimate_response.data.mass_g).to eq 12_431
|
37
69
|
end
|
38
70
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
RSpec.describe 'Orders Integration' do
|
2
2
|
before do
|
3
3
|
Patch.configure do |config|
|
4
|
-
config.access_token = ENV['
|
4
|
+
config.access_token = ENV['SANDBOX_API_KEY']
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -26,14 +26,51 @@ RSpec.describe 'Orders Integration' do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'supports create with a project-id' do
|
29
|
-
|
30
|
-
|
29
|
+
retrieve_project_response = Patch::Project.retrieve_project(
|
30
|
+
Constants::BIOMASS_TEST_PROJECT_ID
|
31
|
+
)
|
31
32
|
|
32
|
-
|
33
|
+
project_id = retrieve_project_response.data.id
|
34
|
+
average_price_per_tonne_cents_usd = retrieve_project_response.data.average_price_per_tonne_cents_usd
|
35
|
+
|
36
|
+
order_mass_g = 100_000
|
37
|
+
tonne_per_gram = 1_000_000
|
38
|
+
|
39
|
+
expected_price = (average_price_per_tonne_cents_usd.to_f / tonne_per_gram) * order_mass_g
|
40
|
+
|
41
|
+
create_order_response = Patch::Order.create_order(mass_g: order_mass_g, project_id: project_id)
|
33
42
|
|
34
43
|
expect(create_order_response.success).to eq true
|
35
44
|
expect(create_order_response.data.id).not_to be_nil
|
36
|
-
expect(create_order_response.data.mass_g).to eq(
|
45
|
+
expect(create_order_response.data.mass_g).to eq(order_mass_g)
|
46
|
+
expect(create_order_response.data.price_cents_usd.to_i).to eq(expected_price)
|
47
|
+
expect(create_order_response.data.patch_fee_cents_usd).not_to be_empty
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'supports create with a total price' do
|
51
|
+
retrieve_project_response = Patch::Project.retrieve_project(
|
52
|
+
Constants::BIOMASS_TEST_PROJECT_ID
|
53
|
+
)
|
54
|
+
|
55
|
+
project_id = retrieve_project_response.data.id
|
56
|
+
total_price_cents_usd = 5_00
|
57
|
+
|
58
|
+
create_order_response = Patch::Order.create_order(
|
59
|
+
total_price_cents_usd: total_price_cents_usd,
|
60
|
+
project_id: project_id
|
61
|
+
)
|
62
|
+
|
63
|
+
expect(create_order_response.success).to eq true
|
64
|
+
|
65
|
+
order = create_order_response.data
|
66
|
+
|
67
|
+
expect(order.id).not_to be_nil
|
68
|
+
expect(order.mass_g).to eq(5_00_000)
|
69
|
+
expect(order.price_cents_usd.to_i).to eq(500)
|
70
|
+
expect(order.patch_fee_cents_usd).not_to be_empty
|
71
|
+
expect(
|
72
|
+
order.price_cents_usd.to_i + order.patch_fee_cents_usd.to_i
|
73
|
+
).to eq(total_price_cents_usd)
|
37
74
|
end
|
38
75
|
|
39
76
|
it 'supports create with metadata' do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
RSpec.describe 'Preferences Integration' do
|
2
2
|
before do
|
3
3
|
Patch.configure do |config|
|
4
|
-
config.access_token = ENV['
|
4
|
+
config.access_token = ENV['SANDBOX_API_KEY']
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -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
|
-
|
14
|
-
|
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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.describe 'Projects Integration' do
|
2
2
|
Patch.configure do |config|
|
3
|
-
config.access_token = ENV['
|
3
|
+
config.access_token = ENV['SANDBOX_API_KEY']
|
4
4
|
end
|
5
5
|
|
6
6
|
it 'supports retrieve and list' do
|
@@ -21,4 +21,22 @@ RSpec.describe 'Projects Integration' do
|
|
21
21
|
retrieve_project_response = Patch::Project.retrieve_project(project_id)
|
22
22
|
expect(retrieve_project_response.data.id).to eq project_id
|
23
23
|
end
|
24
|
+
|
25
|
+
describe 'returned fields' do
|
26
|
+
before do
|
27
|
+
@project = Patch::Project.retrieve_projects(page: 1).data.first
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns photos' do
|
31
|
+
expect(@project.photos).to be_an_instance_of(Array)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns average_price_per_tonne_cents_usd' do
|
35
|
+
expect(@project.average_price_per_tonne_cents_usd).to be_an_instance_of(Integer)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns remaining_mass_g' do
|
39
|
+
expect(@project.remaining_mass_g).to be_an_instance_of(Integer)
|
40
|
+
end
|
41
|
+
end
|
24
42
|
end
|
@@ -20,18 +20,25 @@ require 'date'
|
|
20
20
|
describe 'Allocation' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
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 =
|
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 =
|
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)
|
@@ -20,18 +20,25 @@ require 'date'
|
|
20
20
|
describe 'CreatePreferenceRequest' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
23
|
+
@instance = build(:create_preference_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 } }
|
33
|
+
let(:nullable_properties) { Set.new }
|
34
|
+
end
|
35
|
+
|
30
36
|
describe 'test an instance of CreatePreferenceRequest' do
|
31
37
|
it 'should create an instance of CreatePreferenceRequest' do
|
32
38
|
expect(@instance).to be_instance_of(Patch::CreatePreferenceRequest)
|
33
39
|
end
|
34
40
|
end
|
41
|
+
|
35
42
|
describe 'test attribute "project_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 'ErrorResponse' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
23
|
+
@instance = build(:error_response)
|
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) { { success: @instance.success, error: @instance.error, data: @instance.data } }
|
33
|
+
let(:nullable_properties) { Set.new(["data"]) }
|
34
|
+
end
|
35
|
+
|
30
36
|
describe 'test an instance of ErrorResponse' do
|
31
37
|
it 'should create an instance of ErrorResponse' do
|
32
38
|
expect(@instance).to be_instance_of(Patch::ErrorResponse)
|
@@ -20,13 +20,19 @@ require 'date'
|
|
20
20
|
describe 'EstimateListResponse' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
23
|
+
@instance = build(:estimate_list_response)
|
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) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } }
|
33
|
+
let(:nullable_properties) { Set.new(["error"]) }
|
34
|
+
end
|
35
|
+
|
30
36
|
describe 'test an instance of EstimateListResponse' do
|
31
37
|
it 'should create an instance of EstimateListResponse' do
|
32
38
|
expect(@instance).to be_instance_of(Patch::EstimateListResponse)
|
@@ -20,13 +20,19 @@ require 'date'
|
|
20
20
|
describe 'EstimateResponse' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
23
|
+
@instance = build(:estimate_response)
|
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) { { success: @instance.success, error: @instance.error, data: @instance.data } }
|
33
|
+
let(:nullable_properties) { Set.new(["error"]) }
|
34
|
+
end
|
35
|
+
|
30
36
|
describe 'test an instance of EstimateResponse' do
|
31
37
|
it 'should create an instance of EstimateResponse' do
|
32
38
|
expect(@instance).to be_instance_of(Patch::EstimateResponse)
|
@@ -20,18 +20,25 @@ require 'date'
|
|
20
20
|
describe 'Estimate' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
23
|
+
@instance = build(:estimate)
|
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, order: @instance.order.to_hash, production: @instance.production, type: @instance.type } }
|
33
|
+
let(:nullable_properties) { Set.new(["order"]) }
|
34
|
+
end
|
35
|
+
|
30
36
|
describe 'test an instance of Estimate' do
|
31
37
|
it 'should create an instance of Estimate' do
|
32
38
|
expect(@instance).to be_instance_of(Patch::Estimate)
|
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 'MetaIndexObject' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
23
|
+
@instance = build(:meta_index_object)
|
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) { { next_page: @instance.next_page, prev_page: @instance.prev_page } }
|
33
|
+
let(:nullable_properties) { Set.new(["next_page", "prev_page"]) }
|
34
|
+
end
|
35
|
+
|
30
36
|
describe 'test an instance of MetaIndexObject' do
|
31
37
|
it 'should create an instance of MetaIndexObject' do
|
32
38
|
expect(@instance).to be_instance_of(Patch::MetaIndexObject)
|
@@ -20,13 +20,19 @@ require 'date'
|
|
20
20
|
describe 'OrderListResponse' do
|
21
21
|
before do
|
22
22
|
# run before each test
|
23
|
-
@instance =
|
23
|
+
@instance = build(:order_list_response)
|
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) { { success: @instance.success, error: @instance.error, data: @instance.data, meta: @instance.meta } }
|
33
|
+
let(:nullable_properties) { Set.new(["error"]) }
|
34
|
+
end
|
35
|
+
|
30
36
|
describe 'test an instance of OrderListResponse' do
|
31
37
|
it 'should create an instance of OrderListResponse' do
|
32
38
|
expect(@instance).to be_instance_of(Patch::OrderListResponse)
|