Skip to content

Commit 61386e4

Browse files
boconnell2kleinjm
andauthored
Add hotel estimates (#60)
* Added hotel estimates * Generated SDK * Added test code * Update README.md Co-authored-by: James Klein <[email protected]> * Deleted lock files and adjusted test * Adjusted README * Added package-lock file back * Reran generate sdk function Co-authored-by: James Klein <[email protected]>
1 parent 9c2dc13 commit 61386e4

File tree

8 files changed

+185
-5
lines changed

8 files changed

+185
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
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.19.0] - 2022-04-11
9+
10+
### Added
11+
12+
- Adds `patch.estimates.createHotelEstimate()` method
13+
814
## [1.18.0] - 2022-03-22
915

1016
### Changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,30 @@ patch.estimates.createBitcoinEstimate({
126126

127127
// Create a vehicle estimate
128128
const distance_m = 9000000;
129-
// Pass in the shipping distance in meters and the model/make/year of the vehicle
129+
// Pass in the driving distance in meters and the model/make/year of the vehicle
130130
patch.estimates.createVehicleEstimate({
131131
distance_m,
132132
make: 'Toyota',
133133
model: 'Corolla',
134134
year: 1995
135135
});
136136

137+
// Create a hotel estimate
138+
const country_code = 'US'; // ISO3166 alpha-2 country code
139+
const city = 'New York'; // [Optional]
140+
const region = 'New York'; // [Optional]
141+
const star_rating = 4; // [Optional] Star rating of the hotel from 2 to 5
142+
const number_of_nights = 2; // [Optional] Default value is 1
143+
const number_of_rooms = 2; // [Optional] Default value is 1
144+
patch.estimates.createHotelEstimate({
145+
country_code,
146+
city,
147+
region,
148+
star_rating,
149+
number_of_nights,
150+
number_of_rooms
151+
});
152+
137153
// Retrieve an estimate
138154
const estimateId = 'est_test_1234';
139155
patch.estimates.retrieveEstimate(estimate_id);
@@ -230,6 +246,7 @@ patch.projects.retrieveProjects().then((response) => console.log(response));
230246
### Run the specs
231247

232248
Before running the tests, make sure you set the test API key! Please use test API keys and not production ones, they usually start with `key_test_`.
249+
Be sure you navigate back to the root `patch-node` directory to run the tests.
233250

234251
```sh
235252
$ export SANDBOX_API_KEY=<PATCH_TEST_API_KEY>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

src/ApiClient.js

Lines changed: 1 addition & 1 deletion
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.18.0'
19+
'User-Agent': 'patch-node/1.19.0'
2020
};
2121

2222
/**

src/api/EstimatesApi.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ApiClient from '../ApiClient';
99
import CreateBitcoinEstimateRequest from '../model/CreateBitcoinEstimateRequest';
1010
import CreateEthereumEstimateRequest from '../model/CreateEthereumEstimateRequest';
1111
import CreateFlightEstimateRequest from '../model/CreateFlightEstimateRequest';
12+
import CreateHotelEstimateRequest from '../model/CreateHotelEstimateRequest';
1213
import CreateMassEstimateRequest from '../model/CreateMassEstimateRequest';
1314
import CreateShippingEstimateRequest from '../model/CreateShippingEstimateRequest';
1415
import CreateVehicleEstimateRequest from '../model/CreateVehicleEstimateRequest';
@@ -164,6 +165,53 @@ export default class EstimatesApi {
164165
return this.createFlightEstimateWithHttpInfo(createFlightEstimateRequest);
165166
}
166167

168+
createHotelEstimateWithHttpInfo(createHotelEstimateRequest) {
169+
const _createHotelEstimateRequest =
170+
CreateHotelEstimateRequest.constructFromObject(
171+
createHotelEstimateRequest,
172+
new CreateHotelEstimateRequest()
173+
);
174+
let postBody = _createHotelEstimateRequest;
175+
176+
// verify the required parameter 'createHotelEstimateRequest' is set
177+
if (
178+
_createHotelEstimateRequest === undefined ||
179+
_createHotelEstimateRequest === null
180+
) {
181+
throw new Error(
182+
"Missing the required parameter 'createHotelEstimateRequest' when calling createHotelEstimate"
183+
);
184+
}
185+
186+
let pathParams = {};
187+
let queryParams = {};
188+
let headerParams = {};
189+
let formParams = {};
190+
191+
let authNames = ['bearer_auth'];
192+
let contentTypes = ['application/json'];
193+
let accepts = ['application/json'];
194+
let returnType = EstimateResponse;
195+
196+
return this.apiClient.callApi(
197+
'/v1/estimates/hotel',
198+
'POST',
199+
pathParams,
200+
queryParams,
201+
headerParams,
202+
formParams,
203+
postBody,
204+
authNames,
205+
contentTypes,
206+
accepts,
207+
returnType
208+
);
209+
}
210+
211+
createHotelEstimate(createHotelEstimateRequest) {
212+
return this.createHotelEstimateWithHttpInfo(createHotelEstimateRequest);
213+
}
214+
167215
createMassEstimateWithHttpInfo(createMassEstimateRequest) {
168216
const _createMassEstimateRequest =
169217
CreateMassEstimateRequest.constructFromObject(
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 CreateHotelEstimateRequest {
11+
constructor(countryCode) {
12+
CreateHotelEstimateRequest.initialize(this, countryCode);
13+
}
14+
15+
static initialize(obj, countryCode) {
16+
obj['country_code'] = countryCode;
17+
}
18+
19+
static constructFromObject(data, obj) {
20+
if (data) {
21+
obj = obj || new CreateHotelEstimateRequest();
22+
23+
if (data.hasOwnProperty('country_code')) {
24+
obj['country_code'] = ApiClient.convertToType(
25+
data['country_code'],
26+
'String'
27+
);
28+
}
29+
30+
if (data.hasOwnProperty('city')) {
31+
obj['city'] = ApiClient.convertToType(data['city'], 'String');
32+
}
33+
34+
if (data.hasOwnProperty('region')) {
35+
obj['region'] = ApiClient.convertToType(data['region'], 'String');
36+
}
37+
38+
if (data.hasOwnProperty('star_rating')) {
39+
obj['star_rating'] = ApiClient.convertToType(
40+
data['star_rating'],
41+
'Number'
42+
);
43+
}
44+
45+
if (data.hasOwnProperty('number_of_nights')) {
46+
obj['number_of_nights'] = ApiClient.convertToType(
47+
data['number_of_nights'],
48+
'Number'
49+
);
50+
}
51+
52+
if (data.hasOwnProperty('number_of_rooms')) {
53+
obj['number_of_rooms'] = ApiClient.convertToType(
54+
data['number_of_rooms'],
55+
'Number'
56+
);
57+
}
58+
59+
if (data.hasOwnProperty('project_id')) {
60+
obj['project_id'] = ApiClient.convertToType(
61+
data['project_id'],
62+
'String'
63+
);
64+
}
65+
66+
if (data.hasOwnProperty('create_order')) {
67+
obj['create_order'] = ApiClient.convertToType(
68+
data['create_order'],
69+
'Boolean'
70+
);
71+
}
72+
}
73+
return obj;
74+
}
75+
}
76+
77+
CreateHotelEstimateRequest.prototype['country_code'] = undefined;
78+
79+
CreateHotelEstimateRequest.prototype['city'] = undefined;
80+
81+
CreateHotelEstimateRequest.prototype['region'] = undefined;
82+
83+
CreateHotelEstimateRequest.prototype['star_rating'] = undefined;
84+
85+
CreateHotelEstimateRequest.prototype['number_of_nights'] = undefined;
86+
87+
CreateHotelEstimateRequest.prototype['number_of_rooms'] = undefined;
88+
89+
CreateHotelEstimateRequest.prototype['project_id'] = undefined;
90+
91+
CreateHotelEstimateRequest.prototype['create_order'] = false;
92+
93+
export default CreateHotelEstimateRequest;

test/integration/estimates.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,20 @@ describe('Estimates Integration', function () {
135135
expect(estimate.mass_g).to.be.above(0);
136136
expect(estimate.production).to.be.eq(false);
137137
});
138+
139+
it('supports creating hotel estimates', async function () {
140+
const createEstimateResponse = await patch.estimates.createHotelEstimate({
141+
country_code: 'US',
142+
city: 'New York',
143+
region: 'New York',
144+
star_rating: 5,
145+
number_of_nights: 2,
146+
number_of_rooms: 2
147+
});
148+
const estimate = createEstimateResponse.data;
149+
150+
expect(estimate.type).to.be.eq('hotel');
151+
expect(estimate.mass_g).to.be.above(150_000);
152+
expect(estimate.production).to.be.eq(false);
153+
});
138154
});

0 commit comments

Comments
 (0)