diff --git a/CHANGELOG.md b/CHANGELOG.md index 778b092..26d1934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ 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.24.0] - 2022-07-22 + +### Added + +- Adds `Patch::Estimate.create_air_shipping_estimate` method +- Adds `Patch::Estimate.create_rail_shipping_estimate` method +- Adds `Patch::Estimate.create_road_shipping_estimate` method +- Adds `Patch::Estimate.create_sea_shipping_estimate` method + ## [1.23.0] - 2022-06-03 ### Added diff --git a/Gemfile.lock b/Gemfile.lock index fe07d93..4b8c239 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - patch_ruby (1.23.0) + patch_ruby (1.24.0) typhoeus (~> 1.0, >= 1.0.1) GEM diff --git a/lib/patch_ruby.rb b/lib/patch_ruby.rb index 3e15631..bc6badc 100644 --- a/lib/patch_ruby.rb +++ b/lib/patch_ruby.rb @@ -18,12 +18,16 @@ # Models require 'patch_ruby/models/allocation' +require 'patch_ruby/models/create_air_shipping_estimate_request' require 'patch_ruby/models/create_bitcoin_estimate_request' require 'patch_ruby/models/create_ethereum_estimate_request' require 'patch_ruby/models/create_flight_estimate_request' require 'patch_ruby/models/create_hotel_estimate_request' require 'patch_ruby/models/create_mass_estimate_request' require 'patch_ruby/models/create_order_request' +require 'patch_ruby/models/create_rail_shipping_estimate_request' +require 'patch_ruby/models/create_road_shipping_estimate_request' +require 'patch_ruby/models/create_sea_shipping_estimate_request' require 'patch_ruby/models/create_shipping_estimate_request' require 'patch_ruby/models/create_success_response' require 'patch_ruby/models/create_vehicle_estimate_request' diff --git a/lib/patch_ruby/api/estimates_api.rb b/lib/patch_ruby/api/estimates_api.rb index 9b25e19..967c30f 100644 --- a/lib/patch_ruby/api/estimates_api.rb +++ b/lib/patch_ruby/api/estimates_api.rb @@ -15,11 +15,15 @@ module Patch class EstimatesApi OPERATIONS = [ + :create_air_shipping_estimate, :create_bitcoin_estimate, :create_ethereum_estimate, :create_flight_estimate, :create_hotel_estimate, :create_mass_estimate, + :create_rail_shipping_estimate, + :create_road_shipping_estimate, + :create_sea_shipping_estimate, :create_shipping_estimate, :create_vehicle_estimate, :retrieve_estimate, @@ -31,6 +35,75 @@ class EstimatesApi def initialize(api_client = ApiClient.default) @api_client = api_client end + # Creates a GLEC air shipping estimate given freight mass and logistics + # Creates a GLEC air shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_air_shipping_estimate_request [CreateAirShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [EstimateResponse] + def create_air_shipping_estimate(create_air_shipping_estimate_request = {}, opts = {}) + _create_air_shipping_estimate_request = Patch::CreateAirShippingEstimateRequest.new(create_air_shipping_estimate_request) + data, _status_code, _headers = create_air_shipping_estimate_with_http_info(_create_air_shipping_estimate_request, opts) + data + end + + # Creates a GLEC air shipping estimate given freight mass and logistics + # Creates a GLEC air shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_air_shipping_estimate_request [CreateAirShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers + def create_air_shipping_estimate_with_http_info(create_air_shipping_estimate_request, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: EstimatesApi.create_air_shipping_estimate ...' + end + # verify the required parameter 'create_air_shipping_estimate_request' is set + if @api_client.config.client_side_validation && create_air_shipping_estimate_request.nil? + fail ArgumentError, "Missing the required parameter 'create_air_shipping_estimate_request' when calling EstimatesApi.create_air_shipping_estimate" + end + # resource path + local_var_path = '/v1/estimates/shipping/air' + + # query parameters + query_params = opts[:query_params] || {} + + # header parameters + 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] || @api_client.object_to_http_body(create_air_shipping_estimate_request) + + # return_type + return_type = opts[:debug_return_type] || 'EstimateResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || ['bearer_auth'] + + new_options = opts.merge( + :operation => :"EstimatesApi.create_air_shipping_estimate", + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type + ) + + data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: EstimatesApi#create_air_shipping_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + # Create a bitcoin estimate given a timestamp and transaction value # Creates a bitcoin estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest] @@ -376,6 +449,213 @@ def create_mass_estimate_with_http_info(create_mass_estimate_request, opts = {}) return data, status_code, headers end + # Creates a GLEC rail shipping estimate given freight mass and logistics + # Creates a GLEC rail shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_rail_shipping_estimate_request [CreateRailShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [EstimateResponse] + def create_rail_shipping_estimate(create_rail_shipping_estimate_request = {}, opts = {}) + _create_rail_shipping_estimate_request = Patch::CreateRailShippingEstimateRequest.new(create_rail_shipping_estimate_request) + data, _status_code, _headers = create_rail_shipping_estimate_with_http_info(_create_rail_shipping_estimate_request, opts) + data + end + + # Creates a GLEC rail shipping estimate given freight mass and logistics + # Creates a GLEC rail shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_rail_shipping_estimate_request [CreateRailShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers + def create_rail_shipping_estimate_with_http_info(create_rail_shipping_estimate_request, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: EstimatesApi.create_rail_shipping_estimate ...' + end + # verify the required parameter 'create_rail_shipping_estimate_request' is set + if @api_client.config.client_side_validation && create_rail_shipping_estimate_request.nil? + fail ArgumentError, "Missing the required parameter 'create_rail_shipping_estimate_request' when calling EstimatesApi.create_rail_shipping_estimate" + end + # resource path + local_var_path = '/v1/estimates/shipping/rail' + + # query parameters + query_params = opts[:query_params] || {} + + # header parameters + 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] || @api_client.object_to_http_body(create_rail_shipping_estimate_request) + + # return_type + return_type = opts[:debug_return_type] || 'EstimateResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || ['bearer_auth'] + + new_options = opts.merge( + :operation => :"EstimatesApi.create_rail_shipping_estimate", + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type + ) + + data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: EstimatesApi#create_rail_shipping_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + + # Creates a GLEC road shipping estimate given freight mass and logistics + # Creates a GLEC road shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_road_shipping_estimate_request [CreateRoadShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [EstimateResponse] + def create_road_shipping_estimate(create_road_shipping_estimate_request = {}, opts = {}) + _create_road_shipping_estimate_request = Patch::CreateRoadShippingEstimateRequest.new(create_road_shipping_estimate_request) + data, _status_code, _headers = create_road_shipping_estimate_with_http_info(_create_road_shipping_estimate_request, opts) + data + end + + # Creates a GLEC road shipping estimate given freight mass and logistics + # Creates a GLEC road shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_road_shipping_estimate_request [CreateRoadShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers + def create_road_shipping_estimate_with_http_info(create_road_shipping_estimate_request, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: EstimatesApi.create_road_shipping_estimate ...' + end + # verify the required parameter 'create_road_shipping_estimate_request' is set + if @api_client.config.client_side_validation && create_road_shipping_estimate_request.nil? + fail ArgumentError, "Missing the required parameter 'create_road_shipping_estimate_request' when calling EstimatesApi.create_road_shipping_estimate" + end + # resource path + local_var_path = '/v1/estimates/shipping/road' + + # query parameters + query_params = opts[:query_params] || {} + + # header parameters + 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] || @api_client.object_to_http_body(create_road_shipping_estimate_request) + + # return_type + return_type = opts[:debug_return_type] || 'EstimateResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || ['bearer_auth'] + + new_options = opts.merge( + :operation => :"EstimatesApi.create_road_shipping_estimate", + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type + ) + + data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: EstimatesApi#create_road_shipping_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + + # Creates a GLEC sea shipping estimate given freight mass and logistics + # Creates a GLEC sea shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_sea_shipping_estimate_request [CreateSeaShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [EstimateResponse] + def create_sea_shipping_estimate(create_sea_shipping_estimate_request = {}, opts = {}) + _create_sea_shipping_estimate_request = Patch::CreateSeaShippingEstimateRequest.new(create_sea_shipping_estimate_request) + data, _status_code, _headers = create_sea_shipping_estimate_with_http_info(_create_sea_shipping_estimate_request, opts) + data + end + + # Creates a GLEC sea shipping estimate given freight mass and logistics + # Creates a GLEC sea shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # @param create_sea_shipping_estimate_request [CreateSeaShippingEstimateRequest] + # @param [Hash] opts the optional parameters + # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers + def create_sea_shipping_estimate_with_http_info(create_sea_shipping_estimate_request, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: EstimatesApi.create_sea_shipping_estimate ...' + end + # verify the required parameter 'create_sea_shipping_estimate_request' is set + if @api_client.config.client_side_validation && create_sea_shipping_estimate_request.nil? + fail ArgumentError, "Missing the required parameter 'create_sea_shipping_estimate_request' when calling EstimatesApi.create_sea_shipping_estimate" + end + # resource path + local_var_path = '/v1/estimates/shipping/sea' + + # query parameters + query_params = opts[:query_params] || {} + + # header parameters + 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] || @api_client.object_to_http_body(create_sea_shipping_estimate_request) + + # return_type + return_type = opts[:debug_return_type] || 'EstimateResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || ['bearer_auth'] + + new_options = opts.merge( + :operation => :"EstimatesApi.create_sea_shipping_estimate", + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type + ) + + data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: EstimatesApi#create_sea_shipping_estimate\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + # Create a shipping estimate given the distance traveled in meters, package weight, and transportation method. # Creates a shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters. # @param create_shipping_estimate_request [CreateShippingEstimateRequest] diff --git a/lib/patch_ruby/api/orders_api.rb b/lib/patch_ruby/api/orders_api.rb index e61ff6d..24fa802 100644 --- a/lib/patch_ruby/api/orders_api.rb +++ b/lib/patch_ruby/api/orders_api.rb @@ -33,7 +33,6 @@ def initialize(api_client = ApiClient.default) # @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 @@ -166,9 +165,10 @@ def create_order_with_http_info(create_order_request, opts = {}) # @param [Hash] opts the optional parameters # @option opts [PlaceOrderRequest] :place_order_request # @return [OrderResponse] - 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})) + def place_order(order_id, opts = {}) + place_order_request = Patch::PlaceOrderRequest.new(opts) + opts[:place_order_request] = place_order_request + data, _status_code, _headers = place_order_with_http_info(order_id, opts) data end @@ -237,7 +237,6 @@ def place_order_with_http_info(id, opts = {}) # @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 @@ -304,7 +303,6 @@ def retrieve_order_with_http_info(id, opts = {}) # @option opts [String] :metadata_example2 # @return [OrderListResponse] def retrieve_orders(opts = {}) - data, _status_code, _headers = retrieve_orders_with_http_info(opts) data end diff --git a/lib/patch_ruby/api_client.rb b/lib/patch_ruby/api_client.rb index c2384b2..f721a91 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.23.0" + @user_agent = "patch-ruby/1.24.0" @default_headers = { 'Content-Type' => 'application/json', 'User-Agent' => @user_agent diff --git a/lib/patch_ruby/models/create_air_shipping_estimate_request.rb b/lib/patch_ruby/models/create_air_shipping_estimate_request.rb new file mode 100644 index 0000000..151ae67 --- /dev/null +++ b/lib/patch_ruby/models/create_air_shipping_estimate_request.rb @@ -0,0 +1,374 @@ +=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 CreateAirShippingEstimateRequest + attr_accessor :destination_airport + + attr_accessor :origin_airport + + attr_accessor :aircraft_code + + attr_accessor :aircraft_type + + attr_accessor :freight_mass_g + + attr_accessor :emissions_scope + + attr_accessor :project_id + + attr_accessor :create_order + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'destination_airport' => :'destination_airport', + :'origin_airport' => :'origin_airport', + :'aircraft_code' => :'aircraft_code', + :'aircraft_type' => :'aircraft_type', + :'freight_mass_g' => :'freight_mass_g', + :'emissions_scope' => :'emissions_scope', + :'project_id' => :'project_id', + :'create_order' => :'create_order' + } + 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 + { + :'destination_airport' => :'String', + :'origin_airport' => :'String', + :'aircraft_code' => :'String', + :'aircraft_type' => :'String', + :'freight_mass_g' => :'Integer', + :'emissions_scope' => :'String', + :'project_id' => :'String', + :'create_order' => :'Boolean' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'destination_airport', + :'origin_airport', + :'aircraft_code', + :'aircraft_type', + :'emissions_scope', + :'project_id', + :'create_order' + ]) + 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::CreateAirShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateAirShippingEstimateRequestsApi::OPERATIONS.include?(message) + Patch::CreateAirShippingEstimateRequestsApi.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::CreateAirShippingEstimateRequest` 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::CreateAirShippingEstimateRequest`. 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?(:'destination_airport') + self.destination_airport = attributes[:'destination_airport'] + end + + if attributes.key?(:'origin_airport') + self.origin_airport = attributes[:'origin_airport'] + end + + if attributes.key?(:'aircraft_code') + self.aircraft_code = attributes[:'aircraft_code'] + end + + if attributes.key?(:'aircraft_type') + self.aircraft_type = attributes[:'aircraft_type'] + else + self.aircraft_type = 'unknown' + end + + if attributes.key?(:'freight_mass_g') + self.freight_mass_g = attributes[:'freight_mass_g'] + end + + if attributes.key?(:'emissions_scope') + self.emissions_scope = attributes[:'emissions_scope'] + else + self.emissions_scope = 'wtw' + end + + if attributes.key?(:'project_id') + self.project_id = attributes[:'project_id'] + end + + if attributes.key?(:'create_order') + self.create_order = attributes[:'create_order'] + else + self.create_order = false + 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 + if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.') + end + + if !@freight_mass_g.nil? && @freight_mass_g < 0 + invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.') + end + + 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? + aircraft_type_validator = EnumAttributeValidator.new('String', ["passenger", "cargo", "unknown"]) + return false unless aircraft_type_validator.valid?(@aircraft_type) + return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + return false if !@freight_mass_g.nil? && @freight_mass_g < 0 + emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + return false unless emissions_scope_validator.valid?(@emissions_scope) + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] aircraft_type Object to be assigned + def aircraft_type=(aircraft_type) + validator = EnumAttributeValidator.new('String', ["passenger", "cargo", "unknown"]) + unless validator.valid?(aircraft_type) + fail ArgumentError, "invalid value for \"aircraft_type\", must be one of #{validator.allowable_values}." + end + @aircraft_type = aircraft_type + end + + # Custom attribute writer method with validation + # @param [Object] freight_mass_g Value to be assigned + def freight_mass_g=(freight_mass_g) + if !freight_mass_g.nil? && freight_mass_g > 2000000000 + fail ArgumentError, 'invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.' + end + + if !freight_mass_g.nil? && freight_mass_g < 0 + fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.' + end + + @freight_mass_g = freight_mass_g + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] emissions_scope Object to be assigned + def emissions_scope=(emissions_scope) + validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + unless validator.valid?(emissions_scope) + fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}." + end + @emissions_scope = emissions_scope + 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 && + destination_airport == o.destination_airport && + origin_airport == o.origin_airport && + aircraft_code == o.aircraft_code && + aircraft_type == o.aircraft_type && + freight_mass_g == o.freight_mass_g && + emissions_scope == o.emissions_scope && + project_id == o.project_id && + create_order == o.create_order + 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 + [destination_airport, origin_airport, aircraft_code, aircraft_type, freight_mass_g, emissions_scope, project_id, create_order].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/create_order_request.rb b/lib/patch_ruby/models/create_order_request.rb index bfdf173..594bc0b 100644 --- a/lib/patch_ruby/models/create_order_request.rb +++ b/lib/patch_ruby/models/create_order_request.rb @@ -232,7 +232,7 @@ def valid? return false if !@mass_g.nil? && @mass_g > 100000000000 return false if !@mass_g.nil? && @mass_g < 0 return false if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1 - state_validator = EnumAttributeValidator.new('String', ["draft", "placed"]) + state_validator = EnumAttributeValidator.new('String', ["draft", "reserved", "placed"]) return false unless state_validator.valid?(@state) return false if !@vintage_year.nil? && @vintage_year > 2100 return false if !@vintage_year.nil? && @vintage_year < 1900 @@ -271,7 +271,7 @@ def total_price_cents_usd=(total_price_cents_usd) # Custom attribute writer method checking allowed values (enum). # @param [Object] state Object to be assigned def state=(state) - validator = EnumAttributeValidator.new('String', ["draft", "placed"]) + validator = EnumAttributeValidator.new('String', ["draft", "reserved", "placed"]) unless validator.valid?(state) fail ArgumentError, "invalid value for \"state\", must be one of #{validator.allowable_values}." end diff --git a/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb b/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb new file mode 100644 index 0000000..c8a1365 --- /dev/null +++ b/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb @@ -0,0 +1,404 @@ +=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 CreateRailShippingEstimateRequest + attr_accessor :destination_country_code + + attr_accessor :destination_locode + + attr_accessor :destination_postal_code + + attr_accessor :origin_country_code + + attr_accessor :origin_locode + + attr_accessor :origin_postal_code + + attr_accessor :fuel_type + + attr_accessor :freight_mass_g + + attr_accessor :emissions_scope + + attr_accessor :project_id + + attr_accessor :create_order + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'destination_country_code' => :'destination_country_code', + :'destination_locode' => :'destination_locode', + :'destination_postal_code' => :'destination_postal_code', + :'origin_country_code' => :'origin_country_code', + :'origin_locode' => :'origin_locode', + :'origin_postal_code' => :'origin_postal_code', + :'fuel_type' => :'fuel_type', + :'freight_mass_g' => :'freight_mass_g', + :'emissions_scope' => :'emissions_scope', + :'project_id' => :'project_id', + :'create_order' => :'create_order' + } + 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 + { + :'destination_country_code' => :'String', + :'destination_locode' => :'String', + :'destination_postal_code' => :'String', + :'origin_country_code' => :'String', + :'origin_locode' => :'String', + :'origin_postal_code' => :'String', + :'fuel_type' => :'String', + :'freight_mass_g' => :'Integer', + :'emissions_scope' => :'String', + :'project_id' => :'String', + :'create_order' => :'Boolean' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'destination_country_code', + :'destination_locode', + :'destination_postal_code', + :'origin_country_code', + :'origin_locode', + :'origin_postal_code', + :'fuel_type', + :'emissions_scope', + :'project_id', + :'create_order' + ]) + 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::CreateRailShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateRailShippingEstimateRequestsApi::OPERATIONS.include?(message) + Patch::CreateRailShippingEstimateRequestsApi.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::CreateRailShippingEstimateRequest` 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::CreateRailShippingEstimateRequest`. 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?(:'destination_country_code') + self.destination_country_code = attributes[:'destination_country_code'] + end + + if attributes.key?(:'destination_locode') + self.destination_locode = attributes[:'destination_locode'] + end + + if attributes.key?(:'destination_postal_code') + self.destination_postal_code = attributes[:'destination_postal_code'] + end + + if attributes.key?(:'origin_country_code') + self.origin_country_code = attributes[:'origin_country_code'] + end + + if attributes.key?(:'origin_locode') + self.origin_locode = attributes[:'origin_locode'] + end + + if attributes.key?(:'origin_postal_code') + self.origin_postal_code = attributes[:'origin_postal_code'] + end + + if attributes.key?(:'fuel_type') + self.fuel_type = attributes[:'fuel_type'] + else + self.fuel_type = 'default' + end + + if attributes.key?(:'freight_mass_g') + self.freight_mass_g = attributes[:'freight_mass_g'] + end + + if attributes.key?(:'emissions_scope') + self.emissions_scope = attributes[:'emissions_scope'] + else + self.emissions_scope = 'wtw' + end + + if attributes.key?(:'project_id') + self.project_id = attributes[:'project_id'] + end + + if attributes.key?(:'create_order') + self.create_order = attributes[:'create_order'] + else + self.create_order = false + 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 + if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.') + end + + if !@freight_mass_g.nil? && @freight_mass_g < 0 + invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.') + end + + 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? + fuel_type_validator = EnumAttributeValidator.new('String', ["default", "diesel", "elec"]) + return false unless fuel_type_validator.valid?(@fuel_type) + return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + return false if !@freight_mass_g.nil? && @freight_mass_g < 0 + emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + return false unless emissions_scope_validator.valid?(@emissions_scope) + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] fuel_type Object to be assigned + def fuel_type=(fuel_type) + validator = EnumAttributeValidator.new('String', ["default", "diesel", "elec"]) + unless validator.valid?(fuel_type) + fail ArgumentError, "invalid value for \"fuel_type\", must be one of #{validator.allowable_values}." + end + @fuel_type = fuel_type + end + + # Custom attribute writer method with validation + # @param [Object] freight_mass_g Value to be assigned + def freight_mass_g=(freight_mass_g) + if !freight_mass_g.nil? && freight_mass_g > 2000000000 + fail ArgumentError, 'invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.' + end + + if !freight_mass_g.nil? && freight_mass_g < 0 + fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.' + end + + @freight_mass_g = freight_mass_g + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] emissions_scope Object to be assigned + def emissions_scope=(emissions_scope) + validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + unless validator.valid?(emissions_scope) + fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}." + end + @emissions_scope = emissions_scope + 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 && + destination_country_code == o.destination_country_code && + destination_locode == o.destination_locode && + destination_postal_code == o.destination_postal_code && + origin_country_code == o.origin_country_code && + origin_locode == o.origin_locode && + origin_postal_code == o.origin_postal_code && + fuel_type == o.fuel_type && + freight_mass_g == o.freight_mass_g && + emissions_scope == o.emissions_scope && + project_id == o.project_id && + create_order == o.create_order + 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 + [destination_country_code, destination_locode, destination_postal_code, origin_country_code, origin_locode, origin_postal_code, fuel_type, freight_mass_g, emissions_scope, project_id, create_order].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/create_road_shipping_estimate_request.rb b/lib/patch_ruby/models/create_road_shipping_estimate_request.rb new file mode 100644 index 0000000..48c9367 --- /dev/null +++ b/lib/patch_ruby/models/create_road_shipping_estimate_request.rb @@ -0,0 +1,507 @@ +=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 CreateRoadShippingEstimateRequest + attr_accessor :destination_country_code + + attr_accessor :destination_locode + + attr_accessor :destination_postal_code + + attr_accessor :origin_country_code + + attr_accessor :origin_locode + + attr_accessor :origin_postal_code + + attr_accessor :cargo_type + + attr_accessor :container_size_code + + attr_accessor :emissions_scope + + attr_accessor :freight_mass_g + + attr_accessor :fuel_type + + attr_accessor :number_of_containers + + attr_accessor :truck_weight_t + + attr_accessor :project_id + + attr_accessor :create_order + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'destination_country_code' => :'destination_country_code', + :'destination_locode' => :'destination_locode', + :'destination_postal_code' => :'destination_postal_code', + :'origin_country_code' => :'origin_country_code', + :'origin_locode' => :'origin_locode', + :'origin_postal_code' => :'origin_postal_code', + :'cargo_type' => :'cargo_type', + :'container_size_code' => :'container_size_code', + :'emissions_scope' => :'emissions_scope', + :'freight_mass_g' => :'freight_mass_g', + :'fuel_type' => :'fuel_type', + :'number_of_containers' => :'number_of_containers', + :'truck_weight_t' => :'truck_weight_t', + :'project_id' => :'project_id', + :'create_order' => :'create_order' + } + 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 + { + :'destination_country_code' => :'String', + :'destination_locode' => :'String', + :'destination_postal_code' => :'String', + :'origin_country_code' => :'String', + :'origin_locode' => :'String', + :'origin_postal_code' => :'String', + :'cargo_type' => :'String', + :'container_size_code' => :'String', + :'emissions_scope' => :'String', + :'freight_mass_g' => :'Integer', + :'fuel_type' => :'String', + :'number_of_containers' => :'Integer', + :'truck_weight_t' => :'Integer', + :'project_id' => :'String', + :'create_order' => :'Boolean' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'destination_country_code', + :'destination_locode', + :'destination_postal_code', + :'origin_country_code', + :'origin_locode', + :'origin_postal_code', + :'emissions_scope', + :'fuel_type', + :'number_of_containers', + :'truck_weight_t', + :'project_id', + :'create_order' + ]) + 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::CreateRoadShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateRoadShippingEstimateRequestsApi::OPERATIONS.include?(message) + Patch::CreateRoadShippingEstimateRequestsApi.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::CreateRoadShippingEstimateRequest` 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::CreateRoadShippingEstimateRequest`. 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?(:'destination_country_code') + self.destination_country_code = attributes[:'destination_country_code'] + end + + if attributes.key?(:'destination_locode') + self.destination_locode = attributes[:'destination_locode'] + end + + if attributes.key?(:'destination_postal_code') + self.destination_postal_code = attributes[:'destination_postal_code'] + end + + if attributes.key?(:'origin_country_code') + self.origin_country_code = attributes[:'origin_country_code'] + end + + if attributes.key?(:'origin_locode') + self.origin_locode = attributes[:'origin_locode'] + end + + if attributes.key?(:'origin_postal_code') + self.origin_postal_code = attributes[:'origin_postal_code'] + end + + if attributes.key?(:'cargo_type') + self.cargo_type = attributes[:'cargo_type'] + else + self.cargo_type = 'average_mixed' + end + + if attributes.key?(:'container_size_code') + self.container_size_code = attributes[:'container_size_code'] + end + + if attributes.key?(:'emissions_scope') + self.emissions_scope = attributes[:'emissions_scope'] + else + self.emissions_scope = 'wtw' + end + + if attributes.key?(:'freight_mass_g') + self.freight_mass_g = attributes[:'freight_mass_g'] + end + + if attributes.key?(:'fuel_type') + self.fuel_type = attributes[:'fuel_type'] + else + self.fuel_type = 'diesel' + end + + if attributes.key?(:'number_of_containers') + self.number_of_containers = attributes[:'number_of_containers'] + end + + if attributes.key?(:'truck_weight_t') + self.truck_weight_t = attributes[:'truck_weight_t'] + end + + if attributes.key?(:'project_id') + self.project_id = attributes[:'project_id'] + end + + if attributes.key?(:'create_order') + self.create_order = attributes[:'create_order'] + else + self.create_order = false + 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 + if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.') + end + + if !@freight_mass_g.nil? && @freight_mass_g < 0 + invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.') + end + + if !@number_of_containers.nil? && @number_of_containers < 0 + invalid_properties.push('invalid value for "number_of_containers", must be greater than or equal to 0.') + end + + if !@truck_weight_t.nil? && @truck_weight_t > 60 + invalid_properties.push('invalid value for "truck_weight_t", must be smaller than or equal to 60.') + end + + if !@truck_weight_t.nil? && @truck_weight_t < 0 + invalid_properties.push('invalid value for "truck_weight_t", must be greater than or equal to 0.') + end + + 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? + cargo_type_validator = EnumAttributeValidator.new('String', ["average_mixed", "container"]) + return false unless cargo_type_validator.valid?(@cargo_type) + container_size_code_validator = EnumAttributeValidator.new('String', ["20GP", "40GP", "22G1", "42G1", "40HC", "45G1"]) + return false unless container_size_code_validator.valid?(@container_size_code) + emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + return false unless emissions_scope_validator.valid?(@emissions_scope) + return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + return false if !@freight_mass_g.nil? && @freight_mass_g < 0 + fuel_type_validator = EnumAttributeValidator.new('String', ["cng", "diesel", "lng", "petrol"]) + return false unless fuel_type_validator.valid?(@fuel_type) + return false if !@number_of_containers.nil? && @number_of_containers < 0 + return false if !@truck_weight_t.nil? && @truck_weight_t > 60 + return false if !@truck_weight_t.nil? && @truck_weight_t < 0 + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] cargo_type Object to be assigned + def cargo_type=(cargo_type) + validator = EnumAttributeValidator.new('String', ["average_mixed", "container"]) + unless validator.valid?(cargo_type) + fail ArgumentError, "invalid value for \"cargo_type\", must be one of #{validator.allowable_values}." + end + @cargo_type = cargo_type + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] container_size_code Object to be assigned + def container_size_code=(container_size_code) + validator = EnumAttributeValidator.new('String', ["20GP", "40GP", "22G1", "42G1", "40HC", "45G1"]) + unless validator.valid?(container_size_code) + fail ArgumentError, "invalid value for \"container_size_code\", must be one of #{validator.allowable_values}." + end + @container_size_code = container_size_code + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] emissions_scope Object to be assigned + def emissions_scope=(emissions_scope) + validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + unless validator.valid?(emissions_scope) + fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}." + end + @emissions_scope = emissions_scope + end + + # Custom attribute writer method with validation + # @param [Object] freight_mass_g Value to be assigned + def freight_mass_g=(freight_mass_g) + if !freight_mass_g.nil? && freight_mass_g > 2000000000 + fail ArgumentError, 'invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.' + end + + if !freight_mass_g.nil? && freight_mass_g < 0 + fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.' + end + + @freight_mass_g = freight_mass_g + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] fuel_type Object to be assigned + def fuel_type=(fuel_type) + validator = EnumAttributeValidator.new('String', ["cng", "diesel", "lng", "petrol"]) + unless validator.valid?(fuel_type) + fail ArgumentError, "invalid value for \"fuel_type\", must be one of #{validator.allowable_values}." + end + @fuel_type = fuel_type + end + + # Custom attribute writer method with validation + # @param [Object] number_of_containers Value to be assigned + def number_of_containers=(number_of_containers) + if !number_of_containers.nil? && number_of_containers < 0 + fail ArgumentError, 'invalid value for "number_of_containers", must be greater than or equal to 0.' + end + + @number_of_containers = number_of_containers + end + + # Custom attribute writer method with validation + # @param [Object] truck_weight_t Value to be assigned + def truck_weight_t=(truck_weight_t) + if !truck_weight_t.nil? && truck_weight_t > 60 + fail ArgumentError, 'invalid value for "truck_weight_t", must be smaller than or equal to 60.' + end + + if !truck_weight_t.nil? && truck_weight_t < 0 + fail ArgumentError, 'invalid value for "truck_weight_t", must be greater than or equal to 0.' + end + + @truck_weight_t = truck_weight_t + 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 && + destination_country_code == o.destination_country_code && + destination_locode == o.destination_locode && + destination_postal_code == o.destination_postal_code && + origin_country_code == o.origin_country_code && + origin_locode == o.origin_locode && + origin_postal_code == o.origin_postal_code && + cargo_type == o.cargo_type && + container_size_code == o.container_size_code && + emissions_scope == o.emissions_scope && + freight_mass_g == o.freight_mass_g && + fuel_type == o.fuel_type && + number_of_containers == o.number_of_containers && + truck_weight_t == o.truck_weight_t && + project_id == o.project_id && + create_order == o.create_order + 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 + [destination_country_code, destination_locode, destination_postal_code, origin_country_code, origin_locode, origin_postal_code, cargo_type, container_size_code, emissions_scope, freight_mass_g, fuel_type, number_of_containers, truck_weight_t, project_id, create_order].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/create_sea_shipping_estimate_request.rb b/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb new file mode 100644 index 0000000..cda9b94 --- /dev/null +++ b/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb @@ -0,0 +1,461 @@ +=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 CreateSeaShippingEstimateRequest + attr_accessor :destination_country_code + + attr_accessor :destination_locode + + attr_accessor :destination_postal_code + + attr_accessor :origin_country_code + + attr_accessor :origin_locode + + attr_accessor :origin_postal_code + + attr_accessor :container_size_code + + attr_accessor :emissions_scope + + attr_accessor :freight_mass_g + + attr_accessor :freight_volume_cubic_m + + attr_accessor :number_of_containers + + attr_accessor :vessel_imo + + attr_accessor :project_id + + attr_accessor :create_order + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'destination_country_code' => :'destination_country_code', + :'destination_locode' => :'destination_locode', + :'destination_postal_code' => :'destination_postal_code', + :'origin_country_code' => :'origin_country_code', + :'origin_locode' => :'origin_locode', + :'origin_postal_code' => :'origin_postal_code', + :'container_size_code' => :'container_size_code', + :'emissions_scope' => :'emissions_scope', + :'freight_mass_g' => :'freight_mass_g', + :'freight_volume_cubic_m' => :'freight_volume_cubic_m', + :'number_of_containers' => :'number_of_containers', + :'vessel_imo' => :'vessel_imo', + :'project_id' => :'project_id', + :'create_order' => :'create_order' + } + 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 + { + :'destination_country_code' => :'String', + :'destination_locode' => :'String', + :'destination_postal_code' => :'String', + :'origin_country_code' => :'String', + :'origin_locode' => :'String', + :'origin_postal_code' => :'String', + :'container_size_code' => :'String', + :'emissions_scope' => :'String', + :'freight_mass_g' => :'Integer', + :'freight_volume_cubic_m' => :'Integer', + :'number_of_containers' => :'Integer', + :'vessel_imo' => :'Integer', + :'project_id' => :'String', + :'create_order' => :'Boolean' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'destination_country_code', + :'destination_locode', + :'destination_postal_code', + :'origin_country_code', + :'origin_locode', + :'origin_postal_code', + :'emissions_scope', + :'freight_volume_cubic_m', + :'number_of_containers', + :'vessel_imo', + :'project_id', + :'create_order' + ]) + 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::CreateSeaShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateSeaShippingEstimateRequestsApi::OPERATIONS.include?(message) + Patch::CreateSeaShippingEstimateRequestsApi.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::CreateSeaShippingEstimateRequest` 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::CreateSeaShippingEstimateRequest`. 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?(:'destination_country_code') + self.destination_country_code = attributes[:'destination_country_code'] + end + + if attributes.key?(:'destination_locode') + self.destination_locode = attributes[:'destination_locode'] + end + + if attributes.key?(:'destination_postal_code') + self.destination_postal_code = attributes[:'destination_postal_code'] + end + + if attributes.key?(:'origin_country_code') + self.origin_country_code = attributes[:'origin_country_code'] + end + + if attributes.key?(:'origin_locode') + self.origin_locode = attributes[:'origin_locode'] + end + + if attributes.key?(:'origin_postal_code') + self.origin_postal_code = attributes[:'origin_postal_code'] + end + + if attributes.key?(:'container_size_code') + self.container_size_code = attributes[:'container_size_code'] + end + + if attributes.key?(:'emissions_scope') + self.emissions_scope = attributes[:'emissions_scope'] + else + self.emissions_scope = 'wtw' + end + + if attributes.key?(:'freight_mass_g') + self.freight_mass_g = attributes[:'freight_mass_g'] + end + + if attributes.key?(:'freight_volume_cubic_m') + self.freight_volume_cubic_m = attributes[:'freight_volume_cubic_m'] + end + + if attributes.key?(:'number_of_containers') + self.number_of_containers = attributes[:'number_of_containers'] + end + + if attributes.key?(:'vessel_imo') + self.vessel_imo = attributes[:'vessel_imo'] + end + + if attributes.key?(:'project_id') + self.project_id = attributes[:'project_id'] + end + + if attributes.key?(:'create_order') + self.create_order = attributes[:'create_order'] + else + self.create_order = false + 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 + if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.') + end + + if !@freight_mass_g.nil? && @freight_mass_g < 0 + invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.') + end + + if !@freight_volume_cubic_m.nil? && @freight_volume_cubic_m < 0 + invalid_properties.push('invalid value for "freight_volume_cubic_m", must be greater than or equal to 0.') + end + + if !@number_of_containers.nil? && @number_of_containers < 0 + invalid_properties.push('invalid value for "number_of_containers", must be greater than or equal to 0.') + end + + 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? + container_size_code_validator = EnumAttributeValidator.new('String', ["20GP", "40GP", "22G1", "42G1", "40HC", "45G1"]) + return false unless container_size_code_validator.valid?(@container_size_code) + emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + return false unless emissions_scope_validator.valid?(@emissions_scope) + return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000 + return false if !@freight_mass_g.nil? && @freight_mass_g < 0 + return false if !@freight_volume_cubic_m.nil? && @freight_volume_cubic_m < 0 + return false if !@number_of_containers.nil? && @number_of_containers < 0 + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] container_size_code Object to be assigned + def container_size_code=(container_size_code) + validator = EnumAttributeValidator.new('String', ["20GP", "40GP", "22G1", "42G1", "40HC", "45G1"]) + unless validator.valid?(container_size_code) + fail ArgumentError, "invalid value for \"container_size_code\", must be one of #{validator.allowable_values}." + end + @container_size_code = container_size_code + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] emissions_scope Object to be assigned + def emissions_scope=(emissions_scope) + validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"]) + unless validator.valid?(emissions_scope) + fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}." + end + @emissions_scope = emissions_scope + end + + # Custom attribute writer method with validation + # @param [Object] freight_mass_g Value to be assigned + def freight_mass_g=(freight_mass_g) + if !freight_mass_g.nil? && freight_mass_g > 2000000000 + fail ArgumentError, 'invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.' + end + + if !freight_mass_g.nil? && freight_mass_g < 0 + fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.' + end + + @freight_mass_g = freight_mass_g + end + + # Custom attribute writer method with validation + # @param [Object] freight_volume_cubic_m Value to be assigned + def freight_volume_cubic_m=(freight_volume_cubic_m) + if !freight_volume_cubic_m.nil? && freight_volume_cubic_m < 0 + fail ArgumentError, 'invalid value for "freight_volume_cubic_m", must be greater than or equal to 0.' + end + + @freight_volume_cubic_m = freight_volume_cubic_m + end + + # Custom attribute writer method with validation + # @param [Object] number_of_containers Value to be assigned + def number_of_containers=(number_of_containers) + if !number_of_containers.nil? && number_of_containers < 0 + fail ArgumentError, 'invalid value for "number_of_containers", must be greater than or equal to 0.' + end + + @number_of_containers = number_of_containers + 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 && + destination_country_code == o.destination_country_code && + destination_locode == o.destination_locode && + destination_postal_code == o.destination_postal_code && + origin_country_code == o.origin_country_code && + origin_locode == o.origin_locode && + origin_postal_code == o.origin_postal_code && + container_size_code == o.container_size_code && + emissions_scope == o.emissions_scope && + freight_mass_g == o.freight_mass_g && + freight_volume_cubic_m == o.freight_volume_cubic_m && + number_of_containers == o.number_of_containers && + vessel_imo == o.vessel_imo && + project_id == o.project_id && + create_order == o.create_order + 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 + [destination_country_code, destination_locode, destination_postal_code, origin_country_code, origin_locode, origin_postal_code, container_size_code, emissions_scope, freight_mass_g, freight_volume_cubic_m, number_of_containers, vessel_imo, project_id, create_order].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 3b22e9b..48088be 100644 --- a/lib/patch_ruby/models/order.rb +++ b/lib/patch_ruby/models/order.rb @@ -331,7 +331,7 @@ def valid? return false if @mass_g < 0 return false if @production.nil? return false if @state.nil? - state_validator = EnumAttributeValidator.new('String', ["draft", "placed", "processing", "complete", "cancelled"]) + state_validator = EnumAttributeValidator.new('String', ["draft", "reserved", "placed", "processing", "complete", "cancelled"]) return false unless state_validator.valid?(@state) return false if @amount.nil? return false if @amount > 100000000000 @@ -368,7 +368,7 @@ def mass_g=(mass_g) # Custom attribute writer method checking allowed values (enum). # @param [Object] state Object to be assigned def state=(state) - validator = EnumAttributeValidator.new('String', ["draft", "placed", "processing", "complete", "cancelled"]) + validator = EnumAttributeValidator.new('String', ["draft", "reserved", "placed", "processing", "complete", "cancelled"]) unless validator.valid?(state) fail ArgumentError, "invalid value for \"state\", must be one of #{validator.allowable_values}." end diff --git a/lib/patch_ruby/models/project.rb b/lib/patch_ruby/models/project.rb index 9ed7047..3fa11b0 100644 --- a/lib/patch_ruby/models/project.rb +++ b/lib/patch_ruby/models/project.rb @@ -30,7 +30,7 @@ class Project # DEPRECATED. Favor the technology_type field instead. attr_accessor :type - # The mechanism of the project. Either removal or avoidance. + # The mechanism of the project. One of: removal, avoidance, avoidance_and_removal. attr_accessor :mechanism # The country of origin of the project. diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index ed1b760..047401f 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.23.0' + VERSION = '1.24.0' end diff --git a/spec/integration/estimates_spec.rb b/spec/integration/estimates_spec.rb index f4554eb..971423c 100644 --- a/spec/integration/estimates_spec.rb +++ b/spec/integration/estimates_spec.rb @@ -171,4 +171,155 @@ expect(create_estimate_response.data.mass_g).to be >= 100_000 expect(create_estimate_response.data.id).not_to be_nil end + + context "when creating an air shipping estimate" do + it "supports creating an estimate using airports" do + air_shipping_estimate = Patch::Estimate.create_air_shipping_estimate( + aircraft_type: "cargo", + create_order: false, + destination_airport: "JFK", + freight_mass_g: 31_300, + origin_airport: "SFO" + ) + expect(air_shipping_estimate.data.type).to eq('shipping_air') + expect(air_shipping_estimate.data.mass_g).to be >= 20_000 + end + + it "supports creating an estimate with an order" do + air_shipping_estimate = Patch::Estimate.create_air_shipping_estimate( + aircraft_type: "cargo", + create_order: true, + destination_airport: "JFK", + freight_mass_g: 19_140, + origin_airport: "SFO" + ) + expect(air_shipping_estimate.data.type).to eq('shipping_air') + expect(air_shipping_estimate.data.mass_g).to be >= 20_000 + expect(air_shipping_estimate.data.order.amount).to be >= 10_000 + end + end + + context "when creating a rail shipping estimate" do + it "supports creating an estimate using locodes" do + rail_shipping_estimate = Patch::Estimate.create_rail_shipping_estimate( + create_order: false, + destination_locode: "USSEA", + emissions_scope: "wtw", + freight_mass_g: 419_060, + fuel_type: "diesel", + origin_locode: "USSD2" + ) + expect(rail_shipping_estimate.data.type).to eq('shipping_rail') + expect(rail_shipping_estimate.data.mass_g).to be >= 15_000 + end + + it "supports creating an estimate using postal codes" do + rail_shipping_estimate = Patch::Estimate.create_rail_shipping_estimate( + create_order: false, + destination_country_code: "US", + destination_postal_code: "97209", + emissions_scope: "wtw", + freight_mass_g: 226_000, + fuel_type: "diesel", + origin_country_code: "US", + origin_postal_code: "90210" + ) + expect(rail_shipping_estimate.data.type).to eq('shipping_rail') + expect(rail_shipping_estimate.data.mass_g).to be >= 4_000 + end + + it "supports creating an estimate with an order" do + rail_shipping_estimate = Patch::Estimate.create_rail_shipping_estimate( + create_order: true, + destination_locode: "USSEA", + freight_mass_g: 359_000, + origin_locode: "USSD2" + ) + expect(rail_shipping_estimate.data.type).to eq('shipping_rail') + expect(rail_shipping_estimate.data.mass_g).to be >= 15_000 + expect(rail_shipping_estimate.data.order.amount).to be >= 10_000 + end + end + + context "when creating a road shipping estimate" do + it "supports creating an estimate using locodes" do + road_shipping_estimate = Patch::Estimate.create_road_shipping_estimate( + create_order: false, + container_size_code: "20GP", + destination_locode: "USSEA", + emissions_scope: "wtw", + freight_mass_g: 124_870, + origin_locode: "USSD2" + ) + expect(road_shipping_estimate.data.type).to eq('shipping_road') + expect(road_shipping_estimate.data.mass_g).to be >= 15_000 + end + + it "supports creating an estimate using postal codes" do + road_shipping_estimate = Patch::Estimate.create_road_shipping_estimate( + create_order: false, + destination_country_code: "US", + destination_postal_code: "97209", + emissions_scope: "wtw", + freight_mass_g: 226_000, + origin_country_code: "US", + origin_postal_code: "90210" + ) + expect(road_shipping_estimate.data.type).to eq('shipping_road') + expect(road_shipping_estimate.data.mass_g).to be >= 4_000 + end + + it "supports creating an estimate with an order" do + road_shipping_estimate = Patch::Estimate.create_road_shipping_estimate( + create_order: true, + destination_locode: "USSEA", + freight_mass_g: 359_000, + origin_locode: "USSD2" + ) + expect(road_shipping_estimate.data.type).to eq('shipping_road') + expect(road_shipping_estimate.data.mass_g).to be >= 15_000 + expect(road_shipping_estimate.data.order.amount).to be >= 10_000 + end + end + + context "when creating a sea shipping estimate" do + it "supports creating an estimate using locodes" do + sea_shipping_estimate = Patch::Estimate.create_sea_shipping_estimate( + create_order: false, + container_size_code: "20GP", + destination_locode: "HKHKG", + emissions_scope: "wtw", + freight_mass_g: 124_870, + origin_locode: "FRMRS" + ) + expect(sea_shipping_estimate.data.type).to eq('shipping_sea') + expect(sea_shipping_estimate.data.mass_g).to be >= 10_000 + end + + it "supports creating an estimate using postal codes" do + sea_shipping_estimate = Patch::Estimate.create_sea_shipping_estimate( + create_order: false, + destination_country_code: "US", + destination_postal_code: "97209", + emissions_scope: "wtw", + freight_mass_g: 226_000, + origin_country_code: "US", + origin_postal_code: "90210" + ) + expect(sea_shipping_estimate.data.type).to eq('shipping_sea') + expect(sea_shipping_estimate.data.mass_g).to be >= 4_000 + end + + it "supports creating an estimate with an order" do + sea_shipping_estimate = Patch::Estimate.create_sea_shipping_estimate( + create_order: true, + destination_locode: "USSEA", + freight_mass_g: 359_000, + origin_locode: "USSD2" + ) + expect(sea_shipping_estimate.data.type).to eq('shipping_sea') + expect(sea_shipping_estimate.data.mass_g).to be >= 15_000 + expect(sea_shipping_estimate.data.order.amount).to be >= 10_000 + end + end end diff --git a/spec/integration/orders_spec.rb b/spec/integration/orders_spec.rb index 69b5e84..edd9224 100644 --- a/spec/integration/orders_spec.rb +++ b/spec/integration/orders_spec.rb @@ -47,7 +47,7 @@ Constants::BIOMASS_TEST_PROJECT_ID ) - issued_to = {email: 'envimpact@companyb.com', name: 'Company B'} + issued_to = { email: 'envimpact@companyb.com', name: 'Company B' } total_price_cents_usd = 50_00 create_order_response = Patch::Order.create_order( @@ -135,8 +135,8 @@ 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}) + 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])