Skip to content

Commit 6f7671b

Browse files
authored
Merge pull request #7 from patch-technology/ta/regenerate-ruby-client
add project_id to estimates and orders
2 parents 91fb163 + f5ed8d8 commit 6f7671b

31 files changed

+619
-294
lines changed

.rubocop.yml

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license)
2+
# Automatically generated by OpenAPI Generator (https://openapi-generator.tech)
3+
AllCops:
4+
TargetRubyVersion: 2.4
5+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
6+
# to ignore them, so only the ones explicitly set in this file are enabled.
7+
DisabledByDefault: true
8+
Exclude:
9+
- '**/templates/**/*'
10+
- '**/vendor/**/*'
11+
- 'actionpack/lib/action_dispatch/journey/parser.rb'
12+
13+
# Prefer &&/|| over and/or.
14+
Style/AndOr:
15+
Enabled: true
16+
17+
# Align `when` with `case`.
18+
Layout/CaseIndentation:
19+
Enabled: true
20+
21+
# Align comments with method definitions.
22+
Layout/CommentIndentation:
23+
Enabled: true
24+
25+
Layout/ElseAlignment:
26+
Enabled: true
27+
28+
Layout/EmptyLineAfterMagicComment:
29+
Enabled: true
30+
31+
# In a regular class definition, no empty lines around the body.
32+
Layout/EmptyLinesAroundClassBody:
33+
Enabled: true
34+
35+
# In a regular method definition, no empty lines around the body.
36+
Layout/EmptyLinesAroundMethodBody:
37+
Enabled: true
38+
39+
# In a regular module definition, no empty lines around the body.
40+
Layout/EmptyLinesAroundModuleBody:
41+
Enabled: true
42+
43+
Layout/FirstArgumentIndentation:
44+
Enabled: true
45+
46+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
47+
Style/HashSyntax:
48+
Enabled: false
49+
50+
# Method definitions after `private` or `protected` isolated calls need one
51+
# extra level of indentation.
52+
Layout/IndentationConsistency:
53+
Enabled: true
54+
EnforcedStyle: indented_internal_methods
55+
56+
# Two spaces, no tabs (for indentation).
57+
Layout/IndentationWidth:
58+
Enabled: true
59+
60+
Layout/LeadingCommentSpace:
61+
Enabled: true
62+
63+
Layout/SpaceAfterColon:
64+
Enabled: true
65+
66+
Layout/SpaceAfterComma:
67+
Enabled: true
68+
69+
Layout/SpaceAroundEqualsInParameterDefault:
70+
Enabled: true
71+
72+
Layout/SpaceAroundKeyword:
73+
Enabled: true
74+
75+
Layout/SpaceAroundOperators:
76+
Enabled: true
77+
78+
Layout/SpaceBeforeComma:
79+
Enabled: true
80+
81+
Layout/SpaceBeforeFirstArg:
82+
Enabled: true
83+
84+
Style/DefWithParentheses:
85+
Enabled: true
86+
87+
# Defining a method with parameters needs parentheses.
88+
Style/MethodDefParentheses:
89+
Enabled: true
90+
91+
Style/FrozenStringLiteralComment:
92+
Enabled: false
93+
EnforcedStyle: always
94+
95+
# Use `foo {}` not `foo{}`.
96+
Layout/SpaceBeforeBlockBraces:
97+
Enabled: true
98+
99+
# Use `foo { bar }` not `foo {bar}`.
100+
Layout/SpaceInsideBlockBraces:
101+
Enabled: true
102+
103+
# Use `{ a: 1 }` not `{a:1}`.
104+
Layout/SpaceInsideHashLiteralBraces:
105+
Enabled: true
106+
107+
Layout/SpaceInsideParens:
108+
Enabled: true
109+
110+
# Check quotes usage according to lint rule below.
111+
#Style/StringLiterals:
112+
# Enabled: true
113+
# EnforcedStyle: single_quotes
114+
115+
# Detect hard tabs, no hard tabs.
116+
Layout/IndentationStyle:
117+
Enabled: true
118+
119+
# Blank lines should not have any spaces.
120+
Layout/TrailingEmptyLines:
121+
Enabled: true
122+
123+
# No trailing whitespace.
124+
Layout/TrailingWhitespace:
125+
Enabled: false
126+
127+
# Use quotes for string literals when they are enough.
128+
Style/RedundantPercentQ:
129+
Enabled: true
130+
131+
# Align `end` with the matching keyword or starting expression except for
132+
# assignments, where it should be aligned with the LHS.
133+
Layout/EndAlignment:
134+
Enabled: true
135+
EnforcedStyleAlignWith: variable
136+
AutoCorrect: true
137+
138+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
139+
Lint/RequireParentheses:
140+
Enabled: true
141+
142+
Style/RedundantReturn:
143+
Enabled: true
144+
AllowMultipleReturnValues: true
145+
146+
Style/Semicolon:
147+
Enabled: true
148+
AllowAsExpressionSeparator: true

CHANGELOG.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.1.0] - 2020-08-19
11+
12+
### Added
13+
14+
- `project_id` optional field to `order` creation
15+
- `metadata` optional field to `order` creation
16+
- `project_id` optional field to `estimate` creation
17+
- changelog file
18+
19+
## [1.0.0] - 2020-07-05
20+
21+
### Added
22+
23+
- This is the first official release of Patch's Ruby Gem.
24+
25+
## [1.0.0.pre] - 2020-07-02
26+
27+
### Added
28+
29+
- Pre-release of v1 Gem
30+
- Adds support for Orders, Estimates, Projects and Preferences
31+

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
patch_ruby (1.0.0)
4+
patch_ruby (1.1.0)
55
json (~> 2.1, >= 2.1.0)
66
typhoeus (~> 1.0, >= 1.0.1)
77

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ In Patch, orders represent a purchase of carbon offsets or negative emissions by
5353
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
5454
Patch::Order.create_order(mass_g: mass)
5555

56+
## You can also specify a project-id field (optional) to be used instead of the preferred one
57+
project_id = 'pro_test_1234' # Pass in the project's ID
58+
Patch::Order.create_order(mass_g: mass, project_id: project_id)
59+
60+
## Orders also accept a metadata field (optional)
61+
metadata = {user: "john doe"}
62+
Patch::Order.create_order(mass_g: mass, metadata: metadata)
63+
5664
# Retrieve an order
5765
order_id = 'ord_test_1234' # Pass in the order's id
5866
Patch::Order.retrieve_order(order_id)
@@ -81,6 +89,10 @@ Estimates allow API users to get a quote for the cost of compensating a certain
8189
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
8290
Patch::Estimate.create_mass_estimate(mass_g: mass)
8391

92+
## You can also specify a project-id field (optional) to be used instead of the preferred one
93+
project_id = 'pro_test_1234' # Pass in the project's ID
94+
Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)
95+
8496
# Retrieve an estimate
8597
estimate_id = 'est_test_1234'
8698
Patch::Estimate.retrieve_estimate(estimate_id)
@@ -129,3 +141,30 @@ Patch::Preference.delete_preference(preference_id)
129141
page = 1 # Pass in which page of preferences you'd like
130142
Patch::Preference.retrieve_preferences(page: page)
131143
```
144+
145+
## Development
146+
147+
To build the gem locally, run:
148+
```
149+
$ gem build patch_ruby.gemspec
150+
```
151+
152+
This will create a .gem file. To install the local gem:
153+
```
154+
$ gem install patch_ruby-1.x.x.gem
155+
```
156+
157+
Install dependencies:
158+
```
159+
$ bundle install
160+
```
161+
162+
Set up required environment variables:
163+
```
164+
$ export PATCH_RUBY_API_KEY=<SANDBOX API KEY>
165+
```
166+
167+
Run tests:
168+
```
169+
$ bundle exec rspec
170+
```

lib/patch_ruby/api/estimates_api.rb

+18-21
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ class EstimatesApi
2525
def initialize(api_client = ApiClient.default)
2626
@api_client = api_client
2727
end
28-
2928
# Create an estimate based on mass of CO2
30-
# Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, linked to the estimate.
31-
# @param create_mass_estimate_request [CreateMassEstimateRequest]
29+
# Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, linked to the estimate.
30+
# @param create_mass_estimate_request [CreateMassEstimateRequest]
3231
# @param [Hash] opts the optional parameters
3332
# @return [EstimateResponse]
3433
def create_mass_estimate(create_mass_estimate_request, opts = {})
@@ -37,8 +36,8 @@ def create_mass_estimate(create_mass_estimate_request, opts = {})
3736
end
3837

3938
# Create an estimate based on mass of CO2
40-
# Creates an estimate for the mass of CO2 to be compensated. An order in the &#x60;draft&#x60; state will also be created, linked to the estimate.
41-
# @param create_mass_estimate_request [CreateMassEstimateRequest]
39+
# Creates an estimate for the mass of CO2 to be compensated. An order in the &#x60;draft&#x60; state will also be created, linked to the estimate.
40+
# @param create_mass_estimate_request [CreateMassEstimateRequest]
4241
# @param [Hash] opts the optional parameters
4342
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
4443
def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
@@ -49,7 +48,6 @@ def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
4948
if @api_client.config.client_side_validation && create_mass_estimate_request.nil?
5049
fail ArgumentError, "Missing the required parameter 'create_mass_estimate_request' when calling EstimatesApi.create_mass_estimate"
5150
end
52-
5351
# resource path
5452
local_var_path = '/v1/estimates/mass'
5553

@@ -67,10 +65,10 @@ def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
6765
form_params = opts[:form_params] || {}
6866

6967
# http body (model)
70-
post_body = opts[:body] || @api_client.object_to_http_body(create_mass_estimate_request)
68+
post_body = opts[:body] || @api_client.object_to_http_body(create_mass_estimate_request)
7169

7270
# return_type
73-
return_type = opts[:return_type] || 'EstimateResponse'
71+
return_type = opts[:return_type] || 'EstimateResponse'
7472

7573
# auth_names
7674
auth_names = opts[:auth_names] || ['bearer_auth']
@@ -92,8 +90,8 @@ def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
9290
end
9391

9492
# Retrieves an estimate
95-
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
96-
# @param id [String]
93+
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
94+
# @param id [String]
9795
# @param [Hash] opts the optional parameters
9896
# @return [EstimateResponse]
9997
def retrieve_estimate(id, opts = {})
@@ -102,8 +100,8 @@ def retrieve_estimate(id, opts = {})
102100
end
103101

104102
# Retrieves an estimate
105-
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
106-
# @param id [String]
103+
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
104+
# @param id [String]
107105
# @param [Hash] opts the optional parameters
108106
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
109107
def retrieve_estimate_with_http_info(id, opts = {})
@@ -114,7 +112,6 @@ def retrieve_estimate_with_http_info(id, opts = {})
114112
if @api_client.config.client_side_validation && id.nil?
115113
fail ArgumentError, "Missing the required parameter 'id' when calling EstimatesApi.retrieve_estimate"
116114
end
117-
118115
# resource path
119116
local_var_path = '/v1/estimates/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))
120117

@@ -130,10 +127,10 @@ def retrieve_estimate_with_http_info(id, opts = {})
130127
form_params = opts[:form_params] || {}
131128

132129
# http body (model)
133-
post_body = opts[:body]
130+
post_body = opts[:body]
134131

135132
# return_type
136-
return_type = opts[:return_type] || 'EstimateResponse'
133+
return_type = opts[:return_type] || 'EstimateResponse'
137134

138135
# auth_names
139136
auth_names = opts[:auth_names] || ['bearer_auth']
@@ -155,19 +152,19 @@ def retrieve_estimate_with_http_info(id, opts = {})
155152
end
156153

157154
# Retrieves a list of estimates
158-
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
155+
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
159156
# @param [Hash] opts the optional parameters
160-
# @option opts [Integer] :page
157+
# @option opts [Integer] :page
161158
# @return [EstimateListResponse]
162159
def retrieve_estimates(opts = {})
163160
data, _status_code, _headers = retrieve_estimates_with_http_info(opts)
164161
data
165162
end
166163

167164
# Retrieves a list of estimates
168-
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
165+
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
169166
# @param [Hash] opts the optional parameters
170-
# @option opts [Integer] :page
167+
# @option opts [Integer] :page
171168
# @return [Array<(EstimateListResponse, Integer, Hash)>] EstimateListResponse data, response status code and response headers
172169
def retrieve_estimates_with_http_info(opts = {})
173170
if @api_client.config.debugging
@@ -189,10 +186,10 @@ def retrieve_estimates_with_http_info(opts = {})
189186
form_params = opts[:form_params] || {}
190187

191188
# http body (model)
192-
post_body = opts[:body]
189+
post_body = opts[:body]
193190

194191
# return_type
195-
return_type = opts[:return_type] || 'EstimateListResponse'
192+
return_type = opts[:return_type] || 'EstimateListResponse'
196193

197194
# auth_names
198195
auth_names = opts[:auth_names] || ['bearer_auth']

0 commit comments

Comments
 (0)