Skip to content

Commit f4b2dcc

Browse files
committed
add helper and example
1 parent 2fc502d commit f4b2dcc

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
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: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,28 @@ amadeus.travel.analytics.airTraffic.busiestPeriod.get({
338338
direction: Amadeus.direction.arriving
339339
})
340340

341-
// Trip Parser API
342-
// To submit a new job
343-
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(
344345
JSON.stringify({
345-
'type': 'trip-parser-job',
346-
'content': 'base64String'
347-
})
348-
)
349-
// To check status of the job with ID 'XXX'
350-
amadeus.travel.tripParserJobs('XXX').get()
351-
// To get the results of the job with ID 'XXX'
352-
amadeus.travel.tripParserJobs('XXX').result.get()
346+
'payload': amadeus.travel.tripParser.fromFile(fs.readFileSync('confirmation.eml')),
347+
"metadata": {
348+
"documentType": "html",
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+
}))
353363

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

src/amadeus/namespaces/travel/trip_parser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class TripParser {
3131
post(params = {}) {
3232
return this.client.post('/v3/travel/trip-parser', params);
3333
}
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+
}
3441
}
3542

3643
export default TripParser;

0 commit comments

Comments
 (0)