patch_ruby 1.0.0.pre → 1.0.0
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/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/README.md +90 -14
- data/lib/patch_ruby/version.rb +1 -1
- data/spec/api_client_spec.rb +12 -33
- data/spec/integration/estimates_spec.rb +18 -23
- data/spec/integration/orders_spec.rb +28 -40
- data/spec/integration/preferences_spec.rb +24 -30
- data/spec/integration/projects_spec.rb +17 -24
- data/spec/spec_helper.rb +0 -11
- metadata +4 -14
- data/spec/fixtures/vcr_cassettes/estimate_orders.yml +0 -276
- data/spec/fixtures/vcr_cassettes/estimates.yml +0 -211
- data/spec/fixtures/vcr_cassettes/orders.yml +0 -229
- data/spec/fixtures/vcr_cassettes/preferences.yml +0 -352
- data/spec/fixtures/vcr_cassettes/projects.yml +0 -143
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4c502af4271525d9883ffe131279f065edd0a089adcb0acc104271ee427e86a
|
4
|
+
data.tar.gz: 0ec3666b9e93a7ad36a810c3d07ed53e1a46162eb566c04f473a572646881405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcd3e4e634cb5faeeedcc9d3516b075858738d43cb8c1565000b15f95f2539a60d28e48df695030c31499fbeb83e06540a7f485fff4ddc27786ff01028795a9f
|
7
|
+
data.tar.gz: eb808b4ca051b0922ffbcb9a98cd50be35795d0beaa01d3bc0811cf39eca0744dc249a4cd289e98761bb1e30673b880eabc135262e0008ac24c7421880a08013
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -55,7 +55,6 @@ GEM
|
|
55
55
|
typhoeus (1.4.0)
|
56
56
|
ethon (>= 0.9.0)
|
57
57
|
unicode-display_width (1.5.0)
|
58
|
-
vcr (6.0.0)
|
59
58
|
|
60
59
|
PLATFORMS
|
61
60
|
ruby
|
@@ -66,7 +65,6 @@ DEPENDENCIES
|
|
66
65
|
rake (~> 13.0.1)
|
67
66
|
rspec (~> 3.6, >= 3.6.0)
|
68
67
|
rubocop (~> 0.66.0)
|
69
|
-
vcr (~> 6.0)
|
70
68
|
|
71
69
|
BUNDLED WITH
|
72
70
|
2.1.4
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# Patch
|
1
|
+
# Patch Ruby SDK
|
2
2
|

|
3
|
+
[](https://badge.fury.io/rb/patch_ruby)
|
3
4
|
|
4
5
|
The official Ruby gem for the [Patch API](https://www.usepatch.com)
|
5
6
|
|
6
7
|
## Documentation
|
7
|
-
|
8
|
-
For detailed documentation and examples, see the [Patch API docs](https://www.usepatch.com).
|
8
|
+
For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml)
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -29,6 +29,8 @@ gem install patch_ruby
|
|
29
29
|
|
30
30
|
## Usage
|
31
31
|
|
32
|
+
### Configuration
|
33
|
+
|
32
34
|
After installing the gem, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:
|
33
35
|
```ruby
|
34
36
|
require 'patch_ruby'
|
@@ -39,16 +41,90 @@ Patch.configure do |config|
|
|
39
41
|
end
|
40
42
|
```
|
41
43
|
|
42
|
-
|
44
|
+
### Orders
|
45
|
+
In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
|
46
|
+
|
47
|
+
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1orders/get)
|
48
|
+
|
49
|
+
#### Examples
|
43
50
|
```ruby
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
# Create an order
|
52
|
+
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
|
53
|
+
Patch::Order.create_order(mass_g: mass)
|
54
|
+
|
55
|
+
# Retrieve an order
|
56
|
+
order_id = 'ord_test_1234' # Pass in the order's id
|
57
|
+
Patch::Order.retrieve_order(order_id)
|
58
|
+
|
59
|
+
# Place an order
|
60
|
+
order_id = 'ord_test_1234' # Pass in the order's id
|
61
|
+
Patch::Order.place_order(order_id)
|
62
|
+
|
63
|
+
# Cancel an order
|
64
|
+
order_id = 'ord_test_1234' # Pass in the order's id
|
65
|
+
Patch::Order.cancel_order(order_id)
|
66
|
+
|
67
|
+
# Retrieve a list of orders
|
68
|
+
page = 1 # Pass in which page of orders you'd like
|
69
|
+
Patch::Order.retrieve_orders(page: page)
|
70
|
+
```
|
71
|
+
|
72
|
+
### Estimates
|
73
|
+
Estimates allow API users to get a quote for the cost of compensating a certain amount of CO2. When creating an estimate, an order in the `draft` state will also be created, reserving the allocation of a project for 5 minutes. If you don't place your draft order within those 5 minutes, the order will automatically be cancelled.
|
74
|
+
|
75
|
+
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1estimates/get)
|
76
|
+
|
77
|
+
#### Examples
|
78
|
+
```ruby
|
79
|
+
# Create an estimate
|
80
|
+
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
|
81
|
+
Patch::Estimate.create_mass_estimate(mass_g: mass)
|
82
|
+
|
83
|
+
# Retrieve an estimate
|
84
|
+
estimate_id = 'est_test_1234'
|
85
|
+
Patch::Estimate.retrieve_estimate(estimate_id)
|
86
|
+
|
87
|
+
# Retrieve a list of estimates
|
88
|
+
page = 1 # Pass in which page of estimates you'd like
|
89
|
+
Patch::Estimate.retrieve_estimates(page: page)
|
90
|
+
```
|
91
|
+
|
92
|
+
### Projects
|
93
|
+
Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.
|
94
|
+
|
95
|
+
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1projects/get)
|
96
|
+
|
97
|
+
#### Examples
|
98
|
+
```ruby
|
99
|
+
# Retrieve a project
|
100
|
+
project_id = 'pro_test_1234' # Pass in the project's ID
|
101
|
+
Patch::Project.retrieve_project(project_id)
|
102
|
+
|
103
|
+
# Retrieve a list of projects
|
104
|
+
page = 1 # Pass in which page of projects you'd like
|
105
|
+
Patch::Project.retrieve_projects(page: page)
|
106
|
+
```
|
107
|
+
|
108
|
+
### Preferences
|
109
|
+
Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](dashboard.usepatch.com/projects).
|
110
|
+
|
111
|
+
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1preferences/post)
|
112
|
+
|
113
|
+
#### Examples
|
114
|
+
```ruby
|
115
|
+
# Create a preference
|
116
|
+
project_id = 'pro_test_1234' # Pass in the project_id for your preference
|
117
|
+
Patch::Preference.create_preference(project_id: project_id)
|
118
|
+
|
119
|
+
# Retrieve a preference
|
120
|
+
preference_id = 'pre_test_1234' # Pass in the preferences's id
|
121
|
+
Patch::Preference.retrieve_preference(preference_id)
|
122
|
+
|
123
|
+
# Delete a preference
|
124
|
+
preference_id = 'pre_test_1234' # Pass in the preferences's id
|
125
|
+
Patch::Preference.delete_preference(preference_id)
|
126
|
+
|
127
|
+
# Retrieve a list of preferences
|
128
|
+
page = 1 # Pass in which page of preferences you'd like
|
129
|
+
Patch::Preference.retrieve_preferences(page: page)
|
54
130
|
```
|
data/lib/patch_ruby/version.rb
CHANGED
data/spec/api_client_spec.rb
CHANGED
@@ -10,43 +10,22 @@ OpenAPI Generator version: 4.3.1
|
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
13
|
-
require 'spec_helper'
|
14
|
-
|
15
13
|
describe Patch::ApiClient do
|
16
14
|
context 'initialization' do
|
17
|
-
context '
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
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')
|
33
24
|
end
|
34
25
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
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('')
|
50
29
|
end
|
51
30
|
end
|
52
31
|
end
|
@@ -1,31 +1,26 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe 'Estimates Integration' do
|
4
|
-
it
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
config.host = ENV['PATCH_RUBY_HOST']
|
10
|
-
end
|
11
|
-
|
12
|
-
create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
|
13
|
-
estimate_id = create_estimate_response.data.id
|
2
|
+
it 'supports create, retrieve and list' do
|
3
|
+
# Configure the Patch gem
|
4
|
+
Patch.configure do |config|
|
5
|
+
config.access_token = ENV['PATCH_RUBY_API_KEY']
|
6
|
+
end
|
14
7
|
|
15
|
-
|
16
|
-
|
8
|
+
create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
|
9
|
+
estimate_id = create_estimate_response.data.id
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
estimates = []
|
11
|
+
retrieve_estimate_response = Patch::Estimate.retrieve_estimate(estimate_id)
|
12
|
+
expect(retrieve_estimate_response.data.id).to eq estimate_id
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
estimates += retrieve_estimates_response.data
|
26
|
-
end
|
14
|
+
page_limit = 1
|
15
|
+
next_page = 1
|
16
|
+
estimates = []
|
27
17
|
|
28
|
-
|
18
|
+
while !next_page.nil? && next_page <= page_limit
|
19
|
+
retrieve_estimates_response = Patch::Estimate.retrieve_estimates(page: next_page)
|
20
|
+
next_page = retrieve_estimates_response.meta.next_page
|
21
|
+
estimates += retrieve_estimates_response.data
|
29
22
|
end
|
23
|
+
|
24
|
+
expect(estimates.length).not_to be_zero
|
30
25
|
end
|
31
26
|
end
|
@@ -1,53 +1,41 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe 'Orders Integration' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
config.host = ENV['PATCH_RUBY_HOST']
|
10
|
-
end
|
11
|
-
|
12
|
-
create_order_response = Patch::Order.create_order(mass_g: 100)
|
13
|
-
order_id = create_order_response.data.id
|
14
|
-
|
15
|
-
retrieve_order_response = Patch::Order.retrieve_order(order_id)
|
16
|
-
expect(retrieve_order_response.data.id).to eq order_id
|
17
|
-
|
18
|
-
# place_order_response = Patch::Order.place_order(order_id)
|
19
|
-
# expect(place_order_response.data.state).to eq 'placed'
|
2
|
+
before do
|
3
|
+
Patch.configure do |config|
|
4
|
+
config.access_token = ENV['PATCH_RUBY_API_KEY']
|
5
|
+
end
|
6
|
+
end
|
20
7
|
|
21
|
-
|
22
|
-
|
8
|
+
it 'supports create, place, cancel, retrieve and list' do
|
9
|
+
create_order_response = Patch::Order.create_order(mass_g: 100)
|
10
|
+
order_id = create_order_response.data.id
|
23
11
|
|
24
|
-
|
25
|
-
|
26
|
-
orders = []
|
12
|
+
retrieve_order_response = Patch::Order.retrieve_order(order_id)
|
13
|
+
expect(retrieve_order_response.data.id).to eq order_id
|
27
14
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
orders += retrieve_orders_response.data
|
32
|
-
end
|
15
|
+
page_limit = 1
|
16
|
+
next_page = 1
|
17
|
+
orders = []
|
33
18
|
|
34
|
-
|
19
|
+
while !next_page.nil? && next_page <= page_limit
|
20
|
+
retrieve_orders_response = Patch::Order.retrieve_orders(page: next_page)
|
21
|
+
next_page = retrieve_orders_response.meta.next_page
|
22
|
+
orders += retrieve_orders_response.data
|
35
23
|
end
|
24
|
+
|
25
|
+
expect(orders.length).not_to be_zero
|
36
26
|
end
|
37
27
|
|
38
|
-
it
|
39
|
-
|
40
|
-
|
41
|
-
order_to_place_id = create_estimate_to_place_response.data.order.id
|
28
|
+
it 'supports place and cancel for orders created via an estimate' do
|
29
|
+
create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
|
30
|
+
order_to_place_id = create_estimate_to_place_response.data.order.id
|
42
31
|
|
43
|
-
|
44
|
-
|
32
|
+
place_order_response = Patch::Order.place_order(order_to_place_id)
|
33
|
+
expect(place_order_response.data.state).to eq 'placed'
|
45
34
|
|
46
|
-
|
47
|
-
|
35
|
+
create_estimate_to_cancel_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
|
36
|
+
order_to_cancel_id = create_estimate_to_cancel_response.data.order.id
|
48
37
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
38
|
+
cancel_order_response = Patch::Order.cancel_order(order_to_cancel_id)
|
39
|
+
expect(cancel_order_response.data.state).to eq 'cancelled'
|
52
40
|
end
|
53
41
|
end
|
@@ -1,40 +1,34 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe 'Preferences Integration' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
config.host = ENV['PATCH_RUBY_HOST']
|
10
|
-
end
|
2
|
+
before do
|
3
|
+
Patch.configure do |config|
|
4
|
+
config.access_token = ENV['PATCH_RUBY_API_KEY']
|
5
|
+
end
|
6
|
+
end
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
it 'supports create, delete, retrieve and list' do
|
9
|
+
retrieve_projects_response = Patch::Project.retrieve_projects
|
10
|
+
expect(retrieve_projects_response.data.length).not_to be_zero
|
11
|
+
project_id = retrieve_projects_response.data.first.id
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
create_preference_response = Patch::Preference.create_preference(project_id: project_id)
|
14
|
+
preference_id = create_preference_response.data.id
|
18
15
|
|
19
|
-
|
20
|
-
|
16
|
+
retrieve_preference_response = Patch::Preference.retrieve_preference(preference_id)
|
17
|
+
expect(retrieve_preference_response.data.id).to eq preference_id
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
preferences = []
|
19
|
+
page_limit = 1
|
20
|
+
next_page = 1
|
21
|
+
preferences = []
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
while !next_page.nil? && next_page <= page_limit
|
24
|
+
retrieve_preferences_response = Patch::Preference.retrieve_preferences(page: next_page)
|
25
|
+
next_page = retrieve_preferences_response.meta.next_page
|
26
|
+
preferences += retrieve_preferences_response.data
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
# END receive_preferences
|
29
|
+
expect(preferences.length).not_to be_zero
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
31
|
+
delete_preference_response = Patch::Preference.delete_preference(preference_id)
|
32
|
+
expect(delete_preference_response.data.id).to eq preference_id
|
39
33
|
end
|
40
34
|
end
|
@@ -1,31 +1,24 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe 'Projects Integration' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Patch.configure do |config|
|
8
|
-
config.access_token = ENV['PATCH_RUBY_API_KEY']
|
9
|
-
config.host = ENV['PATCH_RUBY_HOST']
|
10
|
-
end
|
2
|
+
Patch.configure do |config|
|
3
|
+
config.access_token = ENV['PATCH_RUBY_API_KEY']
|
4
|
+
end
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
it 'supports retrieve and list' do
|
7
|
+
page_limit = 1
|
8
|
+
next_page = 1
|
9
|
+
projects = []
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
while !next_page.nil? && next_page <= page_limit
|
12
|
+
retrieve_projects_response = Patch::Project.retrieve_projects(page: next_page)
|
13
|
+
next_page = retrieve_projects_response.meta.next_page
|
14
|
+
projects += retrieve_projects_response.data
|
15
|
+
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
expect(projects.length).not_to be_zero
|
18
|
+
project_id = retrieve_projects_response.data.first.id
|
19
|
+
# END receive_projects
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
21
|
+
retrieve_project_response = Patch::Project.retrieve_project(project_id)
|
22
|
+
expect(retrieve_project_response.data.id).to eq project_id
|
30
23
|
end
|
31
24
|
end
|