Code Monkey home page Code Monkey logo

impala-js's Introduction

Impala API Javascript SDK

Actions Status

A port of https://github.com/GetImpala/impala-php

Installation

It's as simple as:

$ npm i @rpallas/impala-js

Tests

To run the tests you can run the following commands:

$ npm i
$ npm test

Obtaining an API key

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.

Getting Started

After installation, you can create an impala client like this:

const ImpalaSDK = require('@rpallas/impala-js')

const impala = ImpalaSDK.create('api-key')

Working with a single hotel

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' })

Working with multiple hotels

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()

Making API calls

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']})

Config

A config object containing the following properties can be passed to the create function.

  • hotelId - The hotelId of the hotel to return when working with a single hotel.
  • useragent - A useragent string which is appended to the User-Agent header in requests. Can also be set to false to disable the useragent header.

Example

const config = {
  hotelId: 'hotelId',
  useragent: `${myAppName}/${myAppVersion}`
}
const impala = ImpalaSDK.create('api-key', config)

API methods

Name HTTP API endpoint
getAllocationById GET /v2/hotel/:hotelId/allocation/:allocationId
getAllocations GET /v2/hotel/:hotelId/allocation
getAreaById GET /v2/hotel/:hotelId/area/:areaId
getAreas GET /v2/hotel/:hotelId/area
getAreaTypeById GET /v2/hotel/:hotelId/area-type/:areaTypeId
getAreaTypes [GET /v2/hotel/:hotelId/area-type][type-area-type]
getBillById GET /v2/hotel/:hotelId/bill/:billId
getChargeByIdForBill GET /v2/hotel/:hotelId/bill/:billId/charge/:chargeId
getChargesForBill GET /v2/hotel/:hotelId/bill/:billId/charge
createChargeForBill POST /v2/hotel/:hotelId/bill/:billId/charge
refundChargeByIdForBill POST /v2/hotel/:hotelId/bill/:billId/charge/:chargeId/refund
getPaymentByIdForBill GET /v2/hotel/:hotelId/bill/:billId/payment/:paymentId
getPaymentsForBill GET /v2/hotel/:hotelId/bill/:billId/payment
createPaymentForBill POST /v2/hotel/:hotelId/bill/:billId/payment
refundPaymentByIdForBill POST /v2/hotel/:hotelId/bill/:billId/payment/:paymentId/refund
getBookingById GET /v2/hotel/:hotelId/booking/:bookingId
getBookings GET /v2/hotel/:hotelId/booking
createBooking POST /v2/hotel/:hotelId/booking
updateBookingById PATCH /v2/hotel/:hotelId/booking/:bookingId
checkInBookingById POST /v2/hotel/:hotelId/booking/:bookingId/check-in
checkOutBookingById POST /v2/hotel/:hotelId/booking/:bookingId/check-out
cancelBookingById POST /v2/hotel/:hotelId/booking/:bookingId/cancel
getGuestsForBooking GET /v2/hotel/:hotelId/booking/:bookingId/guest
getBillsForBooking GET /v2/hotel/:hotelId/booking/:bookingId/bill
getBookingSets [GET /v2/hotel/:hotelId/booking-set][type-bookingset]
getBookingSetById [GET /v2/hotel/:hotelId/booking-set/:bookingSetId][type-bookingset]
createBookingSet [POST /v2/hotel/:hotelId/booking-set][type-bookingset]
updateBookingSet [PATCH /v2/hotel/:hotelId/booking-set/:bookingSetId][type-bookingset]
getExtraById GET /v2/hotel/:hotelId/extra/:extraId
getExtras GET /v2/hotel/:hotelId/extra
getGuestById GET /v2/hotel/:hotelId/guest/:guestId
getGuests GET /v2/hotel/:hotelId/guest
createGuest POST /v2/hotel/:hotelId/guest
updateGuest PATCH /v2/hotel/:hotelId/guest/:guestId
getBillsForGuest GET /v2/hotel/:hotelId/guest/:guestId/bill
getRatePlanById GET /v2/hotel/:hotelId/rate-plan/:ratePlanId
getRatePlans GET /v2/hotel/:hotelId/rate-plan
getPriceForRatePlan GET /v2/hotel/:hotelId/rate-plan/:ratePlanId/price
updatePriceForRatePlan PUT /v2/hotel/:hotelId/rate-plan/:ratePlanId/price
getRateSets GET /v2/hotel/:hotelId/rate-set

impala-js's People

Contributors

rpallas avatar renovate-bot avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.