Skip to content

add project_id to estimates and orders #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license)
# Automatically generated by OpenAPI Generator (https://openapi-generator.tech)
AllCops:
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'

# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true

Layout/ElseAlignment:
Enabled: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/FirstArgumentIndentation:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: false

# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: indented_internal_methods

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true

Layout/LeadingCommentSpace:
Enabled: true

Layout/SpaceAfterColon:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true

Layout/SpaceAroundOperators:
Enabled: true

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Style/DefWithParentheses:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: false
EnforcedStyle: always

# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true

# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true

# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
#Style/StringLiterals:
# Enabled: true
# EnforcedStyle: single_quotes

# Detect hard tabs, no hard tabs.
Layout/IndentationStyle:
Enabled: true

# Blank lines should not have any spaces.
Layout/TrailingEmptyLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: false

# Use quotes for string literals when they are enough.
Style/RedundantPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
AutoCorrect: true

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true

Style/RedundantReturn:
Enabled: true
AllowMultipleReturnValues: true

Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.1.0] - 2020-08-19

### Added

- `project_id` optional field to `order` creation
- `metadata` optional field to `order` creation
- `project_id` optional field to `estimate` creation
- changelog file

## [1.0.0] - 2020-07-05

### Added

- This is the first official release of Patch's Ruby Gem.

## [1.0.0.pre] - 2020-07-02

### Added

- Pre-release of v1 Gem
- Adds support for Orders, Estimates, Projects and Preferences

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
patch_ruby (1.0.0)
patch_ruby (1.1.0)
json (~> 2.1, >= 2.1.0)
typhoeus (~> 1.0, >= 1.0.1)

Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ In Patch, orders represent a purchase of carbon offsets or negative emissions by
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
Patch::Order.create_order(mass_g: mass)

## You can also specify a project-id field (optional) to be used instead of the preferred one
project_id = 'pro_test_1234' # Pass in the project's ID
Patch::Order.create_order(mass_g: mass, project_id: project_id)

## Orders also accept a metadata field (optional)
metadata = {user: "john doe"}
Patch::Order.create_order(mass_g: mass, metadata: metadata)

# Retrieve an order
order_id = 'ord_test_1234' # Pass in the order's id
Patch::Order.retrieve_order(order_id)
Expand Down Expand Up @@ -81,6 +89,10 @@ Estimates allow API users to get a quote for the cost of compensating a certain
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
Patch::Estimate.create_mass_estimate(mass_g: mass)

## You can also specify a project-id field (optional) to be used instead of the preferred one
project_id = 'pro_test_1234' # Pass in the project's ID
Patch::Estimate.create_mass_estimate(mass_g: mass, project_id: project_id)

# Retrieve an estimate
estimate_id = 'est_test_1234'
Patch::Estimate.retrieve_estimate(estimate_id)
Expand Down Expand Up @@ -129,3 +141,30 @@ Patch::Preference.delete_preference(preference_id)
page = 1 # Pass in which page of preferences you'd like
Patch::Preference.retrieve_preferences(page: page)
```

## Development

To build the gem locally, run:
```
$ gem build patch_ruby.gemspec
```

This will create a .gem file. To install the local gem:
```
$ gem install patch_ruby-1.x.x.gem
```

Install dependencies:
```
$ bundle install
```

Set up required environment variables:
```
$ export PATCH_RUBY_API_KEY=<SANDBOX API KEY>
```

Run tests:
```
$ bundle exec rspec
```
39 changes: 18 additions & 21 deletions lib/patch_ruby/api/estimates_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ class EstimatesApi
def initialize(api_client = ApiClient.default)
@api_client = api_client
end

# Create an estimate based on mass of CO2
# 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.
# @param create_mass_estimate_request [CreateMassEstimateRequest]
# 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.
# @param create_mass_estimate_request [CreateMassEstimateRequest]
# @param [Hash] opts the optional parameters
# @return [EstimateResponse]
def create_mass_estimate(create_mass_estimate_request, opts = {})
Expand All @@ -37,8 +36,8 @@ def create_mass_estimate(create_mass_estimate_request, opts = {})
end

# Create an estimate based on mass of CO2
# 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.
# @param create_mass_estimate_request [CreateMassEstimateRequest]
# 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.
# @param create_mass_estimate_request [CreateMassEstimateRequest]
# @param [Hash] opts the optional parameters
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
Expand All @@ -49,7 +48,6 @@ def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {})
if @api_client.config.client_side_validation && create_mass_estimate_request.nil?
fail ArgumentError, "Missing the required parameter 'create_mass_estimate_request' when calling EstimatesApi.create_mass_estimate"
end

# resource path
local_var_path = '/v1/estimates/mass'

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

# http body (model)
post_body = opts[:body] || @api_client.object_to_http_body(create_mass_estimate_request)
post_body = opts[:body] || @api_client.object_to_http_body(create_mass_estimate_request)

# return_type
return_type = opts[:return_type] || 'EstimateResponse'
return_type = opts[:return_type] || 'EstimateResponse'

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

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

# Retrieves an estimate
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
# @param id [String]
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers
def retrieve_estimate_with_http_info(id, opts = {})
Expand All @@ -114,7 +112,6 @@ def retrieve_estimate_with_http_info(id, opts = {})
if @api_client.config.client_side_validation && id.nil?
fail ArgumentError, "Missing the required parameter 'id' when calling EstimatesApi.retrieve_estimate"
end

# resource path
local_var_path = '/v1/estimates/{id}'.sub('{' + 'id' + '}', CGI.escape(id.to_s))

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

# http body (model)
post_body = opts[:body]
post_body = opts[:body]

# return_type
return_type = opts[:return_type] || 'EstimateResponse'
return_type = opts[:return_type] || 'EstimateResponse'

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

# Retrieves a list of estimates
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
# @param [Hash] opts the optional parameters
# @option opts [Integer] :page
# @option opts [Integer] :page
# @return [EstimateListResponse]
def retrieve_estimates(opts = {})
data, _status_code, _headers = retrieve_estimates_with_http_info(opts)
data
end

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

# http body (model)
post_body = opts[:body]
post_body = opts[:body]

# return_type
return_type = opts[:return_type] || 'EstimateListResponse'
return_type = opts[:return_type] || 'EstimateListResponse'

# auth_names
auth_names = opts[:auth_names] || ['bearer_auth']
Expand Down
Loading