patch_ruby 1.2.5 → 1.5.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -2
- data/Gemfile.lock +4 -4
- data/README.md +72 -8
- data/lib/patch_ruby.rb +1 -0
- data/lib/patch_ruby/api/estimates_api.rb +195 -0
- data/lib/patch_ruby/api/projects_api.rb +9 -0
- data/lib/patch_ruby/configuration.rb +2 -2
- data/lib/patch_ruby/models/create_mass_estimate_request.rb +17 -6
- data/lib/patch_ruby/models/create_order_request.rb +5 -5
- data/lib/patch_ruby/models/estimate.rb +13 -3
- data/lib/patch_ruby/models/order.rb +5 -5
- data/lib/patch_ruby/models/photo.rb +4 -0
- data/lib/patch_ruby/models/project.rb +21 -7
- data/lib/patch_ruby/models/sdg.rb +269 -0
- data/lib/patch_ruby/version.rb +1 -1
- data/patch_ruby.gemspec +1 -1
- data/spec/configuration_spec.rb +3 -3
- data/spec/integration/estimates_spec.rb +55 -0
- data/spec/integration/orders_spec.rb +6 -5
- data/spec/integration/preferences_spec.rb +6 -2
- data/spec/integration/projects_spec.rb +20 -0
- data/spec/models/create_mass_estimate_request_spec.rb +1 -1
- data/spec/models/project_spec.rb +1 -1
- data/spec/patch_ruby_spec.rb +18 -0
- metadata +35 -32
data/lib/patch_ruby/version.rb
CHANGED
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.
|
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'
|
data/spec/configuration_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
38
|
+
# expect(config.base_url).to eq("https://api.patch.io")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -24,4 +24,59 @@ RSpec.describe 'Estimates Integration' do
|
|
24
24
|
|
25
25
|
expect(estimates.length).not_to be_zero
|
26
26
|
end
|
27
|
+
|
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
|
+
)
|
78
|
+
|
79
|
+
expect(create_estimate_response.data.type).to eq 'shipping'
|
80
|
+
expect(create_estimate_response.data.mass_g).to eq 12_431
|
81
|
+
end
|
27
82
|
end
|
@@ -40,11 +40,12 @@ RSpec.describe 'Orders Integration' do
|
|
40
40
|
|
41
41
|
create_order_response = Patch::Order.create_order(mass_g: order_mass_g, project_id: project_id)
|
42
42
|
|
43
|
+
order = create_order_response.data
|
43
44
|
expect(create_order_response.success).to eq true
|
44
|
-
expect(
|
45
|
-
expect(
|
46
|
-
expect(
|
47
|
-
expect(
|
45
|
+
expect(order.id).not_to be_nil
|
46
|
+
expect(order.mass_g).to eq(order_mass_g)
|
47
|
+
expect(order.price_cents_usd.to_i).to be_between(expected_price - 1, expected_price + 1)
|
48
|
+
expect(order.patch_fee_cents_usd).not_to be_empty
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'supports create with a total price' do
|
@@ -66,7 +67,7 @@ RSpec.describe 'Orders Integration' do
|
|
66
67
|
|
67
68
|
expect(order.id).not_to be_nil
|
68
69
|
expect(order.mass_g).to eq(5_00_000)
|
69
|
-
expect(order.price_cents_usd
|
70
|
+
expect(order.price_cents_usd).not_to be_empty
|
70
71
|
expect(order.patch_fee_cents_usd).not_to be_empty
|
71
72
|
expect(
|
72
73
|
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
|
-
|
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
|
@@ -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
|
@@ -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 }
|
33
|
+
let(:nullable_properties) { Set.new(["create_order"]) }
|
34
34
|
end
|
35
35
|
|
36
36
|
describe 'test an instance of CreateMassEstimateRequest' do
|
data/spec/models/project_spec.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
describe Patch do
|
2
|
+
context 'Models' do
|
3
|
+
it 'defines all models' do
|
4
|
+
constants.each do |constant|
|
5
|
+
expect { Patch.const_get(constant) }.not_to raise_error
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def constants
|
11
|
+
# Given a file path return the constant of that path, for example:
|
12
|
+
# 'lib/patch_ruby/models/project_response.rb' -> ProjectResponse
|
13
|
+
Dir.glob("lib/patch_ruby/models/*.rb").map do |file|
|
14
|
+
parsed_filename = file.split('/').last.split('.').first
|
15
|
+
constant = parsed_filename.split('_').map(&:capitalize).join('')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
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.2
|
4
|
+
version: 1.5.2
|
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-
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/patch_ruby/models/project.rb
|
111
111
|
- lib/patch_ruby/models/project_list_response.rb
|
112
112
|
- lib/patch_ruby/models/project_response.rb
|
113
|
+
- lib/patch_ruby/models/sdg.rb
|
113
114
|
- lib/patch_ruby/models/standard.rb
|
114
115
|
- lib/patch_ruby/version.rb
|
115
116
|
- patch_ruby.gemspec
|
@@ -160,9 +161,10 @@ files:
|
|
160
161
|
- spec/models/project_list_response_spec.rb
|
161
162
|
- spec/models/project_response_spec.rb
|
162
163
|
- spec/models/project_spec.rb
|
164
|
+
- spec/patch_ruby_spec.rb
|
163
165
|
- spec/spec_helper.rb
|
164
166
|
- spec/support/shared/generated_classes.rb
|
165
|
-
homepage: https://www.
|
167
|
+
homepage: https://www.patch.io
|
166
168
|
licenses:
|
167
169
|
- MIT
|
168
170
|
metadata: {}
|
@@ -186,52 +188,53 @@ signing_key:
|
|
186
188
|
specification_version: 4
|
187
189
|
summary: Ruby wrapper for the Patch API
|
188
190
|
test_files:
|
189
|
-
- spec/api/projects_api_spec.rb
|
190
|
-
- spec/api/orders_api_spec.rb
|
191
191
|
- spec/api/preferences_api_spec.rb
|
192
192
|
- spec/api/estimates_api_spec.rb
|
193
|
+
- spec/api/projects_api_spec.rb
|
194
|
+
- spec/api/orders_api_spec.rb
|
193
195
|
- spec/api_client_spec.rb
|
194
196
|
- spec/configuration_spec.rb
|
195
197
|
- spec/constants.rb
|
196
|
-
- spec/factories/estimates.rb
|
197
|
-
- spec/factories/estimate_list_responses.rb
|
198
|
-
- spec/factories/create_order_requests.rb
|
199
|
-
- spec/factories/project_list_responses.rb
|
200
|
-
- spec/factories/order_list_responses.rb
|
201
|
-
- spec/factories/estimate_responses.rb
|
202
|
-
- spec/factories/error_responses.rb
|
203
198
|
- spec/factories/preference_list_responses.rb
|
204
|
-
- spec/factories/preference_responses.rb
|
205
|
-
- spec/factories/meta_index_objects.rb
|
206
199
|
- spec/factories/order_responses.rb
|
207
|
-
- spec/factories/preferences.rb
|
208
|
-
- spec/factories/project_responses.rb
|
209
|
-
- spec/factories/create_preference_requests.rb
|
210
|
-
- spec/factories/orders.rb
|
211
200
|
- spec/factories/projects.rb
|
201
|
+
- spec/factories/error_responses.rb
|
202
|
+
- spec/factories/orders.rb
|
203
|
+
- spec/factories/create_order_requests.rb
|
212
204
|
- spec/factories/create_mass_estimate_requests.rb
|
205
|
+
- spec/factories/project_responses.rb
|
206
|
+
- spec/factories/estimate_list_responses.rb
|
207
|
+
- spec/factories/order_list_responses.rb
|
208
|
+
- spec/factories/create_preference_requests.rb
|
213
209
|
- spec/factories/allocations.rb
|
214
|
-
- spec/
|
210
|
+
- spec/factories/preferences.rb
|
211
|
+
- spec/factories/project_list_responses.rb
|
212
|
+
- spec/factories/estimates.rb
|
213
|
+
- spec/factories/preference_responses.rb
|
214
|
+
- spec/factories/estimate_responses.rb
|
215
|
+
- spec/factories/meta_index_objects.rb
|
215
216
|
- spec/integration/estimates_spec.rb
|
217
|
+
- spec/integration/orders_spec.rb
|
216
218
|
- spec/integration/preferences_spec.rb
|
217
219
|
- spec/integration/projects_spec.rb
|
220
|
+
- spec/models/create_order_request_spec.rb
|
221
|
+
- spec/models/create_mass_estimate_request_spec.rb
|
222
|
+
- spec/models/order_spec.rb
|
223
|
+
- spec/models/allocation_spec.rb
|
224
|
+
- spec/models/order_list_response_spec.rb
|
225
|
+
- spec/models/estimate_list_response_spec.rb
|
218
226
|
- spec/models/error_response_spec.rb
|
219
|
-
- spec/models/
|
227
|
+
- spec/models/project_list_response_spec.rb
|
220
228
|
- spec/models/preference_spec.rb
|
221
|
-
- spec/models/project_response_spec.rb
|
222
|
-
- spec/models/project_spec.rb
|
223
|
-
- spec/models/create_preference_request_spec.rb
|
224
229
|
- spec/models/order_response_spec.rb
|
225
|
-
- spec/models/
|
226
|
-
- spec/models/
|
227
|
-
- spec/models/
|
228
|
-
- spec/models/
|
230
|
+
- spec/models/preference_list_response_spec.rb
|
231
|
+
- spec/models/create_preference_request_spec.rb
|
232
|
+
- spec/models/project_response_spec.rb
|
233
|
+
- spec/models/estimate_spec.rb
|
229
234
|
- spec/models/meta_index_object_spec.rb
|
230
|
-
- spec/models/project_list_response_spec.rb
|
231
235
|
- spec/models/preference_response_spec.rb
|
232
|
-
- spec/models/
|
233
|
-
- spec/models/
|
234
|
-
- spec/
|
235
|
-
- spec/models/create_order_request_spec.rb
|
236
|
+
- spec/models/project_spec.rb
|
237
|
+
- spec/models/estimate_response_spec.rb
|
238
|
+
- spec/patch_ruby_spec.rb
|
236
239
|
- spec/spec_helper.rb
|
237
240
|
- spec/support/shared/generated_classes.rb
|