patch_ruby 1.0.0.pre → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +69 -0
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +13 -12
  5. data/Makefile +10 -0
  6. data/README.md +144 -15
  7. data/lib/patch_ruby.rb +2 -0
  8. data/lib/patch_ruby/models/allocation.rb +15 -0
  9. data/lib/patch_ruby/models/create_mass_estimate_request.rb +41 -4
  10. data/lib/patch_ruby/models/create_order_request.rb +68 -7
  11. data/lib/patch_ruby/models/estimate.rb +15 -0
  12. data/lib/patch_ruby/models/order.rb +85 -4
  13. data/lib/patch_ruby/models/photo.rb +216 -0
  14. data/lib/patch_ruby/models/preference.rb +15 -0
  15. data/lib/patch_ruby/models/project.rb +119 -25
  16. data/lib/patch_ruby/models/standard.rb +244 -0
  17. data/lib/patch_ruby/version.rb +1 -1
  18. data/spec/api/estimates_api_spec.rb +6 -7
  19. data/spec/api/orders_api_spec.rb +10 -11
  20. data/spec/api/preferences_api_spec.rb +8 -9
  21. data/spec/api/projects_api_spec.rb +4 -5
  22. data/spec/api_client_spec.rb +12 -33
  23. data/spec/constants.rb +3 -0
  24. data/spec/integration/estimates_spec.rb +30 -23
  25. data/spec/integration/orders_spec.rb +85 -38
  26. data/spec/integration/preferences_spec.rb +24 -30
  27. data/spec/integration/projects_spec.rb +38 -27
  28. data/spec/models/allocation_spec.rb +0 -1
  29. data/spec/models/create_mass_estimate_request_spec.rb +0 -1
  30. data/spec/models/create_order_request_spec.rb +0 -1
  31. data/spec/models/create_preference_request_spec.rb +0 -1
  32. data/spec/models/error_response_spec.rb +0 -1
  33. data/spec/models/estimate_list_response_spec.rb +0 -1
  34. data/spec/models/estimate_response_spec.rb +0 -1
  35. data/spec/models/estimate_spec.rb +0 -1
  36. data/spec/models/meta_index_object_spec.rb +0 -1
  37. data/spec/models/order_list_response_spec.rb +0 -1
  38. data/spec/models/order_response_spec.rb +0 -1
  39. data/spec/models/order_spec.rb +0 -1
  40. data/spec/models/preference_list_response_spec.rb +0 -1
  41. data/spec/models/preference_response_spec.rb +0 -1
  42. data/spec/models/preference_spec.rb +0 -1
  43. data/spec/models/project_list_response_spec.rb +0 -1
  44. data/spec/models/project_response_spec.rb +0 -1
  45. data/spec/models/project_spec.rb +0 -1
  46. data/spec/spec_helper.rb +1 -11
  47. metadata +26 -30
  48. data/spec/fixtures/vcr_cassettes/estimate_orders.yml +0 -276
  49. data/spec/fixtures/vcr_cassettes/estimates.yml +0 -211
  50. data/spec/fixtures/vcr_cassettes/orders.yml +0 -229
  51. data/spec/fixtures/vcr_cassettes/preferences.yml +0 -352
  52. data/spec/fixtures/vcr_cassettes/projects.yml +0 -143
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adcc2ae16ffd8f1fae30c7231ea100282a46b9cb59fa04ef855d37b3c0269b7e
4
- data.tar.gz: 87c2e5a75eec03a3d05ccca1bc74201e658f3d1bf1a0eec3759b7df3c6815c77
3
+ metadata.gz: 2cc157169de2e66eca8ad5c41897f0345f9bd9286bf8ee62ab6c1040a327d3ff
4
+ data.tar.gz: 5960f6ea41e96264a1293c6b40531817afcd810dd9e5a36988750d94a042c34b
5
5
  SHA512:
6
- metadata.gz: 0d8c3b806824a51b72215cab36372c1608e46c02b3e6ea007f060871da0c3e22e943edffc7484cbe9a9d551685bedd3e14e2eb35b3655e38dd6cfec8f9abcca6
7
- data.tar.gz: b66e6323bfa7932d43d3865b28bc9e09d3cac9a14daa5177fe7a0c1bc5355403e64aed6cee1ba126c5c1fcf3b7c01152dd25408cb7add2742ddf07e20977c129
6
+ metadata.gz: 7053e90b8e96ab75c3c3563146adb3cafa62c370e8c6bf429c7c0ff5e8d90f5020603d4ffb90b63847fd8821e47f5c47ccff1eace9f02734aa40e9053421597f
7
+ data.tar.gz: 589fd1ec70c6ac629bc77d4249d82b0b17205d465909990f8c86992792a661ca972cfa32e666e0a1807c1dff94807d13b9e7c2c293e2becf15bf006a54a2f5af
@@ -0,0 +1,69 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.2.4] - 2020-10-14
11
+
12
+ ### Added
13
+
14
+ - `total_price_cents_usd` field to `orders`
15
+ - allows users to create an order by total price
16
+
17
+ ### Changed
18
+
19
+ - order creation requires either `mass_g` or `total_price_cents_usd`, but not both
20
+
21
+ ## [1.2.3] - 2020-10-05
22
+
23
+ ### Added
24
+
25
+ - `patch_fee_cents_usd` field to `orders`
26
+
27
+ ## [1.2.2] - 2020-09-18
28
+
29
+ ### Added
30
+
31
+ - `photos` field to `projects`
32
+
33
+ ## [1.2.1] - 2020-09-18
34
+
35
+ ### Fixed
36
+
37
+ - Fixing an issue related to the OpenApi code generator.
38
+
39
+ ## [1.2.0] - 2020-09-17
40
+
41
+ ### Added
42
+
43
+ - `average_price_per_tonne_cents_usd` field to `projects`
44
+ - `remaining_mass_g` field to `projects`
45
+ - `standard` field to `projects`
46
+ - validations on `mass_g` field (has to be greater than 1 and less than 2,000,000,000).
47
+
48
+ ## [1.1.0] - 2020-08-19
49
+
50
+ ### Added
51
+
52
+ - `project_id` optional field to `order` creation
53
+ - `metadata` optional field to `order` creation
54
+ - `project_id` optional field to `estimate` creation
55
+ - changelog file
56
+
57
+ ## [1.0.0] - 2020-07-05
58
+
59
+ ### Added
60
+
61
+ - This is the first official release of Patch's Ruby Gem.
62
+
63
+ ## [1.0.0.pre] - 2020-07-02
64
+
65
+ ### Added
66
+
67
+ - Pre-release of v1 Gem
68
+ - Adds support for Orders, Estimates, Projects and Preferences
69
+
data/Gemfile CHANGED
@@ -5,6 +5,5 @@ gemspec
5
5
  group :development, :test do
6
6
  gem 'rake', '~> 13.0.1'
7
7
  gem 'pry-byebug'
8
- gem 'rubocop', '~> 0.66.0'
9
- gem 'vcr', '~> 6.0'
8
+ gem 'rubocop'
10
9
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_ruby (1.0.0.pre)
4
+ patch_ruby (1.2.4)
5
5
  json (~> 2.1, >= 2.1.0)
6
6
  typhoeus (~> 1.0, >= 1.0.1)
7
7
 
@@ -15,7 +15,6 @@ GEM
15
15
  ethon (0.12.0)
16
16
  ffi (>= 1.3.0)
17
17
  ffi (1.13.1)
18
- jaro_winkler (1.5.4)
19
18
  json (2.3.1)
20
19
  method_source (1.0.0)
21
20
  parallel (1.19.2)
@@ -27,9 +26,10 @@ GEM
27
26
  pry-byebug (3.9.0)
28
27
  byebug (~> 11.0)
29
28
  pry (~> 0.13.0)
30
- psych (3.1.0)
31
29
  rainbow (3.0.0)
32
30
  rake (13.0.1)
31
+ regexp_parser (1.7.1)
32
+ rexml (3.2.4)
33
33
  rspec (3.9.0)
34
34
  rspec-core (~> 3.9.0)
35
35
  rspec-expectations (~> 3.9.0)
@@ -43,19 +43,21 @@ GEM
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
44
  rspec-support (~> 3.9.0)
45
45
  rspec-support (3.9.3)
46
- rubocop (0.66.0)
47
- jaro_winkler (~> 1.5.1)
46
+ rubocop (0.88.0)
48
47
  parallel (~> 1.10)
49
- parser (>= 2.5, != 2.5.1.1)
50
- psych (>= 3.1.0)
48
+ parser (>= 2.7.1.1)
51
49
  rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.7)
51
+ rexml
52
+ rubocop-ast (>= 0.1.0, < 1.0)
52
53
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 1.6)
54
+ unicode-display_width (>= 1.4.0, < 2.0)
55
+ rubocop-ast (0.3.0)
56
+ parser (>= 2.7.1.4)
54
57
  ruby-progressbar (1.10.1)
55
58
  typhoeus (1.4.0)
56
59
  ethon (>= 0.9.0)
57
- unicode-display_width (1.5.0)
58
- vcr (6.0.0)
60
+ unicode-display_width (1.7.0)
59
61
 
60
62
  PLATFORMS
61
63
  ruby
@@ -65,8 +67,7 @@ DEPENDENCIES
65
67
  pry-byebug
66
68
  rake (~> 13.0.1)
67
69
  rspec (~> 3.6, >= 3.6.0)
68
- rubocop (~> 0.66.0)
69
- vcr (~> 6.0)
70
+ rubocop
70
71
 
71
72
  BUNDLED WITH
72
73
  2.1.4
@@ -0,0 +1,10 @@
1
+ SHELL = /bin/bash
2
+
3
+ build:
4
+ rubocop -a && \
5
+ bundle install
6
+
7
+ test:
8
+ bundle exec rspec
9
+
10
+ .PHONY: build test
data/README.md CHANGED
@@ -1,11 +1,12 @@
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)
4
+ [![Discord](https://img.shields.io/discord/733029448558837792)](https://discord.gg/AU8543D)
3
5
 
4
6
  The official Ruby gem for the [Patch API](https://www.usepatch.com)
5
7
 
6
8
  ## Documentation
7
-
8
- For detailed documentation and examples, see the [Patch API docs](https://www.usepatch.com).
9
+ For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/)
9
10
 
10
11
  ## Installation
11
12
 
@@ -29,26 +30,154 @@ gem install patch_ruby
29
30
 
30
31
  ## Usage
31
32
 
33
+ ### Configuration
34
+
32
35
  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
36
  ```ruby
34
37
  require 'patch_ruby'
35
38
 
36
39
  Patch.configure do |config|
37
40
  # Configure the Patch gem with your API key here
38
- config.access_token = ENV['PATCH_RUBY_API_KEY']
41
+ config.access_token = ENV['SANDBOX_API_KEY']
39
42
  end
40
43
  ```
41
44
 
42
- Once configured, you can test it out:
45
+ ### Orders
46
+ 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.
47
+
48
+ In Patch, orders represent a purchase of carbon offsets or negative emissions by mass.
49
+ Place orders directly if you know the amount of carbon dioxide you would like to sequester.
50
+ If you do not know how much to purchase, use an estimate.
51
+ You can also create an order with a maximum desired price, and we'll allocate enough mass to
52
+ fulfill the order for you.
53
+
54
+ [API Reference](https://docs.usepatch.com/#/?id=orders)
55
+
56
+ #### Examples
43
57
  ```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
58
+ # Create an order - you can create an order
59
+ # providing either mass_g or total_price_cents_usd, but not both
60
+
61
+ # Create order with mass
62
+ mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
63
+ Patch::Order.create_order(mass_g: mass)
64
+
65
+ # Create an order with maximum total price
66
+ total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
67
+ Patch::Order.create_order(total_price_cents_usd: total_price_cents_usd)
68
+
69
+ ## You can also specify a project-id field (optional) to be used instead of the preferred one
70
+ project_id = 'pro_test_1234' # Pass in the project's ID
71
+ Patch::Order.create_order(mass_g: mass, project_id: project_id)
72
+
73
+ ## Orders also accept a metadata field (optional)
74
+ metadata = {user: "john doe"}
75
+ Patch::Order.create_order(mass_g: mass, metadata: metadata)
76
+
77
+ # Retrieve an order
78
+ order_id = 'ord_test_1234' # Pass in the order's id
79
+ Patch::Order.retrieve_order(order_id)
80
+
81
+ # Place an order
82
+ order_id = 'ord_test_1234' # Pass in the order's id
83
+ Patch::Order.place_order(order_id)
84
+
85
+ # Cancel an order
86
+ order_id = 'ord_test_1234' # Pass in the order's id
87
+ Patch::Order.cancel_order(order_id)
88
+
89
+ # Retrieve a list of orders
90
+ page = 1 # Pass in which page of orders you'd like
91
+ Patch::Order.retrieve_orders(page: page)
92
+ ```
93
+
94
+ ### Estimates
95
+ 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.
96
+
97
+ [API Reference](https://docs.usepatch.com/#/?id=estimates)
98
+
99
+ #### Examples
100
+ ```ruby
101
+ # Create an estimate
102
+ mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
103
+ Patch::Estimate.create_mass_estimate(mass_g: mass)
104
+
105
+ ## You can also specify a project-id field (optional) to be used instead of the preferred one
106
+ project_id = 'pro_test_1234' # Pass in the project's ID
107
+ Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)
108
+
109
+ # Retrieve an estimate
110
+ estimate_id = 'est_test_1234'
111
+ Patch::Estimate.retrieve_estimate(estimate_id)
112
+
113
+ # Retrieve a list of estimates
114
+ page = 1 # Pass in which page of estimates you'd like
115
+ Patch::Estimate.retrieve_estimates(page: page)
116
+ ```
117
+
118
+ ### Projects
119
+ 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.
120
+
121
+ [API Reference](https://docs.usepatch.com/#/?id=projects)
122
+
123
+ #### Examples
124
+ ```ruby
125
+ # Retrieve a project
126
+ project_id = 'pro_test_1234' # Pass in the project's ID
127
+ Patch::Project.retrieve_project(project_id)
128
+
129
+ # Retrieve a list of projects
130
+ page = 1 # Pass in which page of projects you'd like
131
+ Patch::Project.retrieve_projects(page: page)
132
+ ```
133
+
134
+ ### Preferences
135
+ 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](https://dashboard.usepatch.com/projects).
136
+
137
+ [API Reference](https://docs.usepatch.com/#/?id=preferences)
138
+
139
+ #### Examples
140
+ ```ruby
141
+ # Create a preference
142
+ project_id = 'pro_test_1234' # Pass in the project_id for your preference
143
+ Patch::Preference.create_preference(project_id: project_id)
144
+
145
+ # Retrieve a preference
146
+ preference_id = 'pre_test_1234' # Pass in the preferences's id
147
+ Patch::Preference.retrieve_preference(preference_id)
148
+
149
+ # Delete a preference
150
+ preference_id = 'pre_test_1234' # Pass in the preferences's id
151
+ Patch::Preference.delete_preference(preference_id)
152
+
153
+ # Retrieve a list of preferences
154
+ page = 1 # Pass in which page of preferences you'd like
155
+ Patch::Preference.retrieve_preferences(page: page)
156
+ ```
157
+
158
+ ## Development
159
+
160
+ To build the gem locally, run:
161
+ ```
162
+ $ gem build patch_ruby.gemspec
163
+ ```
164
+
165
+ This will create a .gem file. To install the local gem:
166
+ ```
167
+ $ gem install patch_ruby-1.x.x.gem
168
+ ```
169
+
170
+ Install dependencies:
171
+ ```
172
+ $ bundle install
173
+ ```
174
+
175
+ Set up required environment variables:
176
+ ```
177
+ $ export SANDBOX_API_KEY=<SANDBOX API KEY>
178
+ ```
179
+
180
+ Run tests:
181
+ ```
182
+ $ bundle exec rspec
54
183
  ```
@@ -29,12 +29,14 @@ require 'patch_ruby/models/meta_index_object'
29
29
  require 'patch_ruby/models/order'
30
30
  require 'patch_ruby/models/order_list_response'
31
31
  require 'patch_ruby/models/order_response'
32
+ require 'patch_ruby/models/photo'
32
33
  require 'patch_ruby/models/preference'
33
34
  require 'patch_ruby/models/preference_list_response'
34
35
  require 'patch_ruby/models/preference_response'
35
36
  require 'patch_ruby/models/project'
36
37
  require 'patch_ruby/models/project_list_response'
37
38
  require 'patch_ruby/models/project_response'
39
+ require 'patch_ruby/models/standard'
38
40
 
39
41
  # APIs
40
42
  require 'patch_ruby/api/estimates_api'
@@ -81,12 +81,27 @@ module Patch
81
81
  # @return Array for valid properties with the reasons
82
82
  def list_invalid_properties
83
83
  invalid_properties = Array.new
84
+ if @id.nil?
85
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
86
+ end
87
+
88
+ if @production.nil?
89
+ invalid_properties.push('invalid value for "production", production cannot be nil.')
90
+ end
91
+
92
+ if @mass_g.nil?
93
+ invalid_properties.push('invalid value for "mass_g", mass_g cannot be nil.')
94
+ end
95
+
84
96
  invalid_properties
85
97
  end
86
98
 
87
99
  # Check to see if the all the properties in the model are valid
88
100
  # @return true if the model is valid
89
101
  def valid?
102
+ return false if @id.nil?
103
+ return false if @production.nil?
104
+ return false if @mass_g.nil?
90
105
  true
91
106
  end
92
107
 
@@ -16,17 +16,21 @@ module Patch
16
16
  class CreateMassEstimateRequest
17
17
  attr_accessor :mass_g
18
18
 
19
+ attr_accessor :project_id
20
+
19
21
  # Attribute mapping from ruby-style variable name to JSON key.
20
22
  def self.attribute_map
21
23
  {
22
- :'mass_g' => :'mass_g'
24
+ :'mass_g' => :'mass_g',
25
+ :'project_id' => :'project_id'
23
26
  }
24
27
  end
25
28
 
26
29
  # Attribute type mapping.
27
30
  def self.openapi_types
28
31
  {
29
- :'mass_g' => :'Integer'
32
+ :'mass_g' => :'Integer',
33
+ :'project_id' => :'String'
30
34
  }
31
35
  end
32
36
 
@@ -59,6 +63,10 @@ module Patch
59
63
  if attributes.key?(:'mass_g')
60
64
  self.mass_g = attributes[:'mass_g']
61
65
  end
66
+
67
+ if attributes.key?(:'project_id')
68
+ self.project_id = attributes[:'project_id']
69
+ end
62
70
  end
63
71
 
64
72
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -69,6 +77,14 @@ module Patch
69
77
  invalid_properties.push('invalid value for "mass_g", mass_g cannot be nil.')
70
78
  end
71
79
 
80
+ if @mass_g > 2000000000
81
+ invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 2000000000.')
82
+ end
83
+
84
+ if @mass_g < 1
85
+ invalid_properties.push('invalid value for "mass_g", must be greater than or equal to 1.')
86
+ end
87
+
72
88
  invalid_properties
73
89
  end
74
90
 
@@ -76,15 +92,36 @@ module Patch
76
92
  # @return true if the model is valid
77
93
  def valid?
78
94
  return false if @mass_g.nil?
95
+ return false if @mass_g > 2000000000
96
+ return false if @mass_g < 1
79
97
  true
80
98
  end
81
99
 
100
+ # Custom attribute writer method with validation
101
+ # @param [Object] mass_g Value to be assigned
102
+ def mass_g=(mass_g)
103
+ if mass_g.nil?
104
+ fail ArgumentError, 'mass_g cannot be nil'
105
+ end
106
+
107
+ if mass_g > 2000000000
108
+ fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 2000000000.'
109
+ end
110
+
111
+ if mass_g < 1
112
+ fail ArgumentError, 'invalid value for "mass_g", must be greater than or equal to 1.'
113
+ end
114
+
115
+ @mass_g = mass_g
116
+ end
117
+
82
118
  # Checks equality by comparing each attribute.
83
119
  # @param [Object] Object to be compared
84
120
  def ==(o)
85
121
  return true if self.equal?(o)
86
122
  self.class == o.class &&
87
- mass_g == o.mass_g
123
+ mass_g == o.mass_g &&
124
+ project_id == o.project_id
88
125
  end
89
126
 
90
127
  # @see the `==` method
@@ -96,7 +133,7 @@ module Patch
96
133
  # Calculates hash code according to all attributes.
97
134
  # @return [Integer] Hash code
98
135
  def hash
99
- [mass_g].hash
136
+ [mass_g, project_id].hash
100
137
  end
101
138
 
102
139
  # Builds the object from hash