Skip to content

Commit b51bb15

Browse files
author
Rahul Mody
authored
1.21.0 - API Completness (#62)
* 1.21.0 - api completeness changes * changelog * fix specs * deprecation updates * update readme, cleanup spec * fix vehicle estimate expectation
1 parent 12be0e6 commit b51bb15

16 files changed

+1171
-36
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.21.0] - 2022-05-03
9+
10+
### Added
11+
12+
- Adds optional `total_price` and `currency` field to `order` creation
13+
- Adds optional `amount` and `unit` field to `order` creation
14+
- Adds inventory to `project` responses
15+
- Adds inventory to `order` responses
16+
17+
### Changed
18+
19+
- Deprecates `mass_g` and `total_price_cents_usd` fields for create `order` requests
20+
- Deprecates `average_price_per_tonne_cents_usd` and `remaining_mass_g` from `project` responses
21+
- Deprecates `price_cents_usd`, `patch_fee_cents_usd`, and `mass_g` from `order` responses
22+
823
## [1.20.0] - 2022-04-18
924

1025
### Added

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.20.0)
4+
patch_ruby (1.21.0)
55
typhoeus (~> 1.0, >= 1.0.1)
66

77
GEM

README.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ end
5151

5252
### Orders
5353

54-
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.
54+
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.
5555

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

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

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

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

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

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

7981
## Orders also accept a metadata field (optional)
8082
metadata = {user: "john doe"}
81-
Patch::Order.create_order(mass_g: mass, metadata: metadata)
83+
Patch::Order.create_order(amount: amount, unit: unit, metadata: metadata)
8284

8385
# Retrieve an order
8486
order_id = 'ord_test_1234' # Pass in the order's id

lib/patch_ruby.rb

+3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232
require 'patch_ruby/models/estimate_list_response'
3333
require 'patch_ruby/models/estimate_response'
3434
require 'patch_ruby/models/highlight'
35+
require 'patch_ruby/models/inventory'
3536
require 'patch_ruby/models/meta_index_object'
3637
require 'patch_ruby/models/order'
38+
require 'patch_ruby/models/order_inventory'
39+
require 'patch_ruby/models/order_inventory_project'
3740
require 'patch_ruby/models/order_list_response'
3841
require 'patch_ruby/models/order_response'
3942
require 'patch_ruby/models/parent_technology_type'

lib/patch_ruby/api_client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ApiClient
3131
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
3232
def initialize(config = Configuration.default)
3333
@config = config
34-
@user_agent = "patch-ruby/1.20.0"
34+
@user_agent = "patch-ruby/1.21.0"
3535
@default_headers = {
3636
'Content-Type' => 'application/json',
3737
'User-Agent' => @user_agent

lib/patch_ruby/models/create_order_request.rb

+96-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ class CreateOrderRequest
2727

2828
attr_accessor :vintage_year
2929

30+
attr_accessor :total_price
31+
32+
attr_accessor :currency
33+
34+
attr_accessor :amount
35+
36+
attr_accessor :unit
37+
3038
class EnumAttributeValidator
3139
attr_reader :datatype
3240
attr_reader :allowable_values
@@ -57,7 +65,11 @@ def self.attribute_map
5765
:'project_id' => :'project_id',
5866
:'metadata' => :'metadata',
5967
:'state' => :'state',
60-
:'vintage_year' => :'vintage_year'
68+
:'vintage_year' => :'vintage_year',
69+
:'total_price' => :'total_price',
70+
:'currency' => :'currency',
71+
:'amount' => :'amount',
72+
:'unit' => :'unit'
6173
}
6274
end
6375

@@ -74,7 +86,11 @@ def self.openapi_types
7486
:'project_id' => :'String',
7587
:'metadata' => :'Object',
7688
:'state' => :'String',
77-
:'vintage_year' => :'Integer'
89+
:'vintage_year' => :'Integer',
90+
:'total_price' => :'Integer',
91+
:'currency' => :'String',
92+
:'amount' => :'Integer',
93+
:'unit' => :'String'
7894
}
7995
end
8096

@@ -86,7 +102,11 @@ def self.openapi_nullable
86102
:'project_id',
87103
:'metadata',
88104
:'state',
89-
:'vintage_year'
105+
:'vintage_year',
106+
:'total_price',
107+
:'currency',
108+
:'amount',
109+
:'unit'
90110
])
91111
end
92112

@@ -140,6 +160,22 @@ def initialize(attributes = {})
140160
if attributes.key?(:'vintage_year')
141161
self.vintage_year = attributes[:'vintage_year']
142162
end
163+
164+
if attributes.key?(:'total_price')
165+
self.total_price = attributes[:'total_price']
166+
end
167+
168+
if attributes.key?(:'currency')
169+
self.currency = attributes[:'currency']
170+
end
171+
172+
if attributes.key?(:'amount')
173+
self.amount = attributes[:'amount']
174+
end
175+
176+
if attributes.key?(:'unit')
177+
self.unit = attributes[:'unit']
178+
end
143179
end
144180

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

205+
if !@total_price.nil? && @total_price < 1
206+
invalid_properties.push('invalid value for "total_price", must be greater than or equal to 1.')
207+
end
208+
209+
if !@amount.nil? && @amount > 100000000000
210+
invalid_properties.push('invalid value for "amount", must be smaller than or equal to 100000000000.')
211+
end
212+
213+
if !@amount.nil? && @amount < 0
214+
invalid_properties.push('invalid value for "amount", must be greater than or equal to 0.')
215+
end
216+
169217
invalid_properties
170218
end
171219

@@ -179,6 +227,11 @@ def valid?
179227
return false unless state_validator.valid?(@state)
180228
return false if !@vintage_year.nil? && @vintage_year > 2100
181229
return false if !@vintage_year.nil? && @vintage_year < 1900
230+
return false if !@total_price.nil? && @total_price < 1
231+
return false if !@amount.nil? && @amount > 100000000000
232+
return false if !@amount.nil? && @amount < 0
233+
unit_validator = EnumAttributeValidator.new('String', ["g", "Wh"])
234+
return false unless unit_validator.valid?(@unit)
182235
true
183236
end
184237

@@ -230,6 +283,40 @@ def vintage_year=(vintage_year)
230283
@vintage_year = vintage_year
231284
end
232285

286+
# Custom attribute writer method with validation
287+
# @param [Object] total_price Value to be assigned
288+
def total_price=(total_price)
289+
if !total_price.nil? && total_price < 1
290+
fail ArgumentError, 'invalid value for "total_price", must be greater than or equal to 1.'
291+
end
292+
293+
@total_price = total_price
294+
end
295+
296+
# Custom attribute writer method with validation
297+
# @param [Object] amount Value to be assigned
298+
def amount=(amount)
299+
if !amount.nil? && amount > 100000000000
300+
fail ArgumentError, 'invalid value for "amount", must be smaller than or equal to 100000000000.'
301+
end
302+
303+
if !amount.nil? && amount < 0
304+
fail ArgumentError, 'invalid value for "amount", must be greater than or equal to 0.'
305+
end
306+
307+
@amount = amount
308+
end
309+
310+
# Custom attribute writer method checking allowed values (enum).
311+
# @param [Object] unit Object to be assigned
312+
def unit=(unit)
313+
validator = EnumAttributeValidator.new('String', ["g", "Wh"])
314+
unless validator.valid?(unit)
315+
fail ArgumentError, "invalid value for \"unit\", must be one of #{validator.allowable_values}."
316+
end
317+
@unit = unit
318+
end
319+
233320
# Checks equality by comparing each attribute.
234321
# @param [Object] Object to be compared
235322
def ==(o)
@@ -240,7 +327,11 @@ def ==(o)
240327
project_id == o.project_id &&
241328
metadata == o.metadata &&
242329
state == o.state &&
243-
vintage_year == o.vintage_year
330+
vintage_year == o.vintage_year &&
331+
total_price == o.total_price &&
332+
currency == o.currency &&
333+
amount == o.amount &&
334+
unit == o.unit
244335
end
245336

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

258349
# Builds the object from hash

0 commit comments

Comments
 (0)