Skip to content

Commit

Permalink
Add support for On-Demand Flight Status API (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyroux authored Sep 10, 2020
1 parent db95339 commit 487092d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ amadeus.safety.safetyRatedLocations.bySquare.get({
})
// What is the safety information of a location based on it's Id?
amadeus.safety.safetyRatedLocation('Q930400801').get()

// On-Demand Flight Status
// What's the current status of my flight?
amadeus.schedule.flights.get({
carrierCode: 'AZ',
flightNumber: '319',
scheduledDepartureDate: '2021-03-13'
})
```
## Development & Contributing
Expand Down
12 changes: 12 additions & 0 deletions spec/amadeus/namespaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe('Namespaces', () => {
expect(amadeus.referenceData.airlines).toBeDefined();
expect(amadeus.referenceData.recommendedLocations).toBeDefined();

expect(amadeus.schedule).toBeDefined();
expect(amadeus.schedule.flights).toBeDefined();

expect(amadeus.travel).toBeDefined();
expect(amadeus.travel.analytics).toBeDefined();
expect(amadeus.travel.analytics.airTraffic).toBeDefined();
Expand Down Expand Up @@ -106,6 +109,8 @@ describe('Namespaces', () => {

expect(amadeus.booking.flightOrder('XXX').get).toBeDefined();

expect(amadeus.schedule.flights.get).toBeDefined();

expect(amadeus.eReputation.hotelSentiments.get).toBeDefined();

expect(amadeus.media.files.generatedPhotos.get).toBeDefined();
Expand Down Expand Up @@ -193,6 +198,13 @@ describe('Namespaces', () => {
.toHaveBeenCalledWith('/v1/reference-data/airlines', {});
});

it('.amadeus.schedule.flights.get', () => {
amadeus.client.get = jest.fn();
amadeus.schedule.flights.get();
expect(amadeus.client.get)
.toHaveBeenCalledWith('/v2/schedule/flights', {});
});

it('.amadeus.travel.analytics.airTraffic.traveled.get', () => {
amadeus.client.get = jest.fn();
amadeus.travel.analytics.airTraffic.traveled.get();
Expand Down
5 changes: 4 additions & 1 deletion src/amadeus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import Travel from './amadeus/namespaces/travel';
import EReputation from './amadeus/namespaces/e_reputation';
import Media from './amadeus/namespaces/media';
import Airport from './amadeus/namespaces/airport';
import Safety from './amadeus/namespaces/safety';
import Safety from './amadeus/namespaces/safety';
import Schedule from './amadeus/namespaces/schedule';


/**
* The Amadeus client library for accessing the travel APIs.
Expand Down Expand Up @@ -69,6 +71,7 @@ class Amadeus {
this.airport = new Airport(this.client);
this.pagination = new Pagination(this.client);
this.safety = new Safety(this.client);
this.schedule = new Schedule(this.client);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/amadeus/namespaces/schedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Flights from './schedule/flights';

/**
* A namespaced client for the
* `/v2/schedule` endpoints
*
* Access via the {Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.schedule.flights;
* ```
*
* @param {Client} client
* @property {Flights} flights
* @protected
*/
class Schedule {
constructor(client) {
this.client = client;
this.flights = new Flights(client);
}
}

export default Schedule;
42 changes: 42 additions & 0 deletions src/amadeus/namespaces/schedule/flights.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* A namespaced client for the
* `/v2/schedule/flights` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.schedule.flights;
* ```
*
* @param {Client} client
*/
class Flights {
constructor(client) {
this.client = client;
}

/**
* Provides real-time flight schedule data including up-to-date departure and arrival times,
* terminal and gate information, flight duration and real-time delay status
*
* @param {Object} params
* @param {Double} params.carrierCode 2 to 3-character IATA carrier code - required
* @param {Double} params.flightNumber 1 to 4-digit number of the flight. e.g. 4537 - required
* @param {Double} params.scheduledDepartureDate scheduled departure date of the flight, local to the departure airport - required
* @return {Promise.<Response,ResponseError>} a Promise
* What's the current status of my flight?
* ```js
* amadeus.schedule.flights.get({
* carrierCode: 'AZ',
* flightNumber: '319',
* scheduledDepartureDate: '2021-03-13'
* });
* ```
*/
get(params = {}) {
return this.client.get('/v2/schedule/flights', params);
}
}

export default Flights;

0 comments on commit 487092d

Please sign in to comment.