Skip to content

Commit

Permalink
Add issued_to field to Orders APIs (#64)
Browse files Browse the repository at this point in the history
* Add issued_to field to Orders APIs

* Add nullable field

* Add gem testing example
  • Loading branch information
holtbp authored Jun 6, 2022
1 parent e8d29a0 commit f340aee
Show file tree
Hide file tree
Showing 17 changed files with 862 additions and 53 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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.23.0] - 2022-06-03

### Added

- Adds support for the `issued_to` parameter on `orders`, to add support for creating and placing orders on behalf of another party.

## [1.22.0] - 2022-05-16

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

GEM
Expand Down
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ total_price = 5_00 # Pass in the total price in smallest currency unit (ie cents
currency = "USD"
Patch::Order.create_order(total_price: total_price, currency: currency)

# Create an order with issued_to field (optional)
total_price = 5_00 # Pass in the total price in smallest currency unit (ie cents for USD).
currency = "USD"
issued_to = {email: "envimpact@companya.com", name: "Company A"}
Patch::Order.create_order(total_price: total_price, currency: currency, issued_to: issued_to)

## 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(amount: amount, unit: unit, project_id: project_id)
Expand All @@ -90,6 +96,11 @@ Patch::Order.retrieve_order(order_id)
order_id = 'ord_test_1234' # Pass in the order's id
Patch::Order.place_order(order_id)

## Placing an order on behalf of another party with the issued_to field (optional)
order_id = 'ord_test_1234' # Pass in the order's id
issued_to = {email: "envimpact@companya.com", name: "Company A"}
Patch::Order.place_order(order_id, issued_to: issued_to)

# Cancel an order
order_id = 'ord_test_1234' # Pass in the order's id
Patch::Order.cancel_order(order_id)
Expand Down Expand Up @@ -191,12 +202,12 @@ minimum_available_mass = 100
Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)

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

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

Once you have installed the gem, you can easily test with `irb`. Here's an example of testing Order creation:
```bash
brett@Bretts-MacBook-Pro patch-ruby $ irb
irb(main):001:0> require 'patch_ruby'
=> true
irb(main):002:0>
irb(main):003:1* Patch.configure do |config|
irb(main):004:1* # Configure the Patch gem with your API key here
irb(main):005:1* config.access_token = ENV['SANDBOX_API_KEY']
irb(main):006:0> end
=> "[REDACTED]"
irb(main):007:0> total_price = 5_00
=> 500
irb(main):008:0> currency = "USD"
=> "USD"
irb(main):009:0> issued_to = {email: "envimpact@companya.com", name: "Company A"}
irb(main):010:0> Patch::Order.create_order(total_price: total_price, currency: currency, issued_to: issued_to)
```

### Running tests

Set up the required environment variable.
Expand Down
3 changes: 3 additions & 0 deletions lib/patch_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
require 'patch_ruby/models/estimate_response'
require 'patch_ruby/models/highlight'
require 'patch_ruby/models/inventory'
require 'patch_ruby/models/issued_to'
require 'patch_ruby/models/meta_index_object'
require 'patch_ruby/models/order'
require 'patch_ruby/models/order_inventory'
Expand All @@ -41,13 +42,15 @@
require 'patch_ruby/models/order_response'
require 'patch_ruby/models/parent_technology_type'
require 'patch_ruby/models/photo'
require 'patch_ruby/models/place_order_request'
require 'patch_ruby/models/project'
require 'patch_ruby/models/project_list_response'
require 'patch_ruby/models/project_response'
require 'patch_ruby/models/sdg'
require 'patch_ruby/models/standard'
require 'patch_ruby/models/technology_type'
require 'patch_ruby/models/technology_type_list_response'
require 'patch_ruby/models/v1_orders_issued_to'

# APIs
require 'patch_ruby/api/estimates_api'
Expand Down
75 changes: 41 additions & 34 deletions lib/patch_ruby/api/orders_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# Cancel an order
# 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.
# @param id [String]
# 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.
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [OrderResponse]
def cancel_order(id, opts = {})

data, _status_code, _headers = cancel_order_with_http_info(id, opts)
data
end

# Cancel an order
# 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.
# @param id [String]
# 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.
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers
def cancel_order_with_http_info(id, opts = {})
Expand Down Expand Up @@ -92,19 +92,19 @@ def cancel_order_with_http_info(id, opts = {})
end

# Creates an order
# Creates an order in the `placed` or `draft` state.
# @param create_order_request [CreateOrderRequest]
# Creates an order in the `placed` or `draft` state.
# @param create_order_request [CreateOrderRequest]
# @param [Hash] opts the optional parameters
# @return [OrderResponse]
def create_order(create_order_request = {}, opts = {})
_create_order_request = Patch::CreateOrderRequest.new(create_order_request)
_create_order_request = Patch::CreateOrderRequest.new(create_order_request)
data, _status_code, _headers = create_order_with_http_info(_create_order_request, opts)
data
end

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

# Place an order
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
# @param id [String]
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
# @param id [String]
# @param [Hash] opts the optional parameters
# @option opts [PlaceOrderRequest] :place_order_request
# @return [OrderResponse]
def place_order(id, opts = {})

data, _status_code, _headers = place_order_with_http_info(id, opts)
def place_order(id, place_order_request = {}, opts = {})
_place_order_request = Patch::PlaceOrderRequest.new(place_order_request)
data, _status_code, _headers = place_order_with_http_info(id, opts.merge!({place_order_request: place_order_request}))
data
end

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

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

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

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

# Retrieves an order
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
# @param id [String]
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
# @param id [String]
# @param [Hash] opts the optional parameters
# @return [OrderResponse]
def retrieve_order(id, opts = {})

data, _status_code, _headers = retrieve_order_with_http_info(id, opts)
data
end

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

# Retrieves a list of orders
# 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.
# 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.
# @param [Hash] opts the optional parameters
# @option opts [Integer] :page
# @option opts [String] :metadata
# @option opts [String] :metadata_example1
# @option opts [String] :metadata_example2
# @option opts [Integer] :page
# @option opts [String] :metadata
# @option opts [String] :metadata_example1
# @option opts [String] :metadata_example2
# @return [OrderListResponse]
def retrieve_orders(opts = {})

data, _status_code, _headers = retrieve_orders_with_http_info(opts)
data
end

# Retrieves a list of orders
# 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.
# 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.
# @param [Hash] opts the optional parameters
# @option opts [Integer] :page
# @option opts [String] :metadata
# @option opts [String] :metadata_example1
# @option opts [String] :metadata_example2
# @option opts [Integer] :page
# @option opts [String] :metadata
# @option opts [String] :metadata_example1
# @option opts [String] :metadata_example2
# @return [Array<(OrderListResponse, Integer, Hash)>] OrderListResponse data, response status code and response headers
def retrieve_orders_with_http_info(opts = {})
if @api_client.config.debugging
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.22.0"
@user_agent = "patch-ruby/1.23.0"
@default_headers = {
'Content-Type' => 'application/json',
'User-Agent' => @user_agent
Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/models/allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Allocation
# A unique uid for the record. UIDs will be prepended by all_prod or all_test depending on the mode it was created in.
attr_accessor :id

# A boolean indicating if this project is a production or test mode project.
# A boolean indicating if this project is a production or demo mode project.
attr_accessor :production

# The amount (in grams) of allocated carbon offsets.
Expand Down
20 changes: 15 additions & 5 deletions lib/patch_ruby/models/create_order_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CreateOrderRequest

attr_accessor :unit

attr_accessor :issued_to

class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values
Expand Down Expand Up @@ -69,7 +71,8 @@ def self.attribute_map
:'total_price' => :'total_price',
:'currency' => :'currency',
:'amount' => :'amount',
:'unit' => :'unit'
:'unit' => :'unit',
:'issued_to' => :'issued_to'
}
end

Expand All @@ -90,7 +93,8 @@ def self.openapi_types
:'total_price' => :'Integer',
:'currency' => :'String',
:'amount' => :'Integer',
:'unit' => :'String'
:'unit' => :'String',
:'issued_to' => :'V1OrdersIssuedTo'
}
end

Expand All @@ -106,7 +110,8 @@ def self.openapi_nullable
:'total_price',
:'currency',
:'amount',
:'unit'
:'unit',
:'issued_to'
])
end

Expand Down Expand Up @@ -176,6 +181,10 @@ def initialize(attributes = {})
if attributes.key?(:'unit')
self.unit = attributes[:'unit']
end

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

# Show invalid properties with the reasons. Usually used together with valid?
Expand Down Expand Up @@ -331,7 +340,8 @@ def ==(o)
total_price == o.total_price &&
currency == o.currency &&
amount == o.amount &&
unit == o.unit
unit == o.unit &&
issued_to == o.issued_to
end

# @see the `==` method
Expand All @@ -343,7 +353,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, total_price, currency, amount, unit].hash
[mass_g, total_price_cents_usd, project_id, metadata, state, vintage_year, total_price, currency, amount, unit, issued_to].hash
end

# Builds the object from hash
Expand Down
2 changes: 1 addition & 1 deletion lib/patch_ruby/models/estimate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Estimate
# A unique uid for the record. UIDs will be prepended by est_prod or est_test depending on the mode it was created in.
attr_accessor :id

# A boolean indicating if this estimate is a production or test mode estimate.
# A boolean indicating if this estimate is a production or demo mode estimate.
attr_accessor :production

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

0 comments on commit f340aee

Please sign in to comment.