Skip to content

Commit

Permalink
1.21.0 - API Completness (#62)
Browse files Browse the repository at this point in the history
* 1.21.0 - api completeness changes

* changelog

* fix specs

* deprecation updates

* update readme, cleanup spec

* fix vehicle estimate expectation
  • Loading branch information
rmody3 committed May 4, 2022
1 parent 12be0e6 commit b51bb15
Show file tree
Hide file tree
Showing 16 changed files with 1,171 additions and 36 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ 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).

## [1.21.0] - 2022-05-03

### Added

- Adds optional `total_price` and `currency` field to `order` creation
- Adds optional `amount` and `unit` field to `order` creation
- Adds inventory to `project` responses
- Adds inventory to `order` responses

### Changed

- Deprecates `mass_g` and `total_price_cents_usd` fields for create `order` requests
- Deprecates `average_price_per_tonne_cents_usd` and `remaining_mass_g` from `project` responses
- Deprecates `price_cents_usd`, `patch_fee_cents_usd`, and `mass_g` from `order` responses

## [1.20.0] - 2022-04-18

### Added
Expand Down
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.20.0)
patch_ruby (1.21.0)
typhoeus (~> 1.0, >= 1.0.1)

GEM
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ end

### Orders

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.
In Patch, orders represent a purchase of carbon offsets or negative emissions by amount. 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.

You can also create an order with a maximum desired price, and we'll allocate enough mass to
You can also create an order with a maximum desired price, and we'll allocate enough to
fulfill the order for you.

[API Reference](https://docs.patch.io/#/?id=orders)
Expand All @@ -62,23 +62,25 @@ fulfill the order for you.

```ruby
# Create an order - you can create an order
# providing either mass_g or total_price_cents_usd, but not both
# providing either amount (and unit) or total_price (and currency), but not both

# Create order with mass
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
Patch::Order.create_order(mass_g: mass)
# Create order with amount
amount = 1_000_000 # Pass in the amount in unit specified
unit = "g"
Patch::Order.create_order(amount: amount, unit: unit)

# Create an order with maximum total price
total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
Patch::Order.create_order(total_price_cents_usd: total_price_cents_usd)
# Create an order with total price
total_price = 5_00 # Pass in the total price in smallest currency unit (ie cents for USD).
currency = "USD"
Patch::Order.create_order(total_price: total_price, currency: currency)

## 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)
Patch::Order.create_order(amount: amount, unit: unit, project_id: project_id)

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

# Retrieve an order
order_id = 'ord_test_1234' # Pass in the order's id
Expand Down
3 changes: 3 additions & 0 deletions lib/patch_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
require 'patch_ruby/models/estimate_list_response'
require 'patch_ruby/models/estimate_response'
require 'patch_ruby/models/highlight'
require 'patch_ruby/models/inventory'
require 'patch_ruby/models/meta_index_object'
require 'patch_ruby/models/order'
require 'patch_ruby/models/order_inventory'
require 'patch_ruby/models/order_inventory_project'
require 'patch_ruby/models/order_list_response'
require 'patch_ruby/models/order_response'
require 'patch_ruby/models/parent_technology_type'
Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ApiClient
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
def initialize(config = Configuration.default)
@config = config
@user_agent = "patch-ruby/1.20.0"
@user_agent = "patch-ruby/1.21.0"
@default_headers = {
'Content-Type' => 'application/json',
'User-Agent' => @user_agent
Expand Down
101 changes: 96 additions & 5 deletions lib/patch_ruby/models/create_order_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class CreateOrderRequest

attr_accessor :vintage_year

attr_accessor :total_price

attr_accessor :currency

attr_accessor :amount

attr_accessor :unit

class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values
Expand Down Expand Up @@ -57,7 +65,11 @@ def self.attribute_map
:'project_id' => :'project_id',
:'metadata' => :'metadata',
:'state' => :'state',
:'vintage_year' => :'vintage_year'
:'vintage_year' => :'vintage_year',
:'total_price' => :'total_price',
:'currency' => :'currency',
:'amount' => :'amount',
:'unit' => :'unit'
}
end

Expand All @@ -74,7 +86,11 @@ def self.openapi_types
:'project_id' => :'String',
:'metadata' => :'Object',
:'state' => :'String',
:'vintage_year' => :'Integer'
:'vintage_year' => :'Integer',
:'total_price' => :'Integer',
:'currency' => :'String',
:'amount' => :'Integer',
:'unit' => :'String'
}
end

Expand All @@ -86,7 +102,11 @@ def self.openapi_nullable
:'project_id',
:'metadata',
:'state',
:'vintage_year'
:'vintage_year',
:'total_price',
:'currency',
:'amount',
:'unit'
])
end

Expand Down Expand Up @@ -140,6 +160,22 @@ def initialize(attributes = {})
if attributes.key?(:'vintage_year')
self.vintage_year = attributes[:'vintage_year']
end

if attributes.key?(:'total_price')
self.total_price = attributes[:'total_price']
end

if attributes.key?(:'currency')
self.currency = attributes[:'currency']
end

if attributes.key?(:'amount')
self.amount = attributes[:'amount']
end

if attributes.key?(:'unit')
self.unit = attributes[:'unit']
end
end

# Show invalid properties with the reasons. Usually used together with valid?
Expand All @@ -166,6 +202,18 @@ def list_invalid_properties
invalid_properties.push('invalid value for "vintage_year", must be greater than or equal to 1900.')
end

if !@total_price.nil? && @total_price < 1
invalid_properties.push('invalid value for "total_price", must be greater than or equal to 1.')
end

if !@amount.nil? && @amount > 100000000000
invalid_properties.push('invalid value for "amount", must be smaller than or equal to 100000000000.')
end

if !@amount.nil? && @amount < 0
invalid_properties.push('invalid value for "amount", must be greater than or equal to 0.')
end

invalid_properties
end

Expand All @@ -179,6 +227,11 @@ def valid?
return false unless state_validator.valid?(@state)
return false if !@vintage_year.nil? && @vintage_year > 2100
return false if !@vintage_year.nil? && @vintage_year < 1900
return false if !@total_price.nil? && @total_price < 1
return false if !@amount.nil? && @amount > 100000000000
return false if !@amount.nil? && @amount < 0
unit_validator = EnumAttributeValidator.new('String', ["g", "Wh"])
return false unless unit_validator.valid?(@unit)
true
end

Expand Down Expand Up @@ -230,6 +283,40 @@ def vintage_year=(vintage_year)
@vintage_year = vintage_year
end

# Custom attribute writer method with validation
# @param [Object] total_price Value to be assigned
def total_price=(total_price)
if !total_price.nil? && total_price < 1
fail ArgumentError, 'invalid value for "total_price", must be greater than or equal to 1.'
end

@total_price = total_price
end

# Custom attribute writer method with validation
# @param [Object] amount Value to be assigned
def amount=(amount)
if !amount.nil? && amount > 100000000000
fail ArgumentError, 'invalid value for "amount", must be smaller than or equal to 100000000000.'
end

if !amount.nil? && amount < 0
fail ArgumentError, 'invalid value for "amount", must be greater than or equal to 0.'
end

@amount = amount
end

# Custom attribute writer method checking allowed values (enum).
# @param [Object] unit Object to be assigned
def unit=(unit)
validator = EnumAttributeValidator.new('String', ["g", "Wh"])
unless validator.valid?(unit)
fail ArgumentError, "invalid value for \"unit\", must be one of #{validator.allowable_values}."
end
@unit = unit
end

# Checks equality by comparing each attribute.
# @param [Object] Object to be compared
def ==(o)
Expand All @@ -240,7 +327,11 @@ def ==(o)
project_id == o.project_id &&
metadata == o.metadata &&
state == o.state &&
vintage_year == o.vintage_year
vintage_year == o.vintage_year &&
total_price == o.total_price &&
currency == o.currency &&
amount == o.amount &&
unit == o.unit
end

# @see the `==` method
Expand All @@ -252,7 +343,7 @@ def eql?(o)
# Calculates hash code according to all attributes.
# @return [Integer] Hash code
def hash
[mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year].hash
[mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year, total_price, currency, amount, unit].hash
end

# Builds the object from hash
Expand Down
Loading

0 comments on commit b51bb15

Please sign in to comment.