Giter Site home page Giter Site logo

dustygaron / amadeus-node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amadeus4dev/amadeus-node

0.0 1.0 0.0 1.85 MB

Node library for the Amadeus Self-Service travel APIs

Home Page: https://developer.amadeus.com

License: MIT License

JavaScript 100.00%

amadeus-node's Introduction

Amadeus Node SDK

Module Version Build Status Maintainability Dependencies Contact Support

Amadeus provides a set of APIs for the travel industry. Flights, Hotels, Locations and more.

For more details see the Node documentation on Amadeus.com.

Installation

This module has been tested using Node 6 and higher, though it should work with Node 4 and 5 as well. You can install install it using Yarn or NPM.

npm install amadeus --save

Getting Started

To make your first API call you will need to register for an Amadeus Developer Account and set up your first application.

var Amadeus = require('amadeus');

var amadeus = new Amadeus({
  clientId: 'REPLACE_BY_YOUR_API_KEY',
  clientSecret: 'REPLACE_BY_YOUR_API_SECRET'
});

amadeus.referenceData.urls.checkinLinks.get({
  airlineCode: 'BA'
}).then(function(response){
  console.log(response.data[0].href);
}).catch(function(responseError){
  console.log(responseError.code);
});

Initialization

The client can be initialized directly.

// Initialize using parameters
var amadeus = new Amadeus({
  clientId: 'REPLACE_BY_YOUR_API_KEY',
  clientSecret: 'REPLACE_BY_YOUR_API_SECRET'
});

Alternatively it can be initialized without any parameters if the environment variables AMADEUS_CLIENT_ID and AMADEUS_CLIENT_SECRET are present.

var amadeus = new Amadeus();

Your credentials can be found on the Amadeus dashboard. Sign up for an account today.

By default the environment for the SDK is the test environment. To switch to a production (paid-for) environment please switch the hostname as follows:

var amadeus = new Amadeus({
  hostname: 'production'
});

Documentation

Amadeus has a large set of APIs, and our documentation is here to get you started today. Head over to our Reference documentation for in-depth information about every SDK method, it's arguments and return types.

Making API calls

This library conveniently maps every API path to a similar path.

For example, GET /v2/reference-data/urls/checkin-links?airlineCode=BA would be:

amadeus.referenceData.urls.checkinLinks.get({ airlineCode: 'BA' });

Similarly, to select a resource by ID, you can pass in the ID to the singular path.

For example, GET /v1/shopping/hotelOffer/123/ would be:

amadeus.shopping.hotelOffer('123').get(...);

You can make any arbitrary API call as well directly with the .client.get method:

amadeus.client.get('/v2/reference-data/urls/checkin-links', { airlineCode: 'BA' });

Promises

Every API call returns a Promise that either resolves or rejects. Every resolved API call returns a Response object containing a body attribute with the raw response. If the API call contained a JSON response it will parse the JSON into the .result attribute. If this data also contains a data key, it will make that available as the .data attribute.

For a failed API call it returns a ResponseError containing the (parsed or unparsed) response, the request, and an error code.

amadeus.referenceData.urls.checkinLinks.get({
  airlineCode: 'BA'
}).then(function(response){
  console.log(response.body);   //=> The raw body
  console.log(response.result); //=> The fully parsed result
  console.log(response.data);   //=> The data attribute taken from the result
}).catch(function(error){
  console.log(error.response); //=> The response object with (un)parsed data
  console.log(error.response.request); //=> The details of the request made
  console.log(error.code); //=> A unique error code to identify the type of error
});

Pagination

If an API endpoint supports pagination, the other pages are available under the .next, .previous, .last and .first methods.

amadeus.referenceData.locations.get({
  keyword: 'LON',
  subType: 'AIRPORT,CITY'
}).then(function(response){
  console.log(response.data); // first page
  return amadeus.next(response);
}).then(function(nextResponse){
  console.log(nextResponse.data); // second page
});

If a page is not available, the response will resolve to null.

Logging & Debugging

The SDK makes it easy to add your own logger compatible with the default console.

var amadeus = new Amadeus({
  clientId: 'REPLACE_BY_YOUR_API_KEY',
  clientSecret: 'REPLACE_BY_YOUR_API_SECRET',
  logger: new MyConsole()
});

Additionally, to enable more verbose logging, you can set the appropriate level on your own logger, though the easiest way would be to enable debugging via a parameter on initialization, or using the AMADEUS_LOG_LEVEL environment variable. The available options are silent (default), warn, and debug.

var amadeus = new Amadeus({
  clientId: 'REPLACE_BY_YOUR_API_KEY',
  clientSecret: 'REPLACE_BY_YOUR_API_SECRET',
  logLevel: 'debug'
});

List of supported endpoints

// Flight Inspiration Search
amadeus.shopping.flightDestinations.get({
  origin : 'MAD'
})

// Flight Cheapest Date Search
amadeus.shopping.flightDates.get({
  origin : 'MAD',
  destination : 'MUC'
})

// Flight Low-fare Search
  amadeus.shopping.flightOffers.get({
  origin : 'NYC',
  destination : 'MAD',
  departureDate : '2019-08-01'
})

// Flight Checkin Links
amadeus.referenceData.urls.checkinLinks.get({
  airlineCode : 'BA'
})

// Airline Code Lookup
amadeus.referenceData.airlines.get({
  airlineCodes : 'U2'
})

// Airports and City Search (autocomplete)
// Find all the cities and airports starting by 'LON'
amadeus.referenceData.locations.get({
  keyword : 'LON',
  subType : Amadeus.location.any
})

// Get a specific city or airport based on its id
amadeus.referenceData.location('ALHR').get()

// Airport Nearest Relevant Airport (for London)
amadeus.referenceData.locations.airports.get({
  longitude : 0.1278,
  latitude  : 51.5074
})

// Flight Most Searched Destinations
// Which were the most searched flight destinations from Madrid in August 2017?
amadeus.travel.analytics.airTraffic.searched.get({
    originCityCode : 'MAD',
    searchPeriod : '2017-08',
    marketCountryCode : 'ES'
})
// How many people in Spain searched for a trip from Madrid to New-York in September 2017?
amadeus.travel.analytics.airTraffic.searchedByDestination.get({
    originCityCode : 'MAD',
    destinationCityCode : 'NYC',
    searchPeriod : '2017-08',
    marketCountryCode : 'ES'
})

// Flight Most Booked Destinations
amadeus.travel.analytics.airTraffic.booked.get({
    originCityCode : 'MAD',
    period : '2017-08'
})

// Flight Most Traveled Destinations
amadeus.travel.analytics.airTraffic.traveled.get({
    originCityCode : 'MAD',
    period : '2017-01'
})

// Flight Busiest Traveling Period
amadeus.travel.analytics.airTraffic.busiestPeriod.get({
    cityCode: 'MAD',
    period: '2017',
    direction: Amadeus.direction.arriving
})

// Hotel Search API
// Get list of hotels by city code
amadeus.shopping.hotelOffers.get({
  cityCode : 'MAD'
})
// Get list of offers for a specific hotel
amadeus.shopping.hotelOffersByHotel.get({
  hotelId : 'XKPARC12'
})
// Confirm the availability of a specific offer id 
amadeus.shopping.hotelOffer('XXX').get()

// Points of Interest
// What are the popular places in Barcelona (based a geo location and a radius)
amadeus.referenceData.locations.pointsOfInterest.get({
    latitude : 41.397158,
    longitude : 2.160873
})
 
// What are the popular places in Barcelona? (based on a square)
amadeus.referenceData.locations.pointsOfInterest.bySquare.get({
    north: 41.397158,
    west: 2.160873,
    south: 41.394582,
    east: 2.177181
})

// Hotel Ratings
// Get Sentiment Analysis of reviews about Holiday Inn Paris Notre Dame.
amadeus.eReputation.hotelSentiments.get({
    hotelIds: 'XKPARC12'
})

Development & Contributing

Want to contribute? Read our Contributors Guide for guidance on installing and running this code in a development environment.

License

This library is released under the MIT License.

Help

Our developer support team is here to help you. You can find us on StackOverflow and email.

amadeus-node's People

Watchers

 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.