Skip to content

Commit 64481e0

Browse files
authored
Add /estimates/ecommerce API support (#77)
1 parent 99f0ea7 commit 64481e0

12 files changed

+163
-12
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.24.2] - 2022-08-10
9+
10+
### Added
11+
12+
- Adds `patch.estimates.createEcommerceEstimate` method
13+
814
## [1.24.0] - 2022-07-22
915

1016
### Added

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ patch.estimates.createMassEstimate({ mass_g });
122122
const distance_m = 9000000; // Pass in the distance traveled in meters
123123
patch.estimates.createFlightEstimate({ distance_m });
124124

125-
// Create a shipping estimate
125+
// Create an ecommerce estimate
126126
const distance_m = 9000000;
127127
// Pass in the shipping distance in meters, the transportation method, and the package mass
128-
patch.estimates.createShippingEstimate({
128+
patch.estimates.createEcommerceEstimate({
129129
distance_m,
130-
transportation_method: 'air',
131-
package_mass_g: 1000
130+
package_mass_g: 1000,
131+
transportation_method: 'air'
132132
});
133133

134134
// Create a bitcoin estimate

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@patch-technology/patch",
3-
"version": "1.24.1",
3+
"version": "1.24.2",
44
"description": "Node.js wrapper for the Patch API",
55
"license": "MIT",
66
"repository": {

src/ApiClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApiClient {
1616
};
1717

1818
this.defaultHeaders = {
19-
'User-Agent': 'patch-node/1.24.1'
19+
'User-Agent': 'patch-node/1.24.2'
2020
};
2121

2222
/**

src/api/EstimatesApi.js

+50
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import ApiClient from '../ApiClient';
99
import CreateAirShippingEstimateRequest from '../model/CreateAirShippingEstimateRequest';
1010
import CreateBitcoinEstimateRequest from '../model/CreateBitcoinEstimateRequest';
11+
import CreateEcommerceEstimateRequest from '../model/CreateEcommerceEstimateRequest';
1112
import CreateEthereumEstimateRequest from '../model/CreateEthereumEstimateRequest';
1213
import CreateFlightEstimateRequest from '../model/CreateFlightEstimateRequest';
1314
import CreateHotelEstimateRequest from '../model/CreateHotelEstimateRequest';
@@ -122,6 +123,55 @@ export default class EstimatesApi {
122123
return this.createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest);
123124
}
124125

126+
createEcommerceEstimateWithHttpInfo(createEcommerceEstimateRequest) {
127+
const _createEcommerceEstimateRequest =
128+
CreateEcommerceEstimateRequest.constructFromObject(
129+
createEcommerceEstimateRequest,
130+
new CreateEcommerceEstimateRequest()
131+
);
132+
133+
// verify the required parameter 'createEcommerceEstimateRequest' is set
134+
if (
135+
_createEcommerceEstimateRequest === undefined ||
136+
_createEcommerceEstimateRequest === null
137+
) {
138+
throw new Error(
139+
"Missing the required parameter 'createEcommerceEstimateRequest' when calling createEcommerceEstimate"
140+
);
141+
}
142+
143+
let postBody = _createEcommerceEstimateRequest;
144+
let pathParams = {};
145+
let queryParams = {};
146+
let headerParams = {};
147+
let formParams = {};
148+
149+
let authNames = ['bearer_auth'];
150+
let contentTypes = ['application/json'];
151+
let accepts = ['application/json'];
152+
let returnType = EstimateResponse;
153+
154+
return this.apiClient.callApi(
155+
'/v1/estimates/ecommerce',
156+
'POST',
157+
pathParams,
158+
queryParams,
159+
headerParams,
160+
formParams,
161+
postBody,
162+
authNames,
163+
contentTypes,
164+
accepts,
165+
returnType
166+
);
167+
}
168+
169+
createEcommerceEstimate(createEcommerceEstimateRequest) {
170+
return this.createEcommerceEstimateWithHttpInfo(
171+
createEcommerceEstimateRequest
172+
);
173+
}
174+
125175
createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest) {
126176
const _createEthereumEstimateRequest =
127177
CreateEthereumEstimateRequest.constructFromObject(

src/model/CreateAirShippingEstimateRequest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CreateAirShippingEstimateRequest.prototype['aircraft_type'] = 'unknown';
8888

8989
CreateAirShippingEstimateRequest.prototype['freight_mass_g'] = undefined;
9090

91-
CreateAirShippingEstimateRequest.prototype['emissions_scope'] = 'wtw';
91+
CreateAirShippingEstimateRequest.prototype['emissions_scope'] = 'ttw';
9292

9393
CreateAirShippingEstimateRequest.prototype['project_id'] = undefined;
9494

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
10+
class CreateEcommerceEstimateRequest {
11+
constructor(distanceM, packageMassG, transportationMethod) {
12+
CreateEcommerceEstimateRequest.initialize(
13+
this,
14+
distanceM,
15+
packageMassG,
16+
transportationMethod
17+
);
18+
}
19+
20+
static initialize(obj, distanceM, packageMassG, transportationMethod) {
21+
obj['distance_m'] = distanceM;
22+
obj['package_mass_g'] = packageMassG;
23+
obj['transportation_method'] = transportationMethod;
24+
}
25+
26+
static constructFromObject(data, obj) {
27+
if (data) {
28+
obj = obj || new CreateEcommerceEstimateRequest();
29+
30+
if (data.hasOwnProperty('distance_m')) {
31+
obj['distance_m'] = ApiClient.convertToType(
32+
data['distance_m'],
33+
'Number'
34+
);
35+
}
36+
37+
if (data.hasOwnProperty('package_mass_g')) {
38+
obj['package_mass_g'] = ApiClient.convertToType(
39+
data['package_mass_g'],
40+
'Number'
41+
);
42+
}
43+
44+
if (data.hasOwnProperty('transportation_method')) {
45+
obj['transportation_method'] = ApiClient.convertToType(
46+
data['transportation_method'],
47+
'String'
48+
);
49+
}
50+
51+
if (data.hasOwnProperty('project_id')) {
52+
obj['project_id'] = ApiClient.convertToType(
53+
data['project_id'],
54+
'String'
55+
);
56+
}
57+
58+
if (data.hasOwnProperty('create_order')) {
59+
obj['create_order'] = ApiClient.convertToType(
60+
data['create_order'],
61+
'Boolean'
62+
);
63+
}
64+
}
65+
return obj;
66+
}
67+
}
68+
69+
CreateEcommerceEstimateRequest.prototype['distance_m'] = undefined;
70+
71+
CreateEcommerceEstimateRequest.prototype['package_mass_g'] = undefined;
72+
73+
CreateEcommerceEstimateRequest.prototype['transportation_method'] = undefined;
74+
75+
CreateEcommerceEstimateRequest.prototype['project_id'] = undefined;
76+
77+
CreateEcommerceEstimateRequest.prototype['create_order'] = false;
78+
79+
export default CreateEcommerceEstimateRequest;

src/model/CreateRailShippingEstimateRequest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ CreateRailShippingEstimateRequest.prototype['fuel_type'] = 'default';
114114

115115
CreateRailShippingEstimateRequest.prototype['freight_mass_g'] = undefined;
116116

117-
CreateRailShippingEstimateRequest.prototype['emissions_scope'] = 'wtw';
117+
CreateRailShippingEstimateRequest.prototype['emissions_scope'] = 'ttw';
118118

119119
CreateRailShippingEstimateRequest.prototype['project_id'] = undefined;
120120

src/model/CreateRoadShippingEstimateRequest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ CreateRoadShippingEstimateRequest.prototype['cargo_type'] = 'average_mixed';
142142

143143
CreateRoadShippingEstimateRequest.prototype['container_size_code'] = undefined;
144144

145-
CreateRoadShippingEstimateRequest.prototype['emissions_scope'] = 'wtw';
145+
CreateRoadShippingEstimateRequest.prototype['emissions_scope'] = 'ttw';
146146

147147
CreateRoadShippingEstimateRequest.prototype['freight_mass_g'] = undefined;
148148

src/model/CreateSeaShippingEstimateRequest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ CreateSeaShippingEstimateRequest.prototype['origin_postal_code'] = undefined;
136136

137137
CreateSeaShippingEstimateRequest.prototype['container_size_code'] = undefined;
138138

139-
CreateSeaShippingEstimateRequest.prototype['emissions_scope'] = 'wtw';
139+
CreateSeaShippingEstimateRequest.prototype['emissions_scope'] = 'ttw';
140140

141141
CreateSeaShippingEstimateRequest.prototype['freight_mass_g'] = undefined;
142142

test/integration/estimates.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ describe('Estimates Integration', function () {
5252
expect(estimate.order).to.be.eq(null);
5353
});
5454

55+
it('supports creating ecommerce estimates', async function () {
56+
const createEstimateResponse =
57+
await patch.estimates.createEcommerceEstimate({
58+
create_order: false,
59+
distance_m: 100000,
60+
package_mass_g: 50000,
61+
transportation_method: 'rail'
62+
});
63+
const estimate = createEstimateResponse.data;
64+
65+
expect(estimate.type).to.be.eq('ecommerce');
66+
expect(estimate.mass_g).to.be.above(0);
67+
expect(estimate.production).to.be.eq(false);
68+
expect(estimate.order).to.be.eq(null);
69+
});
70+
5571
it('supports creating vehicle estimates without an order', async function () {
5672
const createEstimateResponse = await patch.estimates.createVehicleEstimate({
5773
distance_m: 100000,

0 commit comments

Comments
 (0)