diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b90e29..778b092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 92437ea..fe07d93 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - patch_ruby (1.22.0) + patch_ruby (1.23.0) typhoeus (~> 1.0, >= 1.0.1) GEM diff --git a/README.md b/README.md index 6db8919..4f143aa 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) @@ -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 @@ -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. diff --git a/lib/patch_ruby.rb b/lib/patch_ruby.rb index fb16e39..3e15631 100644 --- a/lib/patch_ruby.rb +++ b/lib/patch_ruby.rb @@ -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' @@ -41,6 +42,7 @@ 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' @@ -48,6 +50,7 @@ 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' diff --git a/lib/patch_ruby/api/orders_api.rb b/lib/patch_ruby/api/orders_api.rb index 54c2eb7..e61ff6d 100644 --- a/lib/patch_ruby/api/orders_api.rb +++ b/lib/patch_ruby/api/orders_api.rb @@ -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 = {}) @@ -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 `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 [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers def create_order_with_http_info(create_order_request, opts = {}) @@ -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'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 [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 @@ -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' @@ -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 = {}) @@ -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 diff --git a/lib/patch_ruby/api_client.rb b/lib/patch_ruby/api_client.rb index 518c47b..c2384b2 100644 --- a/lib/patch_ruby/api_client.rb +++ b/lib/patch_ruby/api_client.rb @@ -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 diff --git a/lib/patch_ruby/models/allocation.rb b/lib/patch_ruby/models/allocation.rb index f9e4d04..52cef07 100644 --- a/lib/patch_ruby/models/allocation.rb +++ b/lib/patch_ruby/models/allocation.rb @@ -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. diff --git a/lib/patch_ruby/models/create_order_request.rb b/lib/patch_ruby/models/create_order_request.rb index 13e6c42..bfdf173 100644 --- a/lib/patch_ruby/models/create_order_request.rb +++ b/lib/patch_ruby/models/create_order_request.rb @@ -35,6 +35,8 @@ class CreateOrderRequest attr_accessor :unit + attr_accessor :issued_to + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values @@ -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 @@ -90,7 +93,8 @@ def self.openapi_types :'total_price' => :'Integer', :'currency' => :'String', :'amount' => :'Integer', - :'unit' => :'String' + :'unit' => :'String', + :'issued_to' => :'V1OrdersIssuedTo' } end @@ -106,7 +110,8 @@ def self.openapi_nullable :'total_price', :'currency', :'amount', - :'unit' + :'unit', + :'issued_to' ]) end @@ -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? @@ -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 @@ -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 diff --git a/lib/patch_ruby/models/estimate.rb b/lib/patch_ruby/models/estimate.rb index 14d757d..ead8a01 100644 --- a/lib/patch_ruby/models/estimate.rb +++ b/lib/patch_ruby/models/estimate.rb @@ -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. diff --git a/lib/patch_ruby/models/issued_to.rb b/lib/patch_ruby/models/issued_to.rb new file mode 100644 index 0000000..c3470cd --- /dev/null +++ b/lib/patch_ruby/models/issued_to.rb @@ -0,0 +1,242 @@ +=begin +#Patch API V1 + +#The core API used to integrate with Patch's service + +The version of the OpenAPI document: v1 +Contact: engineering@usepatch.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.3.1 + +=end + +require 'date' +require 'time' + +module Patch + # An object containing the name & email of the party the inventory will be issued to. + class IssuedTo + # Name provided for the issuee + attr_accessor :name + + # Email address provided for the issuee + attr_accessor :email + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'name' => :'name', + :'email' => :'email' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'name' => :'String', + :'email' => :'String' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'name', + :'email' + ]) + end + + + # Allows models with corresponding API classes to delegate API operations to those API classes + # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id + # Eg. Order.create_order delegates to OrdersApi.new.create_order + def self.method_missing(message, *args, &block) + if Object.const_defined?('Patch::IssuedTosApi::OPERATIONS') && Patch::IssuedTosApi::OPERATIONS.include?(message) + Patch::IssuedTosApi.new.send(message, *args) + else + super + end + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::IssuedTo` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + 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 + end + h[k.to_sym] = v + } + + if attributes.key?(:'name') + self.name = attributes[:'name'] + end + + if attributes.key?(:'email') + self.email = attributes[:'email'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + name == o.name && + email == o.email + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [name, email].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = Patch.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + end +end diff --git a/lib/patch_ruby/models/order.rb b/lib/patch_ruby/models/order.rb index f4f7bbb..3b22e9b 100644 --- a/lib/patch_ruby/models/order.rb +++ b/lib/patch_ruby/models/order.rb @@ -24,7 +24,7 @@ class Order # DEPRECATED, use `amount` and `unit` fields instead. The amount of carbon offsets in grams purchased through this order. attr_accessor :mass_g - # A boolean indicating if this order is a production or test mode order. + # A boolean indicating if this order is a production or demo mode order. attr_accessor :production # The current state of the order. @@ -66,6 +66,8 @@ class Order # An array containing the inventory allocated for this order. Inventory is grouped by project, vintage year, and price. attr_accessor :inventory + attr_accessor :issued_to + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values @@ -107,7 +109,8 @@ def self.attribute_map :'allocations' => :'allocations', :'registry_url' => :'registry_url', :'metadata' => :'metadata', - :'inventory' => :'inventory' + :'inventory' => :'inventory', + :'issued_to' => :'issued_to' } end @@ -135,7 +138,8 @@ def self.openapi_types :'allocations' => :'Array', :'registry_url' => :'String', :'metadata' => :'Object', - :'inventory' => :'Array' + :'inventory' => :'Array', + :'issued_to' => :'IssuedTo' } end @@ -245,6 +249,10 @@ def initialize(attributes = {}) self.inventory = value end 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? @@ -416,7 +424,8 @@ def ==(o) allocations == o.allocations && registry_url == o.registry_url && metadata == o.metadata && - inventory == o.inventory + inventory == o.inventory && + issued_to == o.issued_to end # @see the `==` method @@ -428,7 +437,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [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 + [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 end # Builds the object from hash diff --git a/lib/patch_ruby/models/place_order_request.rb b/lib/patch_ruby/models/place_order_request.rb new file mode 100644 index 0000000..9dc25bc --- /dev/null +++ b/lib/patch_ruby/models/place_order_request.rb @@ -0,0 +1,229 @@ +=begin +#Patch API V1 + +#The core API used to integrate with Patch's service + +The version of the OpenAPI document: v1 +Contact: engineering@usepatch.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.3.1 + +=end + +require 'date' +require 'time' + +module Patch + class PlaceOrderRequest + attr_accessor :issued_to + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'issued_to' => :'issued_to' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'issued_to' => :'V1OrdersIssuedTo' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'issued_to' + ]) + end + + + # Allows models with corresponding API classes to delegate API operations to those API classes + # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id + # Eg. Order.create_order delegates to OrdersApi.new.create_order + def self.method_missing(message, *args, &block) + if Object.const_defined?('Patch::PlaceOrderRequestsApi::OPERATIONS') && Patch::PlaceOrderRequestsApi::OPERATIONS.include?(message) + Patch::PlaceOrderRequestsApi.new.send(message, *args) + else + super + end + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::PlaceOrderRequest` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + 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 + end + h[k.to_sym] = v + } + + if attributes.key?(:'issued_to') + self.issued_to = attributes[:'issued_to'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + issued_to == o.issued_to + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [issued_to].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = Patch.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + end +end diff --git a/lib/patch_ruby/models/project.rb b/lib/patch_ruby/models/project.rb index c811f7b..9ed7047 100644 --- a/lib/patch_ruby/models/project.rb +++ b/lib/patch_ruby/models/project.rb @@ -18,7 +18,7 @@ class Project # A unique uid for the record. UIDs will be prepended by pro_prod or pro_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 name of the project. diff --git a/lib/patch_ruby/models/v1_orders_issued_to.rb b/lib/patch_ruby/models/v1_orders_issued_to.rb new file mode 100644 index 0000000..0e5f0f7 --- /dev/null +++ b/lib/patch_ruby/models/v1_orders_issued_to.rb @@ -0,0 +1,239 @@ +=begin +#Patch API V1 + +#The core API used to integrate with Patch's service + +The version of the OpenAPI document: v1 +Contact: engineering@usepatch.com +Generated by: https://openapi-generator.tech +OpenAPI Generator version: 5.3.1 + +=end + +require 'date' +require 'time' + +module Patch + class V1OrdersIssuedTo + attr_accessor :email + + attr_accessor :name + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'email' => :'email', + :'name' => :'name' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'email' => :'String', + :'name' => :'String' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'email', + :'name' + ]) + end + + + # Allows models with corresponding API classes to delegate API operations to those API classes + # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id + # Eg. Order.create_order delegates to OrdersApi.new.create_order + def self.method_missing(message, *args, &block) + if Object.const_defined?('Patch::V1OrdersIssuedTosApi::OPERATIONS') && Patch::V1OrdersIssuedTosApi::OPERATIONS.include?(message) + Patch::V1OrdersIssuedTosApi.new.send(message, *args) + else + super + end + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::V1OrdersIssuedTo` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + 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 + end + h[k.to_sym] = v + } + + if attributes.key?(:'email') + self.email = attributes[:'email'] + end + + if attributes.key?(:'name') + self.name = attributes[:'name'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + invalid_properties = Array.new + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + email == o.email && + name == o.name + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [email, name].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + new.build_from_hash(attributes) + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + self.class.openapi_types.each_pair do |key, type| + if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) + self.send("#{key}=", nil) + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[self.class.attribute_map[key]].is_a?(Array) + self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) + end + elsif !attributes[self.class.attribute_map[key]].nil? + self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) + end + end + + self + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def _deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = Patch.const_get(type) + klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + end +end diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index 7da139e..ed1b760 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.22.0' + VERSION = '1.23.0' end diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index a2d8394..69b5e84 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -42,6 +42,29 @@ expect(order.registry_url).not_to be_empty end + it 'supports create with issued_to' do + retrieve_project_response = Patch::Project.retrieve_project( + Constants::BIOMASS_TEST_PROJECT_ID + ) + + issued_to = {email: 'envimpact@companyb.com', name: 'Company B'} + total_price_cents_usd = 50_00 + + create_order_response = Patch::Order.create_order( + total_price_cents_usd: total_price_cents_usd, + issued_to: issued_to + ) + + expect(create_order_response.success).to eq true + + order = create_order_response.data + + expect(order.id).not_to be_nil + expect(order.price_cents_usd + order.patch_fee_cents_usd).to eq total_price_cents_usd + expect(order.issued_to.email).to eq(issued_to[:email]) + expect(order.issued_to.name).to eq(issued_to[:name]) + end + it 'supports create with a total price' do retrieve_project_response = Patch::Project.retrieve_project( Constants::BIOMASS_TEST_PROJECT_ID @@ -108,6 +131,17 @@ expect(cancel_order_response.data.state).to eq 'cancelled' end + it 'supports place order with issued_to' do + create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100, create_order: true) + order_to_place_id = create_estimate_to_place_response.data.order.id + + issued_to = {email: 'envimpact@companya.com', name: 'Company A'} + place_order_response = Patch::Order.place_order(order_to_place_id, { issued_to: issued_to}) + expect(place_order_response.data.state).to eq 'placed' + expect(place_order_response.data.issued_to.email).to eq(issued_to[:email]) + expect(place_order_response.data.issued_to.name).to eq(issued_to[:name]) + end + it 'supports create with a vintage year' do create_order_response = Patch::Order.create_order(mass_g: 100, vintage_year: 2022) diff --git a/spec/models/create_order_request_spec.rb b/spec/models/create_order_request_spec.rb index a182190..9d38471 100644 --- a/spec/models/create_order_request_spec.rb +++ b/spec/models/create_order_request_spec.rb @@ -31,7 +31,7 @@ let(:instance) { @instance } 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 } } let(:nullable_properties) do - Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit]) + Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit issued_to]) end end