patch_ruby 1.0.0.pre → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adcc2ae16ffd8f1fae30c7231ea100282a46b9cb59fa04ef855d37b3c0269b7e
4
- data.tar.gz: 87c2e5a75eec03a3d05ccca1bc74201e658f3d1bf1a0eec3759b7df3c6815c77
3
+ metadata.gz: e4c502af4271525d9883ffe131279f065edd0a089adcb0acc104271ee427e86a
4
+ data.tar.gz: 0ec3666b9e93a7ad36a810c3d07ed53e1a46162eb566c04f473a572646881405
5
5
  SHA512:
6
- metadata.gz: 0d8c3b806824a51b72215cab36372c1608e46c02b3e6ea007f060871da0c3e22e943edffc7484cbe9a9d551685bedd3e14e2eb35b3655e38dd6cfec8f9abcca6
7
- data.tar.gz: b66e6323bfa7932d43d3865b28bc9e09d3cac9a14daa5177fe7a0c1bc5355403e64aed6cee1ba126c5c1fcf3b7c01152dd25408cb7add2742ddf07e20977c129
6
+ metadata.gz: bcd3e4e634cb5faeeedcc9d3516b075858738d43cb8c1565000b15f95f2539a60d28e48df695030c31499fbeb83e06540a7f485fff4ddc27786ff01028795a9f
7
+ data.tar.gz: eb808b4ca051b0922ffbcb9a98cd50be35795d0beaa01d3bc0811cf39eca0744dc249a4cd289e98761bb1e30673b880eabc135262e0008ac24c7421880a08013
data/Gemfile CHANGED
@@ -6,5 +6,4 @@ group :development, :test do
6
6
  gem 'rake', '~> 13.0.1'
7
7
  gem 'pry-byebug'
8
8
  gem 'rubocop', '~> 0.66.0'
9
- gem 'vcr', '~> 6.0'
10
9
  end
@@ -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 ruby
1
+ # Patch Ruby SDK
2
2
  ![Test](https://github.com/patch-technology/patch-ruby/workflows/Test/badge.svg)
3
+ [![Gem Version](https://badge.fury.io/rb/patch_ruby.svg)](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
- Once configured, you can test it out:
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
- begin
45
- orders_response = Patch::Order.retrieve_orders
46
-
47
- orders_response.data.each do |order|
48
- puts "Order ID: #{order.id}, Order State: #{order.state}"
49
- end
50
- # Rescue from any Patch API errors
51
- rescue Patch::ApiError => e
52
- puts "Failed to retrieve Orders with status code #{e.code}: #{e.message}"
53
- end
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
  ```
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.0.0.pre'
14
+ VERSION = '1.0.0'
15
15
  end
@@ -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 '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
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
- 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
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 "supports create, retrieve and list" do
5
- VCR.use_cassette('estimates') do
6
- # Configure the Patch gem
7
- Patch.configure do |config|
8
- config.access_token = ENV['PATCH_RUBY_API_KEY']
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
- retrieve_estimate_response = Patch::Estimate.retrieve_estimate(estimate_id)
16
- expect(retrieve_estimate_response.data.id).to eq estimate_id
8
+ create_estimate_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
9
+ estimate_id = create_estimate_response.data.id
17
10
 
18
- page_limit = 1
19
- next_page = 1
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
- while !next_page.nil? && next_page <= page_limit
23
- retrieve_estimates_response = Patch::Estimate.retrieve_estimates(page: next_page)
24
- next_page = retrieve_estimates_response.meta.next_page
25
- estimates += retrieve_estimates_response.data
26
- end
14
+ page_limit = 1
15
+ next_page = 1
16
+ estimates = []
27
17
 
28
- expect(estimates.length).not_to be_zero
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
- it "supports create, place, cancel, retrieve and list" do
5
- VCR.use_cassette('orders') do
6
- # Configure the Patch gem
7
- Patch.configure do |config|
8
- config.access_token = ENV['PATCH_RUBY_API_KEY']
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
- # place_order_response = Patch::Order.cancel_order(order_id)
22
- # expect(place_order_response.data.state).to eq 'cancelled'
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
- page_limit = 1
25
- next_page = 1
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
- while !next_page.nil? && next_page <= page_limit
29
- retrieve_orders_response = Patch::Order.retrieve_orders(page: next_page)
30
- next_page = retrieve_orders_response.meta.next_page
31
- orders += retrieve_orders_response.data
32
- end
15
+ page_limit = 1
16
+ next_page = 1
17
+ orders = []
33
18
 
34
- expect(orders.length).not_to be_zero
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 "supports place and cancel for order created via an estimate" do
39
- VCR.use_cassette('estimate_orders') do
40
- create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
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
- place_order_response = Patch::Order.place_order(order_to_place_id)
44
- expect(place_order_response.data.state).to eq 'placed'
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
- create_estimate_to_cancel_response = Patch::Estimate.create_mass_estimate(mass_g: 100)
47
- order_to_cancel_id = create_estimate_to_cancel_response.data.order.id
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
- cancel_order_response = Patch::Order.cancel_order(order_to_cancel_id)
50
- expect(cancel_order_response.data.state).to eq 'cancelled'
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
- it "supports create, delete, retrieve and list" do
5
- VCR.use_cassette('preferences') do
6
- # Configure the Patch gem
7
- Patch.configure do |config|
8
- config.access_token = ENV['PATCH_RUBY_API_KEY']
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
- retrieve_projects_response = Patch::Project.retrieve_projects
13
- expect(retrieve_projects_response.data.length).not_to be_zero
14
- project_id = retrieve_projects_response.data.first.id
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
- create_preference_response = Patch::Preference.create_preference(project_id: project_id)
17
- preference_id = create_preference_response.data.id
13
+ create_preference_response = Patch::Preference.create_preference(project_id: project_id)
14
+ preference_id = create_preference_response.data.id
18
15
 
19
- retrieve_preference_response = Patch::Preference.retrieve_preference(preference_id)
20
- expect(retrieve_preference_response.data.id).to eq preference_id
16
+ retrieve_preference_response = Patch::Preference.retrieve_preference(preference_id)
17
+ expect(retrieve_preference_response.data.id).to eq preference_id
21
18
 
22
- # START receive_preferences
23
- page_limit = 1
24
- next_page = 1
25
- preferences = []
19
+ page_limit = 1
20
+ next_page = 1
21
+ preferences = []
26
22
 
27
- while !next_page.nil? && next_page <= page_limit
28
- retrieve_preferences_response = Patch::Preference.retrieve_preferences(page: next_page)
29
- next_page = retrieve_preferences_response.meta.next_page
30
- preferences += retrieve_preferences_response.data
31
- end
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
- expect(preferences.length).not_to be_zero
34
- # END receive_preferences
29
+ expect(preferences.length).not_to be_zero
35
30
 
36
- delete_preference_response = Patch::Preference.delete_preference(preference_id)
37
- expect(delete_preference_response.data.id).to eq preference_id
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
- it "supports retrieve and list" do
5
- VCR.use_cassette('projects') do
6
- # Configure the Patch gem
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
- # START receive_projects
13
- page_limit = 1
14
- next_page = 1
15
- projects = []
6
+ it 'supports retrieve and list' do
7
+ page_limit = 1
8
+ next_page = 1
9
+ projects = []
16
10
 
17
- while !next_page.nil? && next_page <= page_limit
18
- retrieve_projects_response = Patch::Project.retrieve_projects(page: next_page)
19
- next_page = retrieve_projects_response.meta.next_page
20
- projects += retrieve_projects_response.data
21
- end
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
- expect(projects.length).not_to be_zero
24
- project_id = retrieve_projects_response.data.first.id
25
- # END receive_projects
17
+ expect(projects.length).not_to be_zero
18
+ project_id = retrieve_projects_response.data.first.id
19
+ # END receive_projects
26
20
 
27
- retrieve_project_response = Patch::Project.retrieve_project(project_id)
28
- expect(retrieve_project_response.data.id).to eq project_id
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