Skip to content

Commit 6dad246

Browse files
authored
Merge pull request #155 from amadeus4dev/add-Trip-parser-v3-and-airline-routes
add airline routes + trip parser v3
2 parents 2f2bfd7 + 912903c commit 6dad246

File tree

11 files changed

+156
-150
lines changed

11 files changed

+156
-150
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ coverage
44
test.js
55
docs
66
.vscode/
7-
.DS_Store
7+
.DS_Store

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ spec
66
docs
77
test.js
88
coverage
9+
.DS_Store

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ amadeus.airport.directDestinations.get({
177177
departureAirportCode: 'CDG',
178178
})
179179

180+
//Airline Routes
181+
//find all destinations served by a given airline
182+
amadeus.airline.destinations.get({
183+
airlineCode: 'BA',
184+
})
185+
180186
// Flight Inspiration Search
181187
amadeus.shopping.flightDestinations.get({
182188
origin : 'MAD'
@@ -332,18 +338,28 @@ amadeus.travel.analytics.airTraffic.busiestPeriod.get({
332338
direction: Amadeus.direction.arriving
333339
})
334340

335-
// Trip Parser API
336-
// To submit a new job
337-
amadeus.travel.tripParserJobs().post(
341+
// Trip Parser API V3
342+
// parse information from flight, hotel, rail, and rental car confirmation emails
343+
// Parse directly from your confirmation file by using helper `fromFile`
344+
amadeus.travel.tripParser.post(
338345
JSON.stringify({
339-
'type': 'trip-parser-job',
340-
'content': 'base64String'
341-
})
342-
)
343-
// To check status of the job with ID 'XXX'
344-
amadeus.travel.tripParserJobs('XXX').get()
345-
// To get the results of the job with ID 'XXX'
346-
amadeus.travel.tripParserJobs('XXX').result.get()
346+
'payload': amadeus.travel.tripParser.fromFile(fs.readFileSync('confirmation.eml')),
347+
"metadata": {
348+
"documentType": "eml",
349+
"name": "BOOKING_DOCUMENT",
350+
"encoding": "BASE_64"
351+
}
352+
}))
353+
// Alternatively Parse from a string encoded in BASE_64
354+
amadeus.travel.tripParser.post(
355+
JSON.stringify({
356+
'payload': "STRING in BASE_64"
357+
"metadata": {
358+
"documentType": "html",
359+
"name": "BOOKING_DOCUMENT",
360+
"encoding": "BASE_64"
361+
}
362+
}))
347363

348364
// City Search API
349365
// finds cities that match a specific word or string of letters.

spec/amadeus/namespaces.test.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ describe('Namespaces', () => {
4848
expect(amadeus.travel.predictions).toBeDefined();
4949
expect(amadeus.travel.predictions.tripPurpose).toBeDefined();
5050
expect(amadeus.travel.predictions.flightDelay).toBeDefined();
51-
expect(amadeus.travel.tripParserJobs).toBeDefined();
52-
expect(amadeus.travel.tripParserJobs('XXX').result).toBeDefined();
51+
expect(amadeus.travel.tripParser).toBeDefined();
5352

5453
expect(amadeus.shopping).toBeDefined();
5554
expect(amadeus.shopping.flightDates).toBeDefined();
@@ -103,6 +102,8 @@ describe('Namespaces', () => {
103102
expect(amadeus.dutyOfCare).toBeDefined();
104103
expect(amadeus.dutyOfCare.diseases).toBeDefined();
105104
expect(amadeus.dutyOfCare.diseases.covid19AreaReport).toBeDefined();
105+
106+
expect(amadeus.airline.destinations).toBeDefined();
106107
});
107108

108109
it('should define all expected .get methods', () => {
@@ -126,8 +127,6 @@ describe('Namespaces', () => {
126127
expect(amadeus.travel.analytics.airTraffic.busiestPeriod.get).toBeDefined();
127128
expect(amadeus.travel.predictions.tripPurpose.get).toBeDefined();
128129
expect(amadeus.travel.predictions.flightDelay.get).toBeDefined();
129-
expect(amadeus.travel.tripParserJobs('XXX').get).toBeDefined();
130-
expect(amadeus.travel.tripParserJobs('XXX').result.get).toBeDefined();
131130

132131
expect(amadeus.shopping.flightDates.get).toBeDefined();
133132
expect(amadeus.shopping.flightDestinations.get).toBeDefined();
@@ -162,13 +161,15 @@ describe('Namespaces', () => {
162161
expect(amadeus.location.analytics.categoryRatedAreas.get).toBeDefined();
163162

164163
expect(amadeus.dutyOfCare.diseases.covid19AreaReport.get).toBeDefined();
164+
165+
expect(amadeus.airline.destinations.get).toBeDefined();
165166
});
166167

167168
it('should define all expected .post methods', () => {
168169
expect(amadeus.shopping.flightOffers.prediction.post).toBeDefined();
169170
expect(amadeus.booking.flightOrders.post).toBeDefined();
170171
expect(amadeus.shopping.flightOffersSearch.post).toBeDefined();
171-
expect(amadeus.travel.tripParserJobs('XXX').post).toBeDefined();
172+
expect(amadeus.travel.tripParser.post).toBeDefined();
172173
expect(amadeus.shopping.flightOffers.pricing.post).toBeDefined();
173174
expect(amadeus.shopping.seatmaps.post).toBeDefined();
174175
expect(amadeus.booking.hotelBookings.post).toBeDefined();
@@ -318,25 +319,11 @@ describe('Namespaces', () => {
318319
.toHaveBeenCalledWith('/v1/travel/analytics/air-traffic/busiest-period', {});
319320
});
320321

321-
it('.amadeus.travel.tripParserJobs().get', () => {
322-
amadeus.client.get = jest.fn();
323-
amadeus.travel.tripParserJobs('XXX').get();
324-
expect(amadeus.client.get)
325-
.toHaveBeenCalledWith('/v2/travel/trip-parser-jobs/XXX');
326-
});
327-
328-
it('.amadeus.travel.tripParserJobs().result.get', () => {
329-
amadeus.client.get = jest.fn();
330-
amadeus.travel.tripParserJobs('XXX').result.get();
331-
expect(amadeus.client.get)
332-
.toHaveBeenCalledWith('/v2/travel/trip-parser-jobs/XXX/result');
333-
});
334-
335-
it('.amadeus.travel.tripParserJobs().post', () => {
322+
it('.amadeus.travel.tripParser.post', () => {
336323
amadeus.client.post = jest.fn();
337-
amadeus.travel.tripParserJobs().post();
324+
amadeus.travel.tripParser.post();
338325
expect(amadeus.client.post)
339-
.toHaveBeenCalledWith('/v2/travel/trip-parser-jobs', {});
326+
.toHaveBeenCalledWith('/v3/travel/trip-parser', {});
340327
});
341328

342329
it('.amadeus.shopping.flightDates.get', () => {
@@ -556,5 +543,12 @@ describe('Namespaces', () => {
556543
.toHaveBeenCalledWith('/v1/duty-of-care/diseases/covid19-area-report', {});
557544
});
558545

546+
it('.amadeus.airline.destinations.get', () => {
547+
amadeus.client.get = jest.fn();
548+
amadeus.airline.destinations.get();
549+
expect(amadeus.client.get)
550+
.toHaveBeenCalledWith('/v1/airline/destinations', {});
551+
});
552+
559553
});
560554
});

src/amadeus.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Schedule from './amadeus/namespaces/schedule';
1313
import Analytics from './amadeus/namespaces/analytics';
1414
import Location from './amadeus/namespaces/location';
1515
import DutyOfCare from './amadeus/namespaces/duty_of_care';
16+
import Airline from './amadeus/namespaces/airline';
1617

1718

1819
/**
@@ -78,6 +79,7 @@ class Amadeus {
7879
this.analytics = new Analytics(this.client);
7980
this.location = new Location(this.client);
8081
this.dutyOfCare = new DutyOfCare(this.client);
82+
this.airline = new Airline(this.client);
8183
}
8284

8385
/**

src/amadeus/namespaces/airline.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Destinations from './airline/destinations';
2+
3+
/**
4+
* A namespaced client for the
5+
* `/v1/airline` endpoints
6+
*
7+
* Access via the {@link Amadeus} object
8+
*
9+
* ```js
10+
* let amadeus = new Amadeus();
11+
* amadeus.airline;
12+
* ```
13+
*
14+
* @param {Client} client
15+
* @property {predictions} predictions
16+
*/
17+
class Airline {
18+
constructor(client) {
19+
this.client = client;
20+
this.destinations = new Destinations(client);
21+
}
22+
}
23+
24+
export default Airline;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* A namespaced client for the
3+
* `/v1/airline/destinations` endpoints
4+
*
5+
* Access via the {@link Amadeus} object
6+
*
7+
* ```js
8+
* let amadeus = new Amadeus();
9+
* amadeus.airline.destinations;
10+
* ```
11+
*
12+
* @param {Client} client
13+
*/
14+
class Destinations {
15+
constructor(client) {
16+
this.client = client;
17+
}
18+
19+
/**
20+
* find all destinations served by a given airline
21+
*
22+
* @param {Object} params
23+
* @param {string} params.airlineCode airline IATA code, e.g. BA for British airways
24+
* @return {Promise.<Response,ResponseError>} a Promise
25+
*
26+
* What destinations are served by this airline?
27+
* ```js
28+
* amadeus.airline.destinations.get({
29+
* airlineCode: 'BA',
30+
* })
31+
* ```
32+
*/
33+
get(params = {}) {
34+
return this.client.get('/v1/airline/destinations', params);
35+
}
36+
}
37+
38+
export default Destinations;

src/amadeus/namespaces/travel.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Analytics from './travel/analytics';
22
import Predictions from './travel/predictions';
3-
import TripParserJobs from './travel/trip_parser_jobs';
3+
import TripParser from './travel/trip_parser';
44

55
/**
66
* A namespaced client for the
7-
* `/v1/travel` & `/v2/travel` endpoints
7+
* `/v1/travel` & `/v2/travel` & `/v3/travel` endpoints
88
*
99
* Access via the {@link Amadeus} object
1010
*
@@ -16,18 +16,15 @@ import TripParserJobs from './travel/trip_parser_jobs';
1616
* @param {Client} client
1717
* @property {Analytics} analytics
1818
* @property {Predictions} predictions
19-
* @property {TripParserJobs} tripParserJobs
19+
* @property {TripParser} tripParser
2020
* @protected
2121
*/
2222
class Travel {
2323
constructor(client) {
2424
this.client = client;
2525
this.analytics = new Analytics(client);
2626
this.predictions = new Predictions(client);
27-
}
28-
29-
tripParserJobs (jobId) {
30-
return new TripParserJobs(this.client, jobId);
27+
this.tripParser = new TripParser(client);
3128
}
3229
}
3330

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* A namespaced client for the
3+
* `/v3/travel/trip-parser` endpoints
4+
*
5+
* Access via the {@link Amadeus} object
6+
*
7+
* ```js
8+
* let amadeus = new Amadeus();
9+
* amadeus.tripParser;
10+
* ```
11+
*
12+
* @param {Client} client
13+
*/
14+
class TripParser {
15+
constructor(client) {
16+
this.client = client;
17+
}
18+
19+
/**
20+
* parse information from flight, hotel, rail, and rental car confirmation emails
21+
*
22+
* @param {Object} params
23+
* @return {Promise.<Response,ResponseError>} a Promise
24+
*
25+
* "How can I show travelers their full itinerary in one place?"
26+
*
27+
* ```js
28+
* amadeus.tripParser.post(body);
29+
* ```
30+
*/
31+
post(params = {}) {
32+
return this.client.post('/v3/travel/trip-parser', params);
33+
}
34+
/**
35+
* Helper method to convert file contents in UTF-8 encoded string
36+
* into Base64 encoded string
37+
*/
38+
fromFile(fileContentsInUTF8Format) {
39+
return (new Buffer.from(fileContentsInUTF8Format)).toString('base64');
40+
}
41+
}
42+
43+
export default TripParser;

src/amadeus/namespaces/travel/trip_parser_jobs.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)