Skip to content

Commit

Permalink
Add hotel estimates (#60)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
boconnell2 and kleinjm authored Apr 11, 2022
1 parent 9c2dc13 commit 61386e4
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 5 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.19.0] - 2022-04-11

### Added

- Adds `patch.estimates.createHotelEstimate()` method

## [1.18.0] - 2022-03-22

### Changed
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,30 @@ patch.estimates.createBitcoinEstimate({

// Create a vehicle estimate
const distance_m = 9000000;
// Pass in the shipping distance in meters and the model/make/year of the vehicle
// Pass in the driving distance in meters and the model/make/year of the vehicle
patch.estimates.createVehicleEstimate({
distance_m,
make: 'Toyota',
model: 'Corolla',
year: 1995
});

// Create a hotel estimate
const country_code = 'US'; // ISO3166 alpha-2 country code
const city = 'New York'; // [Optional]
const region = 'New York'; // [Optional]
const star_rating = 4; // [Optional] Star rating of the hotel from 2 to 5
const number_of_nights = 2; // [Optional] Default value is 1
const number_of_rooms = 2; // [Optional] Default value is 1
patch.estimates.createHotelEstimate({
country_code,
city,
region,
star_rating,
number_of_nights,
number_of_rooms
});

// Retrieve an estimate
const estimateId = 'est_test_1234';
patch.estimates.retrieveEstimate(estimate_id);
Expand Down Expand Up @@ -230,6 +246,7 @@ patch.projects.retrieveProjects().then((response) => console.log(response));
### Run the specs

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_`.
Be sure you navigate back to the root `patch-node` directory to run the tests.

```sh
$ export SANDBOX_API_KEY=<PATCH_TEST_API_KEY>
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.18.0",
"version": "1.19.0",
"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.18.0'
'User-Agent': 'patch-node/1.19.0'
};

/**
Expand Down
48 changes: 48 additions & 0 deletions src/api/EstimatesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ApiClient from '../ApiClient';
import CreateBitcoinEstimateRequest from '../model/CreateBitcoinEstimateRequest';
import CreateEthereumEstimateRequest from '../model/CreateEthereumEstimateRequest';
import CreateFlightEstimateRequest from '../model/CreateFlightEstimateRequest';
import CreateHotelEstimateRequest from '../model/CreateHotelEstimateRequest';
import CreateMassEstimateRequest from '../model/CreateMassEstimateRequest';
import CreateShippingEstimateRequest from '../model/CreateShippingEstimateRequest';
import CreateVehicleEstimateRequest from '../model/CreateVehicleEstimateRequest';
Expand Down Expand Up @@ -164,6 +165,53 @@ export default class EstimatesApi {
return this.createFlightEstimateWithHttpInfo(createFlightEstimateRequest);
}

createHotelEstimateWithHttpInfo(createHotelEstimateRequest) {
const _createHotelEstimateRequest =
CreateHotelEstimateRequest.constructFromObject(
createHotelEstimateRequest,
new CreateHotelEstimateRequest()
);
let postBody = _createHotelEstimateRequest;

// verify the required parameter 'createHotelEstimateRequest' is set
if (
_createHotelEstimateRequest === undefined ||
_createHotelEstimateRequest === null
) {
throw new Error(
"Missing the required parameter 'createHotelEstimateRequest' when calling createHotelEstimate"
);
}

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/hotel',
'POST',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
authNames,
contentTypes,
accepts,
returnType
);
}

createHotelEstimate(createHotelEstimateRequest) {
return this.createHotelEstimateWithHttpInfo(createHotelEstimateRequest);
}

createMassEstimateWithHttpInfo(createMassEstimateRequest) {
const _createMassEstimateRequest =
CreateMassEstimateRequest.constructFromObject(
Expand Down
93 changes: 93 additions & 0 deletions src/model/CreateHotelEstimateRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Patch API V1
* The core API used to integrate with Patch's service
*
* Contact: [email protected]
*/

import ApiClient from '../ApiClient';

class CreateHotelEstimateRequest {
constructor(countryCode) {
CreateHotelEstimateRequest.initialize(this, countryCode);
}

static initialize(obj, countryCode) {
obj['country_code'] = countryCode;
}

static constructFromObject(data, obj) {
if (data) {
obj = obj || new CreateHotelEstimateRequest();

if (data.hasOwnProperty('country_code')) {
obj['country_code'] = ApiClient.convertToType(
data['country_code'],
'String'
);
}

if (data.hasOwnProperty('city')) {
obj['city'] = ApiClient.convertToType(data['city'], 'String');
}

if (data.hasOwnProperty('region')) {
obj['region'] = ApiClient.convertToType(data['region'], 'String');
}

if (data.hasOwnProperty('star_rating')) {
obj['star_rating'] = ApiClient.convertToType(
data['star_rating'],
'Number'
);
}

if (data.hasOwnProperty('number_of_nights')) {
obj['number_of_nights'] = ApiClient.convertToType(
data['number_of_nights'],
'Number'
);
}

if (data.hasOwnProperty('number_of_rooms')) {
obj['number_of_rooms'] = ApiClient.convertToType(
data['number_of_rooms'],
'Number'
);
}

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;
}
}

CreateHotelEstimateRequest.prototype['country_code'] = undefined;

CreateHotelEstimateRequest.prototype['city'] = undefined;

CreateHotelEstimateRequest.prototype['region'] = undefined;

CreateHotelEstimateRequest.prototype['star_rating'] = undefined;

CreateHotelEstimateRequest.prototype['number_of_nights'] = undefined;

CreateHotelEstimateRequest.prototype['number_of_rooms'] = undefined;

CreateHotelEstimateRequest.prototype['project_id'] = undefined;

CreateHotelEstimateRequest.prototype['create_order'] = false;

export default CreateHotelEstimateRequest;
16 changes: 16 additions & 0 deletions test/integration/estimates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,20 @@ describe('Estimates Integration', function () {
expect(estimate.mass_g).to.be.above(0);
expect(estimate.production).to.be.eq(false);
});

it('supports creating hotel estimates', async function () {
const createEstimateResponse = await patch.estimates.createHotelEstimate({
country_code: 'US',
city: 'New York',
region: 'New York',
star_rating: 5,
number_of_nights: 2,
number_of_rooms: 2
});
const estimate = createEstimateResponse.data;

expect(estimate.type).to.be.eq('hotel');
expect(estimate.mass_g).to.be.above(150_000);
expect(estimate.production).to.be.eq(false);
});
});

0 comments on commit 61386e4

Please sign in to comment.