Skip to content

Commit ebf5bfa

Browse files
authored
Add support for Travel Recommendations API (#82)
1 parent 328a5c0 commit ebf5bfa

File tree

5 files changed

+102
-42
lines changed

5 files changed

+102
-42
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We are trying to keep 100% coverage, so keep an eye on the `coverage` folder for
1616

1717
### Building the source
1818

19-
To build the source, run `npm run build` or `npm run build watch` to keep watching the source for changes and build accordingly.
19+
To build the source, run `npm run build` or `npm run build:watch` to keep watching the source for changes and build accordingly.
2020

2121
### Using a library locally
2222

README.md

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ amadeus.client.post('/v1/shopping/flight-offers/pricing', JSON.stringify({ data
109109

110110
## Promises
111111

112-
Every API call returns a `Promise` that either resolves or rejects.
112+
Every API call returns a `Promise` that either resolves or rejects.
113113

114114
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 contains a `data` key, that will be made available in `data` attribute.
115115

@@ -185,10 +185,10 @@ amadeus.shopping.flightDates.get({
185185

186186
// Flight Offers Search
187187
amadeus.shopping.flightOffersSearch.get({
188-
originLocationCode: 'SYD',
189-
destinationLocationCode: 'BKK',
190-
departureDate: '2020-08-01',
191-
adults: '2'
188+
originLocationCode: 'SYD',
189+
destinationLocationCode: 'BKK',
190+
departureDate: '2020-08-01',
191+
adults: '2'
192192
})
193193

194194
// Flight Choice Prediction
@@ -255,10 +255,10 @@ amadeus.shopping.flightOffersSearch.get({
255255
// To retrieve the seat map of each flight included
256256
// in flight offers for MAD-NYC flight on 2020-08-01
257257
amadeus.shopping.flightOffersSearch.get({
258-
originLocationCode: 'SYD',
259-
destinationLocationCode: 'BKK',
260-
departureDate: '2020-08-01',
261-
adults: '1'
258+
originLocationCode: 'SYD',
259+
destinationLocationCode: 'BKK',
260+
departureDate: '2020-08-01',
261+
adults: '1'
262262
}).then(function(response){
263263
return amadeus.shopping.seatmaps.post(
264264
JSON.stringify({
@@ -303,21 +303,21 @@ amadeus.referenceData.locations.airports.get({
303303

304304
// Flight Most Booked Destinations
305305
amadeus.travel.analytics.airTraffic.booked.get({
306-
originCityCode : 'MAD',
307-
period : '2017-08'
308-
})
306+
originCityCode : 'MAD',
307+
period : '2017-08'
308+
}
309309

310310
// Flight Most Traveled Destinations
311311
amadeus.travel.analytics.airTraffic.traveled.get({
312-
originCityCode : 'MAD',
313-
period : '2017-01'
312+
originCityCode : 'MAD',
313+
period : '2017-01'
314314
})
315315

316316
// Flight Busiest Traveling Period
317317
amadeus.travel.analytics.airTraffic.busiestPeriod.get({
318-
cityCode: 'MAD',
319-
period: '2017',
320-
direction: Amadeus.direction.arriving
318+
cityCode: 'MAD',
319+
period: '2017',
320+
direction: Amadeus.direction.arriving
321321
})
322322

323323
// Trip Parser API
@@ -366,16 +366,16 @@ amadeus.booking.hotelBookings.post(
366366
// Points of Interest
367367
// What are the popular places in Barcelona (based a geo location and a radius)
368368
amadeus.referenceData.locations.pointsOfInterest.get({
369-
latitude : 41.397158,
370-
longitude : 2.160873
369+
latitude : 41.397158,
370+
longitude : 2.160873
371371
})
372372

373373
// What are the popular places in Barcelona? (based on a square)
374374
amadeus.referenceData.locations.pointsOfInterest.bySquare.get({
375-
north: 41.397158,
376-
west: 2.160873,
377-
south: 41.394582,
378-
east: 2.177181
375+
north: 41.397158,
376+
west: 2.160873,
377+
south: 41.394582,
378+
east: 2.177181
379379
})
380380

381381
// Points of Interest
@@ -385,16 +385,16 @@ amadeus.referenceData.locations.pointOfInterest('9CB40CB5D0').get()
385385
// Hotel Ratings
386386
// Get Sentiment Analysis of reviews about Holiday Inn Paris Notre Dame.
387387
amadeus.eReputation.hotelSentiments.get({
388-
hotelIds: 'XKPARC12'
388+
hotelIds: 'XKPARC12'
389389
})
390390

391391
// Trip Purpose Prediction
392392
// Forecast traveler purpose, Business or Leisure, together with the probability in the context of search & shopping.
393393
amadeus.travel.predictions.tripPurpose.get({
394-
originLocationCode: 'NYC',
395-
destinationLocationCode: 'MAD',
396-
departureDate: '2020-08-01',
397-
returnDate: '2020-08-12'
394+
originLocationCode: 'NYC',
395+
destinationLocationCode: 'MAD',
396+
departureDate: '2020-08-01',
397+
returnDate: '2020-08-12'
398398
})
399399

400400
// AI-Generated Photos
@@ -407,25 +407,32 @@ amadeus.media.files.generatedPhotos.get({
407407
// This machine learning API is based on a prediction model that takes the input of the user - time, carrier, airport and aircraft information;
408408
// and predict the segment where the flight is likely to lay.
409409
amadeus.travel.predictions.flightDelay.get({
410-
originLocationCode: 'BRU',
411-
destinationLocationCode: 'FRA',
412-
departureDate: '2020-01-14',
413-
departureTime: '11:05:00',
414-
arrivalDate: '2020-01-14',
415-
arrivalTime: '12:10:00',
416-
aircraftCode: '32A',
417-
carrierCode: 'LH',
418-
flightNumber: '1009',
419-
duration: 'PT1H05M'
410+
originLocationCode: 'BRU',
411+
destinationLocationCode: 'FRA',
412+
departureDate: '2020-01-14',
413+
departureTime: '11:05:00',
414+
arrivalDate: '2020-01-14',
415+
arrivalTime: '12:10:00',
416+
aircraftCode: '32A',
417+
carrierCode: 'LH',
418+
flightNumber: '1009',
419+
duration: 'PT1H05M'
420420
})
421421

422422
// Airport On-time Performance
423423
// Get the percentage of on-time flight departures from JFK
424424
amadeus.airport.predictions.onTime.get({
425-
airportCode: 'JFK',
426-
date: '2020-08-01'
425+
airportCode: 'JFK',
426+
date: '2020-08-01'
427+
})
428+
429+
// Travel Recommendations
430+
amadeus.referenceData.recommendedLocations.get({
431+
cityCodes: 'PAR',
432+
travelerCountryCode: 'FR'
427433
})
428434

435+
// Safe Place
429436
// How safe is Barcelona? (based a geo location and a radius)
430437
amadeus.safety.safetyRatedLocations.get({
431438
latitude: 41.397158,

spec/amadeus/namespaces.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Namespaces', () => {
2626
expect(amadeus.referenceData.locations.pointsOfInterest).toBeDefined();
2727
expect(amadeus.referenceData.locations.pointsOfInterest.bySquare).toBeDefined();
2828
expect(amadeus.referenceData.airlines).toBeDefined();
29+
expect(amadeus.referenceData.recommendedLocations).toBeDefined();
2930

3031
expect(amadeus.travel).toBeDefined();
3132
expect(amadeus.travel.analytics).toBeDefined();
@@ -84,6 +85,7 @@ describe('Namespaces', () => {
8485
expect(amadeus.referenceData.locations.pointsOfInterest.get).toBeDefined();
8586
expect(amadeus.referenceData.locations.pointsOfInterest.bySquare.get).toBeDefined();
8687
expect(amadeus.referenceData.airlines.get).toBeDefined();
88+
expect(amadeus.referenceData.recommendedLocations.get).toBeDefined();
8789

8890
expect(amadeus.travel.analytics.airTraffic.traveled.get).toBeDefined();
8991
expect(amadeus.travel.analytics.airTraffic.booked.get).toBeDefined();
@@ -156,6 +158,13 @@ describe('Namespaces', () => {
156158
.toHaveBeenCalledWith('/v1/reference-data/locations/airports', {});
157159
});
158160

161+
it('.amadeus.referenceData.recommendedLocations.get', () => {
162+
amadeus.client.get = jest.fn();
163+
amadeus.referenceData.recommendedLocations.get();
164+
expect(amadeus.client.get)
165+
.toHaveBeenCalledWith('/v1/reference-data/recommended-locations', {});
166+
});
167+
159168
it('.amadeus.referenceData.locations.pointsOfInterest.get', () => {
160169
amadeus.client.get = jest.fn();
161170
amadeus.referenceData.locations.pointsOfInterest.get();

src/amadeus/namespaces/reference_data.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Urls from './reference_data/urls';
22
import Locations from './reference_data/locations';
33
import Location from './reference_data/location';
4-
import Airlines from './reference_data/airlines';
4+
import Airlines from './reference_data/airlines';
5+
import RecommendedLocations from './reference_data/recommended_locations';
56

67
/**
78
* A namespaced client for the
@@ -24,6 +25,7 @@ class ReferenceData {
2425
this.urls = new Urls(client);
2526
this.locations = new Locations(client);
2627
this.airlines = new Airlines(client);
28+
this.recommendedLocations = new RecommendedLocations(client);
2729
}
2830

2931
/**
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* A namespaced client for the
3+
* `/v1/reference-data/recommended-locations` endpoints
4+
*
5+
* Access via the {@link Amadeus} object
6+
*
7+
* ```js
8+
* let amadeus = new Amadeus();
9+
* amadeus.referenceData.recommendedLocations;
10+
* ```
11+
*
12+
* @param {Client} client
13+
*/
14+
class RecommendedLocations {
15+
constructor(client) {
16+
this.client = client;
17+
}
18+
19+
/**
20+
* Returns the recommended locations (destinations).
21+
*
22+
* @param {Object} params
23+
* @param {string} params.cityCodes Code of the city following IATA standard.
24+
* @param {string} params.travelerCountryCode Origin country of the traveler following IATA standard.
25+
* @param {string} params.destinationCountryCodes Country codes follow IATA standard.
26+
* @return {Promise.<Response,ResponseError>} a Promise
27+
*
28+
* Get recommended destinations from a given origin
29+
*
30+
* ```js
31+
* amadeus.referenceData.recommendedDestinations.get({
32+
* cityCodes: 'PAR',
33+
* travelerCountryCode: 'FR'
34+
* });
35+
* ```
36+
*/
37+
get(params = {}) {
38+
return this.client.get('/v1/reference-data/recommended-locations', params);
39+
}
40+
}
41+
42+
export default RecommendedLocations;

0 commit comments

Comments
 (0)