Skip to content

Commit

Permalink
Add /estimates/ecommerce API support (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtbp authored Aug 11, 2022
1 parent 99f0ea7 commit 64481e0
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.24.2] - 2022-08-10

### Added

- Adds `patch.estimates.createEcommerceEstimate` method

## [1.24.0] - 2022-07-22

### Added
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ApiClient {
};

this.defaultHeaders = {
'User-Agent': 'patch-node/1.24.1'
'User-Agent': 'patch-node/1.24.2'
};

/**
Expand Down
50 changes: 50 additions & 0 deletions src/api/EstimatesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/model/CreateAirShippingEstimateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
79 changes: 79 additions & 0 deletions src/model/CreateEcommerceEstimateRequest.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion src/model/CreateRailShippingEstimateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/model/CreateRoadShippingEstimateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/model/CreateSeaShippingEstimateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions test/integration/estimates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 64481e0

Please sign in to comment.