From 64481e06b832e0cd3be6954808b1f0dd8515e8d7 Mon Sep 17 00:00:00 2001 From: Brett Holt Date: Wed, 10 Aug 2022 17:13:01 -0700 Subject: [PATCH] Add /estimates/ecommerce API support (#77) --- CHANGELOG.md | 6 ++ README.md | 8 +- package-lock.json | 4 +- package.json | 2 +- src/ApiClient.js | 2 +- src/api/EstimatesApi.js | 50 ++++++++++++ src/model/CreateAirShippingEstimateRequest.js | 2 +- src/model/CreateEcommerceEstimateRequest.js | 79 +++++++++++++++++++ .../CreateRailShippingEstimateRequest.js | 2 +- .../CreateRoadShippingEstimateRequest.js | 2 +- src/model/CreateSeaShippingEstimateRequest.js | 2 +- test/integration/estimates.test.js | 16 ++++ 12 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 src/model/CreateEcommerceEstimateRequest.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 32b3284..73ebbfd 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.24.2] - 2022-08-10 + +### Added + +- Adds `patch.estimates.createEcommerceEstimate` method + ## [1.24.0] - 2022-07-22 ### Added diff --git a/README.md b/README.md index b29b01f..efc52f6 100644 --- a/README.md +++ b/README.md @@ -122,13 +122,13 @@ patch.estimates.createMassEstimate({ mass_g }); const distance_m = 9000000; // Pass in the distance traveled in meters patch.estimates.createFlightEstimate({ distance_m }); -// Create a shipping estimate +// Create an ecommerce estimate const distance_m = 9000000; // Pass in the shipping distance in meters, the transportation method, and the package mass -patch.estimates.createShippingEstimate({ +patch.estimates.createEcommerceEstimate({ distance_m, - transportation_method: 'air', - package_mass_g: 1000 + package_mass_g: 1000, + transportation_method: 'air' }); // Create a bitcoin estimate diff --git a/package-lock.json b/package-lock.json index 45aa8b9..46bdf43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.24.1", + "version": "1.24.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.24.1", + "version": "1.24.2", "license": "MIT", "dependencies": { "query-string": "^7.0.1", diff --git a/package.json b/package.json index 7218038..d0d59a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.24.1", + "version": "1.24.2", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index 36f674b..b04fd6c 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.24.1' + 'User-Agent': 'patch-node/1.24.2' }; /** diff --git a/src/api/EstimatesApi.js b/src/api/EstimatesApi.js index 9885947..3e21b2b 100644 --- a/src/api/EstimatesApi.js +++ b/src/api/EstimatesApi.js @@ -8,6 +8,7 @@ import ApiClient from '../ApiClient'; import CreateAirShippingEstimateRequest from '../model/CreateAirShippingEstimateRequest'; import CreateBitcoinEstimateRequest from '../model/CreateBitcoinEstimateRequest'; +import CreateEcommerceEstimateRequest from '../model/CreateEcommerceEstimateRequest'; import CreateEthereumEstimateRequest from '../model/CreateEthereumEstimateRequest'; import CreateFlightEstimateRequest from '../model/CreateFlightEstimateRequest'; import CreateHotelEstimateRequest from '../model/CreateHotelEstimateRequest'; @@ -122,6 +123,55 @@ export default class EstimatesApi { return this.createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest); } + createEcommerceEstimateWithHttpInfo(createEcommerceEstimateRequest) { + const _createEcommerceEstimateRequest = + CreateEcommerceEstimateRequest.constructFromObject( + createEcommerceEstimateRequest, + new CreateEcommerceEstimateRequest() + ); + + // verify the required parameter 'createEcommerceEstimateRequest' is set + if ( + _createEcommerceEstimateRequest === undefined || + _createEcommerceEstimateRequest === null + ) { + throw new Error( + "Missing the required parameter 'createEcommerceEstimateRequest' when calling createEcommerceEstimate" + ); + } + + let postBody = _createEcommerceEstimateRequest; + let pathParams = {}; + let queryParams = {}; + let headerParams = {}; + let formParams = {}; + + let authNames = ['bearer_auth']; + let contentTypes = ['application/json']; + let accepts = ['application/json']; + let returnType = EstimateResponse; + + return this.apiClient.callApi( + '/v1/estimates/ecommerce', + 'POST', + pathParams, + queryParams, + headerParams, + formParams, + postBody, + authNames, + contentTypes, + accepts, + returnType + ); + } + + createEcommerceEstimate(createEcommerceEstimateRequest) { + return this.createEcommerceEstimateWithHttpInfo( + createEcommerceEstimateRequest + ); + } + createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest) { const _createEthereumEstimateRequest = CreateEthereumEstimateRequest.constructFromObject( diff --git a/src/model/CreateAirShippingEstimateRequest.js b/src/model/CreateAirShippingEstimateRequest.js index f2a8513..fb4bf0b 100644 --- a/src/model/CreateAirShippingEstimateRequest.js +++ b/src/model/CreateAirShippingEstimateRequest.js @@ -88,7 +88,7 @@ CreateAirShippingEstimateRequest.prototype['aircraft_type'] = 'unknown'; CreateAirShippingEstimateRequest.prototype['freight_mass_g'] = undefined; -CreateAirShippingEstimateRequest.prototype['emissions_scope'] = 'wtw'; +CreateAirShippingEstimateRequest.prototype['emissions_scope'] = 'ttw'; CreateAirShippingEstimateRequest.prototype['project_id'] = undefined; diff --git a/src/model/CreateEcommerceEstimateRequest.js b/src/model/CreateEcommerceEstimateRequest.js new file mode 100644 index 0000000..653313b --- /dev/null +++ b/src/model/CreateEcommerceEstimateRequest.js @@ -0,0 +1,79 @@ +/** + * Patch API V1 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +import ApiClient from '../ApiClient'; + +class CreateEcommerceEstimateRequest { + constructor(distanceM, packageMassG, transportationMethod) { + CreateEcommerceEstimateRequest.initialize( + this, + distanceM, + packageMassG, + transportationMethod + ); + } + + static initialize(obj, distanceM, packageMassG, transportationMethod) { + obj['distance_m'] = distanceM; + obj['package_mass_g'] = packageMassG; + obj['transportation_method'] = transportationMethod; + } + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new CreateEcommerceEstimateRequest(); + + if (data.hasOwnProperty('distance_m')) { + obj['distance_m'] = ApiClient.convertToType( + data['distance_m'], + 'Number' + ); + } + + if (data.hasOwnProperty('package_mass_g')) { + obj['package_mass_g'] = ApiClient.convertToType( + data['package_mass_g'], + 'Number' + ); + } + + if (data.hasOwnProperty('transportation_method')) { + obj['transportation_method'] = ApiClient.convertToType( + data['transportation_method'], + 'String' + ); + } + + if (data.hasOwnProperty('project_id')) { + obj['project_id'] = ApiClient.convertToType( + data['project_id'], + 'String' + ); + } + + if (data.hasOwnProperty('create_order')) { + obj['create_order'] = ApiClient.convertToType( + data['create_order'], + 'Boolean' + ); + } + } + return obj; + } +} + +CreateEcommerceEstimateRequest.prototype['distance_m'] = undefined; + +CreateEcommerceEstimateRequest.prototype['package_mass_g'] = undefined; + +CreateEcommerceEstimateRequest.prototype['transportation_method'] = undefined; + +CreateEcommerceEstimateRequest.prototype['project_id'] = undefined; + +CreateEcommerceEstimateRequest.prototype['create_order'] = false; + +export default CreateEcommerceEstimateRequest; diff --git a/src/model/CreateRailShippingEstimateRequest.js b/src/model/CreateRailShippingEstimateRequest.js index f1f9d31..70deeb3 100644 --- a/src/model/CreateRailShippingEstimateRequest.js +++ b/src/model/CreateRailShippingEstimateRequest.js @@ -114,7 +114,7 @@ CreateRailShippingEstimateRequest.prototype['fuel_type'] = 'default'; CreateRailShippingEstimateRequest.prototype['freight_mass_g'] = undefined; -CreateRailShippingEstimateRequest.prototype['emissions_scope'] = 'wtw'; +CreateRailShippingEstimateRequest.prototype['emissions_scope'] = 'ttw'; CreateRailShippingEstimateRequest.prototype['project_id'] = undefined; diff --git a/src/model/CreateRoadShippingEstimateRequest.js b/src/model/CreateRoadShippingEstimateRequest.js index e34b340..5dea7b2 100644 --- a/src/model/CreateRoadShippingEstimateRequest.js +++ b/src/model/CreateRoadShippingEstimateRequest.js @@ -142,7 +142,7 @@ CreateRoadShippingEstimateRequest.prototype['cargo_type'] = 'average_mixed'; CreateRoadShippingEstimateRequest.prototype['container_size_code'] = undefined; -CreateRoadShippingEstimateRequest.prototype['emissions_scope'] = 'wtw'; +CreateRoadShippingEstimateRequest.prototype['emissions_scope'] = 'ttw'; CreateRoadShippingEstimateRequest.prototype['freight_mass_g'] = undefined; diff --git a/src/model/CreateSeaShippingEstimateRequest.js b/src/model/CreateSeaShippingEstimateRequest.js index b34cd58..d82ccca 100644 --- a/src/model/CreateSeaShippingEstimateRequest.js +++ b/src/model/CreateSeaShippingEstimateRequest.js @@ -136,7 +136,7 @@ CreateSeaShippingEstimateRequest.prototype['origin_postal_code'] = undefined; CreateSeaShippingEstimateRequest.prototype['container_size_code'] = undefined; -CreateSeaShippingEstimateRequest.prototype['emissions_scope'] = 'wtw'; +CreateSeaShippingEstimateRequest.prototype['emissions_scope'] = 'ttw'; CreateSeaShippingEstimateRequest.prototype['freight_mass_g'] = undefined; diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index d50f76a..35b0ebd 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -52,6 +52,22 @@ describe('Estimates Integration', function () { expect(estimate.order).to.be.eq(null); }); + it('supports creating ecommerce estimates', async function () { + const createEstimateResponse = + await patch.estimates.createEcommerceEstimate({ + create_order: false, + distance_m: 100000, + package_mass_g: 50000, + transportation_method: 'rail' + }); + const estimate = createEstimateResponse.data; + + expect(estimate.type).to.be.eq('ecommerce'); + expect(estimate.mass_g).to.be.above(0); + expect(estimate.production).to.be.eq(false); + expect(estimate.order).to.be.eq(null); + }); + it('supports creating vehicle estimates without an order', async function () { const createEstimateResponse = await patch.estimates.createVehicleEstimate({ distance_m: 100000,