Skip to content

Commit f340aee

Browse files
authoredJun 6, 2022
Add issued_to field to Orders APIs (#64)
* Add issued_to field to Orders APIs * Add nullable field * Add gem testing example
1 parent e8d29a0 commit f340aee

17 files changed

+862
-53
lines changed
 

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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.23.0] - 2022-06-03
9+
10+
### Added
11+
12+
- Adds support for the `issued_to` parameter on `orders`, to add support for creating and placing orders on behalf of another party.
13+
814
## [1.22.0] - 2022-05-16
915

1016
### 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.22.0)
4+
patch_ruby (1.23.0)
55
typhoeus (~> 1.0, >= 1.0.1)
66

77
GEM

‎README.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ total_price = 5_00 # Pass in the total price in smallest currency unit (ie cents
7474
currency = "USD"
7575
Patch::Order.create_order(total_price: total_price, currency: currency)
7676

77+
# Create an order with issued_to field (optional)
78+
total_price = 5_00 # Pass in the total price in smallest currency unit (ie cents for USD).
79+
currency = "USD"
80+
issued_to = {email: "envimpact@companya.com", name: "Company A"}
81+
Patch::Order.create_order(total_price: total_price, currency: currency, issued_to: issued_to)
82+
7783
## You can also specify a project-id field (optional) to be used instead of the preferred one
7884
project_id = 'pro_test_1234' # Pass in the project's ID
7985
Patch::Order.create_order(amount: amount, unit: unit, project_id: project_id)
@@ -90,6 +96,11 @@ Patch::Order.retrieve_order(order_id)
9096
order_id = 'ord_test_1234' # Pass in the order's id
9197
Patch::Order.place_order(order_id)
9298

99+
## Placing an order on behalf of another party with the issued_to field (optional)
100+
order_id = 'ord_test_1234' # Pass in the order's id
101+
issued_to = {email: "envimpact@companya.com", name: "Company A"}
102+
Patch::Order.place_order(order_id, issued_to: issued_to)
103+
93104
# Cancel an order
94105
order_id = 'ord_test_1234' # Pass in the order's id
95106
Patch::Order.cancel_order(order_id)
@@ -191,12 +202,12 @@ minimum_available_mass = 100
191202
Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)
192203

193204
# Retrieve a project in a different language
194-
# See http://docs.patch.test:3000/#/internationalization for more information and support
205+
# See http://docs.patch.test:3000/#/internationalization for more information and support
195206
project_id = 'pro_test_1234'
196207
Patch::Project.retrieve_project(project_id, accept_language: 'fr')
197208

198209
# Retrieve a list of projects in a different language
199-
# See http://docs.patch.test:3000/#/internationalization for more information and support
210+
# See http://docs.patch.test:3000/#/internationalization for more information and support
200211
Patch::Project.retrieve_projects(accept_language: 'fr')
201212
```
202213
## Contributing
@@ -219,6 +230,25 @@ This will create a .gem file. To install the local gem:
219230
gem install patch_ruby-1.x.x.gem
220231
```
221232

233+
Once you have installed the gem, you can easily test with `irb`. Here's an example of testing Order creation:
234+
```bash
235+
brett@Bretts-MacBook-Pro patch-ruby $ irb
236+
irb(main):001:0> require 'patch_ruby'
237+
=> true
238+
irb(main):002:0>
239+
irb(main):003:1* Patch.configure do |config|
240+
irb(main):004:1* # Configure the Patch gem with your API key here
241+
irb(main):005:1* config.access_token = ENV['SANDBOX_API_KEY']
242+
irb(main):006:0> end
243+
=> "[REDACTED]"
244+
irb(main):007:0> total_price = 5_00
245+
=> 500
246+
irb(main):008:0> currency = "USD"
247+
=> "USD"
248+
irb(main):009:0> issued_to = {email: "envimpact@companya.com", name: "Company A"}
249+
irb(main):010:0> Patch::Order.create_order(total_price: total_price, currency: currency, issued_to: issued_to)
250+
```
251+
222252
### Running tests
223253

224254
Set up the required environment variable.

‎lib/patch_ruby.rb

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
require 'patch_ruby/models/estimate_response'
3434
require 'patch_ruby/models/highlight'
3535
require 'patch_ruby/models/inventory'
36+
require 'patch_ruby/models/issued_to'
3637
require 'patch_ruby/models/meta_index_object'
3738
require 'patch_ruby/models/order'
3839
require 'patch_ruby/models/order_inventory'
@@ -41,13 +42,15 @@
4142
require 'patch_ruby/models/order_response'
4243
require 'patch_ruby/models/parent_technology_type'
4344
require 'patch_ruby/models/photo'
45+
require 'patch_ruby/models/place_order_request'
4446
require 'patch_ruby/models/project'
4547
require 'patch_ruby/models/project_list_response'
4648
require 'patch_ruby/models/project_response'
4749
require 'patch_ruby/models/sdg'
4850
require 'patch_ruby/models/standard'
4951
require 'patch_ruby/models/technology_type'
5052
require 'patch_ruby/models/technology_type_list_response'
53+
require 'patch_ruby/models/v1_orders_issued_to'
5154

5255
# APIs
5356
require 'patch_ruby/api/estimates_api'

‎lib/patch_ruby/api/orders_api.rb

+41-34
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ def initialize(api_client = ApiClient.default)
2828
@api_client = api_client
2929
end
3030
# Cancel an order
31-
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled.
32-
# @param id [String]
31+
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled.
32+
# @param id [String]
3333
# @param [Hash] opts the optional parameters
3434
# @return [OrderResponse]
3535
def cancel_order(id, opts = {})
36-
36+
3737
data, _status_code, _headers = cancel_order_with_http_info(id, opts)
3838
data
3939
end
4040

4141
# Cancel an order
42-
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled.
43-
# @param id [String]
42+
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled.
43+
# @param id [String]
4444
# @param [Hash] opts the optional parameters
4545
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
4646
def cancel_order_with_http_info(id, opts = {})
@@ -92,19 +92,19 @@ def cancel_order_with_http_info(id, opts = {})
9292
end
9393

9494
# Creates an order
95-
# Creates an order in the `placed` or `draft` state.
96-
# @param create_order_request [CreateOrderRequest]
95+
# Creates an order in the `placed` or `draft` state.
96+
# @param create_order_request [CreateOrderRequest]
9797
# @param [Hash] opts the optional parameters
9898
# @return [OrderResponse]
9999
def create_order(create_order_request = {}, opts = {})
100-
_create_order_request = Patch::CreateOrderRequest.new(create_order_request)
100+
_create_order_request = Patch::CreateOrderRequest.new(create_order_request)
101101
data, _status_code, _headers = create_order_with_http_info(_create_order_request, opts)
102102
data
103103
end
104104

105105
# Creates an order
106-
# Creates an order in the &#x60;placed&#x60; or &#x60;draft&#x60; state.
107-
# @param create_order_request [CreateOrderRequest]
106+
# Creates an order in the &#x60;placed&#x60; or &#x60;draft&#x60; state.
107+
# @param create_order_request [CreateOrderRequest]
108108
# @param [Hash] opts the optional parameters
109109
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
110110
def create_order_with_http_info(create_order_request, opts = {})
@@ -161,20 +161,22 @@ def create_order_with_http_info(create_order_request, opts = {})
161161
end
162162

163163
# Place an order
164-
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
165-
# @param id [String]
164+
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
165+
# @param id [String]
166166
# @param [Hash] opts the optional parameters
167+
# @option opts [PlaceOrderRequest] :place_order_request
167168
# @return [OrderResponse]
168-
def place_order(id, opts = {})
169-
170-
data, _status_code, _headers = place_order_with_http_info(id, opts)
169+
def place_order(id, place_order_request = {}, opts = {})
170+
_place_order_request = Patch::PlaceOrderRequest.new(place_order_request)
171+
data, _status_code, _headers = place_order_with_http_info(id, opts.merge!({place_order_request: place_order_request}))
171172
data
172173
end
173174

174175
# Place an order
175-
# Placing an order confirms an order&#39;s allocation of offsets. Only orders that are in the &#x60;draft&#x60; state can be placed
176-
# @param id [String]
176+
# Placing an order confirms an order&#39;s allocation of offsets. Only orders that are in the &#x60;draft&#x60; state can be placed
177+
# @param id [String]
177178
# @param [Hash] opts the optional parameters
179+
# @option opts [PlaceOrderRequest] :place_order_request
178180
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
179181
def place_order_with_http_info(id, opts = {})
180182
if @api_client.config.debugging
@@ -194,12 +196,17 @@ def place_order_with_http_info(id, opts = {})
194196
header_params = opts[:header_params] || {}
195197
# HTTP header 'Accept' (if needed)
196198
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
199+
# HTTP header 'Content-Type'
200+
content_type = @api_client.select_header_content_type(['application/json'])
201+
if !content_type.nil?
202+
header_params['Content-Type'] = content_type
203+
end
197204

198205
# form parameters
199206
form_params = opts[:form_params] || {}
200207

201208
# http body (model)
202-
post_body = opts[:debug_body]
209+
post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'place_order_request'])
203210

204211
# return_type
205212
return_type = opts[:debug_return_type] || 'OrderResponse'
@@ -225,19 +232,19 @@ def place_order_with_http_info(id, opts = {})
225232
end
226233

227234
# Retrieves an order
228-
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
229-
# @param id [String]
235+
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
236+
# @param id [String]
230237
# @param [Hash] opts the optional parameters
231238
# @return [OrderResponse]
232239
def retrieve_order(id, opts = {})
233-
240+
234241
data, _status_code, _headers = retrieve_order_with_http_info(id, opts)
235242
data
236243
end
237244

238245
# Retrieves an order
239-
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
240-
# @param id [String]
246+
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
247+
# @param id [String]
241248
# @param [Hash] opts the optional parameters
242249
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
243250
def retrieve_order_with_http_info(id, opts = {})
@@ -289,26 +296,26 @@ def retrieve_order_with_http_info(id, opts = {})
289296
end
290297

291298
# Retrieves a list of orders
292-
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
299+
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
293300
# @param [Hash] opts the optional parameters
294-
# @option opts [Integer] :page
295-
# @option opts [String] :metadata
296-
# @option opts [String] :metadata_example1
297-
# @option opts [String] :metadata_example2
301+
# @option opts [Integer] :page
302+
# @option opts [String] :metadata
303+
# @option opts [String] :metadata_example1
304+
# @option opts [String] :metadata_example2
298305
# @return [OrderListResponse]
299306
def retrieve_orders(opts = {})
300-
307+
301308
data, _status_code, _headers = retrieve_orders_with_http_info(opts)
302309
data
303310
end
304311

305312
# Retrieves a list of orders
306-
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
313+
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
307314
# @param [Hash] opts the optional parameters
308-
# @option opts [Integer] :page
309-
# @option opts [String] :metadata
310-
# @option opts [String] :metadata_example1
311-
# @option opts [String] :metadata_example2
315+
# @option opts [Integer] :page
316+
# @option opts [String] :metadata
317+
# @option opts [String] :metadata_example1
318+
# @option opts [String] :metadata_example2
312319
# @return [Array<(OrderListResponse, Integer, Hash)>] OrderListResponse data, response status code and response headers
313320
def retrieve_orders_with_http_info(opts = {})
314321
if @api_client.config.debugging

‎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.22.0"
34+
@user_agent = "patch-ruby/1.23.0"
3535
@default_headers = {
3636
'Content-Type' => 'application/json',
3737
'User-Agent' => @user_agent

‎lib/patch_ruby/models/allocation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Allocation
1818
# A unique uid for the record. UIDs will be prepended by all_prod or all_test depending on the mode it was created in.
1919
attr_accessor :id
2020

21-
# A boolean indicating if this project is a production or test mode project.
21+
# A boolean indicating if this project is a production or demo mode project.
2222
attr_accessor :production
2323

2424
# The amount (in grams) of allocated carbon offsets.

‎lib/patch_ruby/models/create_order_request.rb

+15-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class CreateOrderRequest
3535

3636
attr_accessor :unit
3737

38+
attr_accessor :issued_to
39+
3840
class EnumAttributeValidator
3941
attr_reader :datatype
4042
attr_reader :allowable_values
@@ -69,7 +71,8 @@ def self.attribute_map
6971
:'total_price' => :'total_price',
7072
:'currency' => :'currency',
7173
:'amount' => :'amount',
72-
:'unit' => :'unit'
74+
:'unit' => :'unit',
75+
:'issued_to' => :'issued_to'
7376
}
7477
end
7578

@@ -90,7 +93,8 @@ def self.openapi_types
9093
:'total_price' => :'Integer',
9194
:'currency' => :'String',
9295
:'amount' => :'Integer',
93-
:'unit' => :'String'
96+
:'unit' => :'String',
97+
:'issued_to' => :'V1OrdersIssuedTo'
9498
}
9599
end
96100

@@ -106,7 +110,8 @@ def self.openapi_nullable
106110
:'total_price',
107111
:'currency',
108112
:'amount',
109-
:'unit'
113+
:'unit',
114+
:'issued_to'
110115
])
111116
end
112117

@@ -176,6 +181,10 @@ def initialize(attributes = {})
176181
if attributes.key?(:'unit')
177182
self.unit = attributes[:'unit']
178183
end
184+
185+
if attributes.key?(:'issued_to')
186+
self.issued_to = attributes[:'issued_to']
187+
end
179188
end
180189

181190
# Show invalid properties with the reasons. Usually used together with valid?
@@ -331,7 +340,8 @@ def ==(o)
331340
total_price == o.total_price &&
332341
currency == o.currency &&
333342
amount == o.amount &&
334-
unit == o.unit
343+
unit == o.unit &&
344+
issued_to == o.issued_to
335345
end
336346

337347
# @see the `==` method
@@ -343,7 +353,7 @@ def eql?(o)
343353
# Calculates hash code according to all attributes.
344354
# @return [Integer] Hash code
345355
def hash
346-
[mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year, total_price, currency, amount, unit].hash
356+
[mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year, total_price, currency, amount, unit, issued_to].hash
347357
end
348358

349359
# Builds the object from hash

‎lib/patch_ruby/models/estimate.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Estimate
1818
# A unique uid for the record. UIDs will be prepended by est_prod or est_test depending on the mode it was created in.
1919
attr_accessor :id
2020

21-
# A boolean indicating if this estimate is a production or test mode estimate.
21+
# A boolean indicating if this estimate is a production or demo mode estimate.
2222
attr_accessor :production
2323

2424
# The type of estimate. Available types are mass, flight, shipping, vehicle, and crypto.

‎lib/patch_ruby/models/issued_to.rb

+242
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
=begin
2+
#Patch API V1
3+
4+
#The core API used to integrate with Patch's service
5+
6+
The version of the OpenAPI document: v1
7+
Contact: engineering@usepatch.com
8+
Generated by: https://openapi-generator.tech
9+
OpenAPI Generator version: 5.3.1
10+
11+
=end
12+
13+
require 'date'
14+
require 'time'
15+
16+
module Patch
17+
# An object containing the name & email of the party the inventory will be issued to.
18+
class IssuedTo
19+
# Name provided for the issuee
20+
attr_accessor :name
21+
22+
# Email address provided for the issuee
23+
attr_accessor :email
24+
25+
# Attribute mapping from ruby-style variable name to JSON key.
26+
def self.attribute_map
27+
{
28+
:'name' => :'name',
29+
:'email' => :'email'
30+
}
31+
end
32+
33+
# Returns all the JSON keys this model knows about
34+
def self.acceptable_attributes
35+
attribute_map.values
36+
end
37+
38+
# Attribute type mapping.
39+
def self.openapi_types
40+
{
41+
:'name' => :'String',
42+
:'email' => :'String'
43+
}
44+
end
45+
46+
# List of attributes with nullable: true
47+
def self.openapi_nullable
48+
Set.new([
49+
:'name',
50+
:'email'
51+
])
52+
end
53+
54+
55+
# Allows models with corresponding API classes to delegate API operations to those API classes
56+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
57+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
58+
def self.method_missing(message, *args, &block)
59+
if Object.const_defined?('Patch::IssuedTosApi::OPERATIONS') && Patch::IssuedTosApi::OPERATIONS.include?(message)
60+
Patch::IssuedTosApi.new.send(message, *args)
61+
else
62+
super
63+
end
64+
end
65+
66+
# Initializes the object
67+
# @param [Hash] attributes Model attributes in the form of hash
68+
def initialize(attributes = {})
69+
if (!attributes.is_a?(Hash))
70+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::IssuedTo` initialize method"
71+
end
72+
73+
# check to see if the attribute exists and convert string to symbol for hash key
74+
attributes = attributes.each_with_object({}) { |(k, v), h|
75+
if (!self.class.attribute_map.key?(k.to_sym))
76+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::IssuedTo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
77+
end
78+
h[k.to_sym] = v
79+
}
80+
81+
if attributes.key?(:'name')
82+
self.name = attributes[:'name']
83+
end
84+
85+
if attributes.key?(:'email')
86+
self.email = attributes[:'email']
87+
end
88+
end
89+
90+
# Show invalid properties with the reasons. Usually used together with valid?
91+
# @return Array for valid properties with the reasons
92+
def list_invalid_properties
93+
invalid_properties = Array.new
94+
invalid_properties
95+
end
96+
97+
# Check to see if the all the properties in the model are valid
98+
# @return true if the model is valid
99+
def valid?
100+
true
101+
end
102+
103+
# Checks equality by comparing each attribute.
104+
# @param [Object] Object to be compared
105+
def ==(o)
106+
return true if self.equal?(o)
107+
self.class == o.class &&
108+
name == o.name &&
109+
email == o.email
110+
end
111+
112+
# @see the `==` method
113+
# @param [Object] Object to be compared
114+
def eql?(o)
115+
self == o
116+
end
117+
118+
# Calculates hash code according to all attributes.
119+
# @return [Integer] Hash code
120+
def hash
121+
[name, email].hash
122+
end
123+
124+
# Builds the object from hash
125+
# @param [Hash] attributes Model attributes in the form of hash
126+
# @return [Object] Returns the model itself
127+
def self.build_from_hash(attributes)
128+
new.build_from_hash(attributes)
129+
end
130+
131+
# Builds the object from hash
132+
# @param [Hash] attributes Model attributes in the form of hash
133+
# @return [Object] Returns the model itself
134+
def build_from_hash(attributes)
135+
return nil unless attributes.is_a?(Hash)
136+
self.class.openapi_types.each_pair do |key, type|
137+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
138+
self.send("#{key}=", nil)
139+
elsif type =~ /\AArray<(.*)>/i
140+
# check to ensure the input is an array given that the attribute
141+
# is documented as an array but the input is not
142+
if attributes[self.class.attribute_map[key]].is_a?(Array)
143+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
144+
end
145+
elsif !attributes[self.class.attribute_map[key]].nil?
146+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
147+
end
148+
end
149+
150+
self
151+
end
152+
153+
# Deserializes the data based on type
154+
# @param string type Data type
155+
# @param string value Value to be deserialized
156+
# @return [Object] Deserialized data
157+
def _deserialize(type, value)
158+
case type.to_sym
159+
when :Time
160+
Time.parse(value)
161+
when :Date
162+
Date.parse(value)
163+
when :String
164+
value.to_s
165+
when :Integer
166+
value.to_i
167+
when :Float
168+
value.to_f
169+
when :Boolean
170+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
171+
true
172+
else
173+
false
174+
end
175+
when :Object
176+
# generic object (usually a Hash), return directly
177+
value
178+
when /\AArray<(?<inner_type>.+)>\z/
179+
inner_type = Regexp.last_match[:inner_type]
180+
value.map { |v| _deserialize(inner_type, v) }
181+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
182+
k_type = Regexp.last_match[:k_type]
183+
v_type = Regexp.last_match[:v_type]
184+
{}.tap do |hash|
185+
value.each do |k, v|
186+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
187+
end
188+
end
189+
else # model
190+
# models (e.g. Pet) or oneOf
191+
klass = Patch.const_get(type)
192+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
193+
end
194+
end
195+
196+
# Returns the string representation of the object
197+
# @return [String] String presentation of the object
198+
def to_s
199+
to_hash.to_s
200+
end
201+
202+
# to_body is an alias to to_hash (backward compatibility)
203+
# @return [Hash] Returns the object in the form of hash
204+
def to_body
205+
to_hash
206+
end
207+
208+
# Returns the object in the form of hash
209+
# @return [Hash] Returns the object in the form of hash
210+
def to_hash
211+
hash = {}
212+
self.class.attribute_map.each_pair do |attr, param|
213+
value = self.send(attr)
214+
if value.nil?
215+
is_nullable = self.class.openapi_nullable.include?(attr)
216+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
217+
end
218+
219+
hash[param] = _to_hash(value)
220+
end
221+
hash
222+
end
223+
224+
# Outputs non-array value in the form of hash
225+
# For object, use to_hash. Otherwise, just return the value
226+
# @param [Object] value Any valid value
227+
# @return [Hash] Returns the value in the form of hash
228+
def _to_hash(value)
229+
if value.is_a?(Array)
230+
value.compact.map { |v| _to_hash(v) }
231+
elsif value.is_a?(Hash)
232+
{}.tap do |hash|
233+
value.each { |k, v| hash[k] = _to_hash(v) }
234+
end
235+
elsif value.respond_to? :to_hash
236+
value.to_hash
237+
else
238+
value
239+
end
240+
end
241+
end
242+
end

‎lib/patch_ruby/models/order.rb

+14-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Order
2424
# DEPRECATED, use `amount` and `unit` fields instead. The amount of carbon offsets in grams purchased through this order.
2525
attr_accessor :mass_g
2626

27-
# A boolean indicating if this order is a production or test mode order.
27+
# A boolean indicating if this order is a production or demo mode order.
2828
attr_accessor :production
2929

3030
# The current state of the order.
@@ -66,6 +66,8 @@ class Order
6666
# An array containing the inventory allocated for this order. Inventory is grouped by project, vintage year, and price.
6767
attr_accessor :inventory
6868

69+
attr_accessor :issued_to
70+
6971
class EnumAttributeValidator
7072
attr_reader :datatype
7173
attr_reader :allowable_values
@@ -107,7 +109,8 @@ def self.attribute_map
107109
:'allocations' => :'allocations',
108110
:'registry_url' => :'registry_url',
109111
:'metadata' => :'metadata',
110-
:'inventory' => :'inventory'
112+
:'inventory' => :'inventory',
113+
:'issued_to' => :'issued_to'
111114
}
112115
end
113116

@@ -135,7 +138,8 @@ def self.openapi_types
135138
:'allocations' => :'Array<Allocation>',
136139
:'registry_url' => :'String',
137140
:'metadata' => :'Object',
138-
:'inventory' => :'Array<OrderInventory>'
141+
:'inventory' => :'Array<OrderInventory>',
142+
:'issued_to' => :'IssuedTo'
139143
}
140144
end
141145

@@ -245,6 +249,10 @@ def initialize(attributes = {})
245249
self.inventory = value
246250
end
247251
end
252+
253+
if attributes.key?(:'issued_to')
254+
self.issued_to = attributes[:'issued_to']
255+
end
248256
end
249257

250258
# Show invalid properties with the reasons. Usually used together with valid?
@@ -416,7 +424,8 @@ def ==(o)
416424
allocations == o.allocations &&
417425
registry_url == o.registry_url &&
418426
metadata == o.metadata &&
419-
inventory == o.inventory
427+
inventory == o.inventory &&
428+
issued_to == o.issued_to
420429
end
421430

422431
# @see the `==` method
@@ -428,7 +437,7 @@ def eql?(o)
428437
# Calculates hash code according to all attributes.
429438
# @return [Integer] Hash code
430439
def hash
431-
[id, created_at, mass_g, production, state, amount, unit, price, patch_fee, currency, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, registry_url, metadata, inventory].hash
440+
[id, created_at, mass_g, production, state, amount, unit, price, patch_fee, currency, allocation_state, price_cents_usd, patch_fee_cents_usd, allocations, registry_url, metadata, inventory, issued_to].hash
432441
end
433442

434443
# Builds the object from hash
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
=begin
2+
#Patch API V1
3+
4+
#The core API used to integrate with Patch's service
5+
6+
The version of the OpenAPI document: v1
7+
Contact: engineering@usepatch.com
8+
Generated by: https://openapi-generator.tech
9+
OpenAPI Generator version: 5.3.1
10+
11+
=end
12+
13+
require 'date'
14+
require 'time'
15+
16+
module Patch
17+
class PlaceOrderRequest
18+
attr_accessor :issued_to
19+
20+
# Attribute mapping from ruby-style variable name to JSON key.
21+
def self.attribute_map
22+
{
23+
:'issued_to' => :'issued_to'
24+
}
25+
end
26+
27+
# Returns all the JSON keys this model knows about
28+
def self.acceptable_attributes
29+
attribute_map.values
30+
end
31+
32+
# Attribute type mapping.
33+
def self.openapi_types
34+
{
35+
:'issued_to' => :'V1OrdersIssuedTo'
36+
}
37+
end
38+
39+
# List of attributes with nullable: true
40+
def self.openapi_nullable
41+
Set.new([
42+
:'issued_to'
43+
])
44+
end
45+
46+
47+
# Allows models with corresponding API classes to delegate API operations to those API classes
48+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
49+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
50+
def self.method_missing(message, *args, &block)
51+
if Object.const_defined?('Patch::PlaceOrderRequestsApi::OPERATIONS') && Patch::PlaceOrderRequestsApi::OPERATIONS.include?(message)
52+
Patch::PlaceOrderRequestsApi.new.send(message, *args)
53+
else
54+
super
55+
end
56+
end
57+
58+
# Initializes the object
59+
# @param [Hash] attributes Model attributes in the form of hash
60+
def initialize(attributes = {})
61+
if (!attributes.is_a?(Hash))
62+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::PlaceOrderRequest` initialize method"
63+
end
64+
65+
# check to see if the attribute exists and convert string to symbol for hash key
66+
attributes = attributes.each_with_object({}) { |(k, v), h|
67+
if (!self.class.attribute_map.key?(k.to_sym))
68+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::PlaceOrderRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
69+
end
70+
h[k.to_sym] = v
71+
}
72+
73+
if attributes.key?(:'issued_to')
74+
self.issued_to = attributes[:'issued_to']
75+
end
76+
end
77+
78+
# Show invalid properties with the reasons. Usually used together with valid?
79+
# @return Array for valid properties with the reasons
80+
def list_invalid_properties
81+
invalid_properties = Array.new
82+
invalid_properties
83+
end
84+
85+
# Check to see if the all the properties in the model are valid
86+
# @return true if the model is valid
87+
def valid?
88+
true
89+
end
90+
91+
# Checks equality by comparing each attribute.
92+
# @param [Object] Object to be compared
93+
def ==(o)
94+
return true if self.equal?(o)
95+
self.class == o.class &&
96+
issued_to == o.issued_to
97+
end
98+
99+
# @see the `==` method
100+
# @param [Object] Object to be compared
101+
def eql?(o)
102+
self == o
103+
end
104+
105+
# Calculates hash code according to all attributes.
106+
# @return [Integer] Hash code
107+
def hash
108+
[issued_to].hash
109+
end
110+
111+
# Builds the object from hash
112+
# @param [Hash] attributes Model attributes in the form of hash
113+
# @return [Object] Returns the model itself
114+
def self.build_from_hash(attributes)
115+
new.build_from_hash(attributes)
116+
end
117+
118+
# Builds the object from hash
119+
# @param [Hash] attributes Model attributes in the form of hash
120+
# @return [Object] Returns the model itself
121+
def build_from_hash(attributes)
122+
return nil unless attributes.is_a?(Hash)
123+
self.class.openapi_types.each_pair do |key, type|
124+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
125+
self.send("#{key}=", nil)
126+
elsif type =~ /\AArray<(.*)>/i
127+
# check to ensure the input is an array given that the attribute
128+
# is documented as an array but the input is not
129+
if attributes[self.class.attribute_map[key]].is_a?(Array)
130+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
131+
end
132+
elsif !attributes[self.class.attribute_map[key]].nil?
133+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
134+
end
135+
end
136+
137+
self
138+
end
139+
140+
# Deserializes the data based on type
141+
# @param string type Data type
142+
# @param string value Value to be deserialized
143+
# @return [Object] Deserialized data
144+
def _deserialize(type, value)
145+
case type.to_sym
146+
when :Time
147+
Time.parse(value)
148+
when :Date
149+
Date.parse(value)
150+
when :String
151+
value.to_s
152+
when :Integer
153+
value.to_i
154+
when :Float
155+
value.to_f
156+
when :Boolean
157+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
158+
true
159+
else
160+
false
161+
end
162+
when :Object
163+
# generic object (usually a Hash), return directly
164+
value
165+
when /\AArray<(?<inner_type>.+)>\z/
166+
inner_type = Regexp.last_match[:inner_type]
167+
value.map { |v| _deserialize(inner_type, v) }
168+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
169+
k_type = Regexp.last_match[:k_type]
170+
v_type = Regexp.last_match[:v_type]
171+
{}.tap do |hash|
172+
value.each do |k, v|
173+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
174+
end
175+
end
176+
else # model
177+
# models (e.g. Pet) or oneOf
178+
klass = Patch.const_get(type)
179+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
180+
end
181+
end
182+
183+
# Returns the string representation of the object
184+
# @return [String] String presentation of the object
185+
def to_s
186+
to_hash.to_s
187+
end
188+
189+
# to_body is an alias to to_hash (backward compatibility)
190+
# @return [Hash] Returns the object in the form of hash
191+
def to_body
192+
to_hash
193+
end
194+
195+
# Returns the object in the form of hash
196+
# @return [Hash] Returns the object in the form of hash
197+
def to_hash
198+
hash = {}
199+
self.class.attribute_map.each_pair do |attr, param|
200+
value = self.send(attr)
201+
if value.nil?
202+
is_nullable = self.class.openapi_nullable.include?(attr)
203+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
204+
end
205+
206+
hash[param] = _to_hash(value)
207+
end
208+
hash
209+
end
210+
211+
# Outputs non-array value in the form of hash
212+
# For object, use to_hash. Otherwise, just return the value
213+
# @param [Object] value Any valid value
214+
# @return [Hash] Returns the value in the form of hash
215+
def _to_hash(value)
216+
if value.is_a?(Array)
217+
value.compact.map { |v| _to_hash(v) }
218+
elsif value.is_a?(Hash)
219+
{}.tap do |hash|
220+
value.each { |k, v| hash[k] = _to_hash(v) }
221+
end
222+
elsif value.respond_to? :to_hash
223+
value.to_hash
224+
else
225+
value
226+
end
227+
end
228+
end
229+
end

‎lib/patch_ruby/models/project.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Project
1818
# A unique uid for the record. UIDs will be prepended by pro_prod or pro_test depending on the mode it was created in.
1919
attr_accessor :id
2020

21-
# A boolean indicating if this project is a production or test mode project.
21+
# A boolean indicating if this project is a production or demo mode project.
2222
attr_accessor :production
2323

2424
# The name of the project.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
=begin
2+
#Patch API V1
3+
4+
#The core API used to integrate with Patch's service
5+
6+
The version of the OpenAPI document: v1
7+
Contact: engineering@usepatch.com
8+
Generated by: https://openapi-generator.tech
9+
OpenAPI Generator version: 5.3.1
10+
11+
=end
12+
13+
require 'date'
14+
require 'time'
15+
16+
module Patch
17+
class V1OrdersIssuedTo
18+
attr_accessor :email
19+
20+
attr_accessor :name
21+
22+
# Attribute mapping from ruby-style variable name to JSON key.
23+
def self.attribute_map
24+
{
25+
:'email' => :'email',
26+
:'name' => :'name'
27+
}
28+
end
29+
30+
# Returns all the JSON keys this model knows about
31+
def self.acceptable_attributes
32+
attribute_map.values
33+
end
34+
35+
# Attribute type mapping.
36+
def self.openapi_types
37+
{
38+
:'email' => :'String',
39+
:'name' => :'String'
40+
}
41+
end
42+
43+
# List of attributes with nullable: true
44+
def self.openapi_nullable
45+
Set.new([
46+
:'email',
47+
:'name'
48+
])
49+
end
50+
51+
52+
# Allows models with corresponding API classes to delegate API operations to those API classes
53+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
54+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
55+
def self.method_missing(message, *args, &block)
56+
if Object.const_defined?('Patch::V1OrdersIssuedTosApi::OPERATIONS') && Patch::V1OrdersIssuedTosApi::OPERATIONS.include?(message)
57+
Patch::V1OrdersIssuedTosApi.new.send(message, *args)
58+
else
59+
super
60+
end
61+
end
62+
63+
# Initializes the object
64+
# @param [Hash] attributes Model attributes in the form of hash
65+
def initialize(attributes = {})
66+
if (!attributes.is_a?(Hash))
67+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::V1OrdersIssuedTo` initialize method"
68+
end
69+
70+
# check to see if the attribute exists and convert string to symbol for hash key
71+
attributes = attributes.each_with_object({}) { |(k, v), h|
72+
if (!self.class.attribute_map.key?(k.to_sym))
73+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::V1OrdersIssuedTo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
74+
end
75+
h[k.to_sym] = v
76+
}
77+
78+
if attributes.key?(:'email')
79+
self.email = attributes[:'email']
80+
end
81+
82+
if attributes.key?(:'name')
83+
self.name = attributes[:'name']
84+
end
85+
end
86+
87+
# Show invalid properties with the reasons. Usually used together with valid?
88+
# @return Array for valid properties with the reasons
89+
def list_invalid_properties
90+
invalid_properties = Array.new
91+
invalid_properties
92+
end
93+
94+
# Check to see if the all the properties in the model are valid
95+
# @return true if the model is valid
96+
def valid?
97+
true
98+
end
99+
100+
# Checks equality by comparing each attribute.
101+
# @param [Object] Object to be compared
102+
def ==(o)
103+
return true if self.equal?(o)
104+
self.class == o.class &&
105+
email == o.email &&
106+
name == o.name
107+
end
108+
109+
# @see the `==` method
110+
# @param [Object] Object to be compared
111+
def eql?(o)
112+
self == o
113+
end
114+
115+
# Calculates hash code according to all attributes.
116+
# @return [Integer] Hash code
117+
def hash
118+
[email, name].hash
119+
end
120+
121+
# Builds the object from hash
122+
# @param [Hash] attributes Model attributes in the form of hash
123+
# @return [Object] Returns the model itself
124+
def self.build_from_hash(attributes)
125+
new.build_from_hash(attributes)
126+
end
127+
128+
# Builds the object from hash
129+
# @param [Hash] attributes Model attributes in the form of hash
130+
# @return [Object] Returns the model itself
131+
def build_from_hash(attributes)
132+
return nil unless attributes.is_a?(Hash)
133+
self.class.openapi_types.each_pair do |key, type|
134+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
135+
self.send("#{key}=", nil)
136+
elsif type =~ /\AArray<(.*)>/i
137+
# check to ensure the input is an array given that the attribute
138+
# is documented as an array but the input is not
139+
if attributes[self.class.attribute_map[key]].is_a?(Array)
140+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
141+
end
142+
elsif !attributes[self.class.attribute_map[key]].nil?
143+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
144+
end
145+
end
146+
147+
self
148+
end
149+
150+
# Deserializes the data based on type
151+
# @param string type Data type
152+
# @param string value Value to be deserialized
153+
# @return [Object] Deserialized data
154+
def _deserialize(type, value)
155+
case type.to_sym
156+
when :Time
157+
Time.parse(value)
158+
when :Date
159+
Date.parse(value)
160+
when :String
161+
value.to_s
162+
when :Integer
163+
value.to_i
164+
when :Float
165+
value.to_f
166+
when :Boolean
167+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
168+
true
169+
else
170+
false
171+
end
172+
when :Object
173+
# generic object (usually a Hash), return directly
174+
value
175+
when /\AArray<(?<inner_type>.+)>\z/
176+
inner_type = Regexp.last_match[:inner_type]
177+
value.map { |v| _deserialize(inner_type, v) }
178+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
179+
k_type = Regexp.last_match[:k_type]
180+
v_type = Regexp.last_match[:v_type]
181+
{}.tap do |hash|
182+
value.each do |k, v|
183+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
184+
end
185+
end
186+
else # model
187+
# models (e.g. Pet) or oneOf
188+
klass = Patch.const_get(type)
189+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
190+
end
191+
end
192+
193+
# Returns the string representation of the object
194+
# @return [String] String presentation of the object
195+
def to_s
196+
to_hash.to_s
197+
end
198+
199+
# to_body is an alias to to_hash (backward compatibility)
200+
# @return [Hash] Returns the object in the form of hash
201+
def to_body
202+
to_hash
203+
end
204+
205+
# Returns the object in the form of hash
206+
# @return [Hash] Returns the object in the form of hash
207+
def to_hash
208+
hash = {}
209+
self.class.attribute_map.each_pair do |attr, param|
210+
value = self.send(attr)
211+
if value.nil?
212+
is_nullable = self.class.openapi_nullable.include?(attr)
213+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
214+
end
215+
216+
hash[param] = _to_hash(value)
217+
end
218+
hash
219+
end
220+
221+
# Outputs non-array value in the form of hash
222+
# For object, use to_hash. Otherwise, just return the value
223+
# @param [Object] value Any valid value
224+
# @return [Hash] Returns the value in the form of hash
225+
def _to_hash(value)
226+
if value.is_a?(Array)
227+
value.compact.map { |v| _to_hash(v) }
228+
elsif value.is_a?(Hash)
229+
{}.tap do |hash|
230+
value.each { |k, v| hash[k] = _to_hash(v) }
231+
end
232+
elsif value.respond_to? :to_hash
233+
value.to_hash
234+
else
235+
value
236+
end
237+
end
238+
end
239+
end

‎lib/patch_ruby/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
=end
1212

1313
module Patch
14-
VERSION = '1.22.0'
14+
VERSION = '1.23.0'
1515
end

‎spec/integration/orders_spec.rb

+34
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@
4242
expect(order.registry_url).not_to be_empty
4343
end
4444

45+
it 'supports create with issued_to' do
46+
retrieve_project_response = Patch::Project.retrieve_project(
47+
Constants::BIOMASS_TEST_PROJECT_ID
48+
)
49+
50+
issued_to = {email: 'envimpact@companyb.com', name: 'Company B'}
51+
total_price_cents_usd = 50_00
52+
53+
create_order_response = Patch::Order.create_order(
54+
total_price_cents_usd: total_price_cents_usd,
55+
issued_to: issued_to
56+
)
57+
58+
expect(create_order_response.success).to eq true
59+
60+
order = create_order_response.data
61+
62+
expect(order.id).not_to be_nil
63+
expect(order.price_cents_usd + order.patch_fee_cents_usd).to eq total_price_cents_usd
64+
expect(order.issued_to.email).to eq(issued_to[:email])
65+
expect(order.issued_to.name).to eq(issued_to[:name])
66+
end
67+
4568
it 'supports create with a total price' do
4669
retrieve_project_response = Patch::Project.retrieve_project(
4770
Constants::BIOMASS_TEST_PROJECT_ID
@@ -108,6 +131,17 @@
108131
expect(cancel_order_response.data.state).to eq 'cancelled'
109132
end
110133

134+
it 'supports place order with issued_to' do
135+
create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100, create_order: true)
136+
order_to_place_id = create_estimate_to_place_response.data.order.id
137+
138+
issued_to = {email: 'envimpact@companya.com', name: 'Company A'}
139+
place_order_response = Patch::Order.place_order(order_to_place_id, { issued_to: issued_to})
140+
expect(place_order_response.data.state).to eq 'placed'
141+
expect(place_order_response.data.issued_to.email).to eq(issued_to[:email])
142+
expect(place_order_response.data.issued_to.name).to eq(issued_to[:name])
143+
end
144+
111145
it 'supports create with a vintage year' do
112146
create_order_response =
113147
Patch::Order.create_order(mass_g: 100, vintage_year: 2022)

‎spec/models/create_order_request_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
let(:instance) { @instance }
3232
let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g, total_price_cents_usd: @instance.total_price_cents_usd, metadata: @instance.metadata } }
3333
let(:nullable_properties) do
34-
Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit])
34+
Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit issued_to])
3535
end
3636
end
3737

0 commit comments

Comments
 (0)
Please sign in to comment.