diff --git a/CHANGELOG.md b/CHANGELOG.md index c61a051..f90cacf 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.19.0] - 2022-04-11 + +### Added + +- Adds `patch.estimates.createHotelEstimate()` method + ## [1.18.0] - 2022-03-22 ### Changed diff --git a/README.md b/README.md index 1c52072..b978767 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ 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', @@ -134,6 +134,22 @@ patch.estimates.createVehicleEstimate({ 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); @@ -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= diff --git a/package-lock.json b/package-lock.json index cb12305..1c21899 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.18.0", + "version": "1.19.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.18.0", + "version": "1.19.0", "license": "MIT", "dependencies": { "query-string": "^7.0.1", diff --git a/package.json b/package.json index fc425d0..f4202ae 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/ApiClient.js b/src/ApiClient.js index 20f0b77..7e2655c 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -16,7 +16,7 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.18.0' + 'User-Agent': 'patch-node/1.19.0' }; /** diff --git a/src/api/EstimatesApi.js b/src/api/EstimatesApi.js index 925af83..cdac3bc 100644 --- a/src/api/EstimatesApi.js +++ b/src/api/EstimatesApi.js @@ -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'; @@ -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( diff --git a/src/model/CreateHotelEstimateRequest.js b/src/model/CreateHotelEstimateRequest.js new file mode 100644 index 0000000..d82cad5 --- /dev/null +++ b/src/model/CreateHotelEstimateRequest.js @@ -0,0 +1,93 @@ +/** + * Patch API V1 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +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; diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index 6592071..bf76126 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -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); + }); });