A port of https://github.com/GetImpala/impala-php
It's as simple as:
$ npm i @rpallas/impala-js
To run the tests you can run the following commands:
$ npm i
$ npm test
To use this library, you will need an Impala API key. More information can be found in the 'Getting Started' section of the Impala developer documentation.
After installation, you can create an impala client like this:
const ImpalaSDK = require('@rpallas/impala-js')
const impala = ImpalaSDK.create('api-key')
If your application will only be dealing with a single hotel at a time, you can instantiate the Impala API like this:
const hotel = ImpalaSDK.create('api-key', { hotelId: 'hotelId' })
If your application will be dealing with multiple hotels, you can omit the hotelId
config parameter, like so:
const impala = ImpalaSDK.create('api-key')
// You can then pass the hotelId directly to the method
await impala.getBookings({ hotelId: 'hotelId' })
// Or with extra parameters
await impala.getBookings({
hotelId: 'hotelId',
startDate: '2018-02-03',
endDate: '2018-02-05'
})
// Or, you can call getHotel to return a single-hotel API instance
const hotel = impala.getHotel('hotelId')
// You can then call the API methods like normal
await hotel.getBookings()
API methods accept an object as their first argument, containing the parameters for the API call. This can be omitted if there are no arguments to set.
API methods that take an ID have the ID as the first argument.
API methods that update a resource take the object representation of a JSON merge patch as their second argument.
For example:
const ImpalaSDK = require('@rpallas/impala-js')
const impala = impalaSDK.create('api-key')
const hotel = impala.getHotel('hotelId')
await hotel.updateBookingById('bookingId', { start: 123456, roomIds: ['abc', 'cde']})
A config
object containing the following properties can be passed to the create
function.
hotelId
- ThehotelId
of the hotel to return when working with a single hotel.useragent
- A useragent string which is appended to theUser-Agent
header in requests. Can also be set tofalse
to disable the useragent header.
const config = {
hotelId: 'hotelId',
useragent: `${myAppName}/${myAppVersion}`
}
const impala = ImpalaSDK.create('api-key', config)