From f37b6fb18b19f6e5e411fb606639420cb63d9ad8 Mon Sep 17 00:00:00 2001 From: darseen Date: Tue, 13 Aug 2024 22:57:31 +0300 Subject: [PATCH 1/6] added auto json.stringify & modified tests accordingly --- spec/amadeus/namespaces.test.js | 20 +++++++++---------- .../namespaces/booking/flight_orders.js | 2 +- .../namespaces/ordering/transfer_orders.js | 4 ++-- .../transfer_orders/transfers/cancellation.js | 4 ++-- .../availability/flight_availabilities.js | 2 +- .../shopping/flight_offers/pricing.js | 2 +- .../shopping/flight_offers/upselling.js | 2 +- .../shopping/flight_offers_search.js | 6 +++--- src/amadeus/namespaces/shopping/seatmaps.js | 2 +- .../namespaces/shopping/transfer_offers.js | 2 +- src/amadeus/namespaces/travel/trip_parser.js | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/spec/amadeus/namespaces.test.js b/spec/amadeus/namespaces.test.js index b8d794c..cd7741d 100644 --- a/spec/amadeus/namespaces.test.js +++ b/spec/amadeus/namespaces.test.js @@ -310,7 +310,7 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.travel.tripParser.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v3/travel/trip-parser', {}); + .toHaveBeenCalledWith('/v3/travel/trip-parser', JSON.stringify({})); }); it('.amadeus.travel.tripParser.fromFile', () => { @@ -344,14 +344,14 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.booking.flightOrders.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/booking/flight-orders', {}); + .toHaveBeenCalledWith('/v1/booking/flight-orders', JSON.stringify({})); }); it('.amadeus.shopping.flightOffers.pricing.post', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffers.pricing.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/flight-offers/pricing', {}); + .toHaveBeenCalledWith('/v1/shopping/flight-offers/pricing', JSON.stringify({})); }); it('.amadeus.shopping.flightOffersSearch.get', () => { @@ -365,7 +365,7 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffersSearch.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v2/shopping/flight-offers', {}); + .toHaveBeenCalledWith('/v2/shopping/flight-offers', JSON.stringify({})); }); it('.amadeus.shopping.seatmaps.get', () => { @@ -379,7 +379,7 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.seatmaps.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/seatmaps', {}); + .toHaveBeenCalledWith('/v1/shopping/seatmaps', JSON.stringify({})); }); it('.amadeus.shopping.hotelOfferSearch().get', () => { @@ -494,14 +494,14 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.availability.flightAvailabilities.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/availability/flight-availabilities', {}); + .toHaveBeenCalledWith('/v1/shopping/availability/flight-availabilities', JSON.stringify({})); }); it('.amadeus.shopping.flight_offers.upselling.post', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffers.upselling.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/flight-offers/upselling', {}); + .toHaveBeenCalledWith('/v1/shopping/flight-offers/upselling', JSON.stringify({})); }); it('.amadeus.airline.destinations.get', () => { @@ -515,21 +515,21 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.transferOffers.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/transfer-offers', {}); + .toHaveBeenCalledWith('/v1/shopping/transfer-offers', JSON.stringify({})); }); it('.amadeus.ordering.transferOrders.post', () => { amadeus.client.post = jest.fn(); amadeus.ordering.transferOrders.post({}, '1234123123'); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/ordering/transfer-orders?offerId=1234123123', {}); + .toHaveBeenCalledWith('/v1/ordering/transfer-orders?offerId=1234123123', JSON.stringify({})); }); it('.amadeus.ordering.transferOrders().transfers.cancellation.post', () => { amadeus.client.post = jest.fn(); amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, 12345); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/ordering/transfer-orders/XXX/transfers/cancellation?confirmNbr=12345', {}); + .toHaveBeenCalledWith('/v1/ordering/transfer-orders/XXX/transfers/cancellation?confirmNbr=12345', JSON.stringify({})); }); }); diff --git a/src/amadeus/namespaces/booking/flight_orders.js b/src/amadeus/namespaces/booking/flight_orders.js index 886883c..b13d01e 100644 --- a/src/amadeus/namespaces/booking/flight_orders.js +++ b/src/amadeus/namespaces/booking/flight_orders.js @@ -33,7 +33,7 @@ class FlightOrders { * ``` */ post(params = {}) { - return this.client.post('/v1/booking/flight-orders', params); + return this.client.post('/v1/booking/flight-orders', JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/ordering/transfer_orders.js b/src/amadeus/namespaces/ordering/transfer_orders.js index ff4871f..9d73c1f 100644 --- a/src/amadeus/namespaces/ordering/transfer_orders.js +++ b/src/amadeus/namespaces/ordering/transfer_orders.js @@ -25,11 +25,11 @@ class TransferOrders { * To book the transfer-offer(s) suggested by transferOffers and create a transfer-order * * ```js - * amadeus.ordering.transferOrders.post(body, '2094123123');; + * amadeus.ordering.transferOrders.post(body, '2094123123'); * ``` */ post(body, offerId) { - return this.client.post(`/v1/ordering/transfer-orders?offerId=${offerId}`, body); + return this.client.post(`/v1/ordering/transfer-orders?offerId=${offerId}`, JSON.stringify(body)); } } diff --git a/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js b/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js index 64a1952..73776e6 100644 --- a/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js +++ b/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js @@ -24,12 +24,12 @@ class Cancellation { * To cancel a transfer order with ID 'XXX' and confirmation number '12345' * * ```js - * amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), '12345');; + * amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, '12345');; * ``` */ post(body, confirmNbr) { return this.client.post( - `/v1/ordering/transfer-orders/${this.orderId}/transfers/cancellation?confirmNbr=${confirmNbr}`, body); + `/v1/ordering/transfer-orders/${this.orderId}/transfers/cancellation?confirmNbr=${confirmNbr}`, JSON.stringify(body)); } } diff --git a/src/amadeus/namespaces/shopping/availability/flight_availabilities.js b/src/amadeus/namespaces/shopping/availability/flight_availabilities.js index 8b41300..59e6da5 100644 --- a/src/amadeus/namespaces/shopping/availability/flight_availabilities.js +++ b/src/amadeus/namespaces/shopping/availability/flight_availabilities.js @@ -27,7 +27,7 @@ class FlightAvailabilities { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/availability/flight-availabilities', params); + return this.client.post('/v1/shopping/availability/flight-availabilities', JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers/pricing.js b/src/amadeus/namespaces/shopping/flight_offers/pricing.js index 3d8db6e..68b47bc 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/pricing.js +++ b/src/amadeus/namespaces/shopping/flight_offers/pricing.js @@ -48,7 +48,7 @@ class Pricing { url += '?' + queryString; } - return this.client.post(url, params); + return this.client.post(url, JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers/upselling.js b/src/amadeus/namespaces/shopping/flight_offers/upselling.js index 258816b..393f993 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/upselling.js +++ b/src/amadeus/namespaces/shopping/flight_offers/upselling.js @@ -27,7 +27,7 @@ class Upselling { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/flight-offers/upselling', params); + return this.client.post('/v1/shopping/flight-offers/upselling', JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers_search.js b/src/amadeus/namespaces/shopping/flight_offers_search.js index d2198d6..0aaf2ef 100644 --- a/src/amadeus/namespaces/shopping/flight_offers_search.js +++ b/src/amadeus/namespaces/shopping/flight_offers_search.js @@ -52,7 +52,7 @@ class FlightOffersSearch { * To do a customized search with given options. * * ```js - * amadeus.shopping.flightOffersSearch.post (JSON.stringify({ + * amadeus.shopping.flightOffersSearch.post({ "currencyCode": "USD", "originDestinations": [ { @@ -114,11 +114,11 @@ class FlightOffersSearch { } } } - })) + }); * ``` */ post(params = {}) { - return this.client.post('/v2/shopping/flight-offers', params); + return this.client.post('/v2/shopping/flight-offers', JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/shopping/seatmaps.js b/src/amadeus/namespaces/shopping/seatmaps.js index 749d180..7b8f61a 100644 --- a/src/amadeus/namespaces/shopping/seatmaps.js +++ b/src/amadeus/namespaces/shopping/seatmaps.js @@ -59,7 +59,7 @@ class Seatmaps { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/seatmaps', params); + return this.client.post('/v1/shopping/seatmaps', JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/shopping/transfer_offers.js b/src/amadeus/namespaces/shopping/transfer_offers.js index 951a462..f3d3c55 100644 --- a/src/amadeus/namespaces/shopping/transfer_offers.js +++ b/src/amadeus/namespaces/shopping/transfer_offers.js @@ -31,7 +31,7 @@ class TransferOffers { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/transfer-offers', params); + return this.client.post('/v1/shopping/transfer-offers', JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/travel/trip_parser.js b/src/amadeus/namespaces/travel/trip_parser.js index 382a8a1..660cd5b 100644 --- a/src/amadeus/namespaces/travel/trip_parser.js +++ b/src/amadeus/namespaces/travel/trip_parser.js @@ -29,7 +29,7 @@ class TripParser { * ``` */ post(params = {}) { - return this.client.post('/v3/travel/trip-parser', params); + return this.client.post('/v3/travel/trip-parser', JSON.stringify(params)); } /** * Helper method to convert file contents in UTF-8 encoded string From 2d636806ba5042dc6a8a38c36fc3843b2c87044d Mon Sep 17 00:00:00 2001 From: darseen Date: Sat, 21 Sep 2024 17:45:02 +0300 Subject: [PATCH 2/6] added JSON.stringify to hotel booking & flight offers prediction --- src/amadeus/namespaces/booking/hotel_bookings.js | 6 +++--- .../shopping/flight_offers/flight_choice_prediction.js | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/amadeus/namespaces/booking/hotel_bookings.js b/src/amadeus/namespaces/booking/hotel_bookings.js index 7a46a15..0ebac11 100644 --- a/src/amadeus/namespaces/booking/hotel_bookings.js +++ b/src/amadeus/namespaces/booking/hotel_bookings.js @@ -26,18 +26,18 @@ class HotelBookings { * * ```js * amadeus.booking.hotelBookings.post( - * JSON.stringify({ + * { * 'data': { * 'offerId': 'XXXX', * 'guests': [], * 'payments': [], * 'rooms': [] - * }}) + * }} * ) * ``` */ post(params = {}) { - return this.client.post('/v1/booking/hotel-bookings', params); + return this.client.post('/v1/booking/hotel-bookings', JSON.stringify(params)); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js b/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js index 68b1a1a..b5f0e70 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js +++ b/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js @@ -31,9 +31,7 @@ class FlightChoicePrediction { * departureDate: '2020-08-01', * adults: '2' * }).then(function(response){ - * return amadeus.shopping.flightOffers.prediction.post( - * JSON.stringify(response) - * ); + * return amadeus.shopping.flightOffers.prediction.post(response); * }).then(function(response){ * console.log(response.data); * }).catch(function(responseError){ @@ -42,7 +40,7 @@ class FlightChoicePrediction { * ``` */ post(params = {}) { - return this.client.post('/v2/shopping/flight-offers/prediction', params); + return this.client.post('/v2/shopping/flight-offers/prediction', JSON.stringify(params)); } } From a9051b757c81746786159de825b5009b28615352 Mon Sep 17 00:00:00 2001 From: darseen Date: Sat, 21 Sep 2024 17:57:18 +0300 Subject: [PATCH 3/6] added JSON.stringify to hotel orders --- src/amadeus/namespaces/booking/hotel_orders.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/amadeus/namespaces/booking/hotel_orders.js b/src/amadeus/namespaces/booking/hotel_orders.js index 8bc1ff5..64e0c65 100644 --- a/src/amadeus/namespaces/booking/hotel_orders.js +++ b/src/amadeus/namespaces/booking/hotel_orders.js @@ -26,20 +26,20 @@ class HotelOrders { * * ```js * amadeus.booking.hotelOrders.post( - * JSON.stringfy({ + * { * 'data': { * 'type': 'hotel-order', * 'guests': [], * 'travelAgent': {}, * 'roomAssociations': [], * 'payment': {} - * }}) - *) + * } + * }) * ``` + */ post(params = {}) { - - return this.client.post('/v2/booking/hotel-orders', params); + return this.client.post('/v2/booking/hotel-orders', JSON.stringify(params)); } } From 34663457abe3f078f090084e55e9112b4056feed Mon Sep 17 00:00:00 2001 From: darseen Date: Sat, 21 Sep 2024 18:05:56 +0300 Subject: [PATCH 4/6] removed JSON.stringify from examples --- README.md | 50 ++++++++++----------- src/amadeus/namespaces/shopping/seatmaps.js | 6 +-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c3102e7..9d2f081 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ amadeus.shopping.flightOffersSearch.get({ // Flight Offers Search POST // A full example can be found at https://github.com/amadeus4dev/amadeus-code-examples -amadeus.shopping.flightOffersSearch.post(JSON.stringify(body)) +amadeus.shopping.flightOffersSearch.post(body) // Flight Offers Price amadeus.shopping.flightOffersSearch.get({ @@ -214,12 +214,12 @@ amadeus.shopping.flightOffersSearch.get({ adults: '1' }).then(function(response){ return amadeus.shopping.flightOffers.pricing.post( - JSON.stringify({ + { 'data': { 'type': 'flight-offers-pricing', 'flightOffers': [response.data[0]] } - }) + } ) }).then(function(response){ console.log(response.data); @@ -229,19 +229,19 @@ amadeus.shopping.flightOffersSearch.get({ // Flight Offers Price with additional parameters // for example: check additional baggage options -amadeus.shopping.flightOffers.pricing.post(JSON.stringify(body),{include: 'bags'}) +amadeus.shopping.flightOffers.pricing.post(body ,{include: 'bags'}); // Flight Create Orders // To book the flight-offer(s) returned by the Flight Offers Price // and create a flight-order with travelers' information. // A full example can be found at https://git.io/JtnYo amadeus.booking.flightOrders.post( - JSON.stringify({ + { 'type': 'flight-order', 'flightOffers': [priced-offers], 'travelers': [] - }) -) + } +); // Retrieve flight order with ID 'XXX'. This ID comes from the // Flight Create Orders API, which is a temporary ID in test environment. @@ -261,9 +261,9 @@ amadeus.shopping.flightOffersSearch.get({ adults: '1' }).then(function(response){ return amadeus.shopping.seatmaps.post( - JSON.stringify({ + { 'data': [response.data[0]] - }) + } ); }).then(function(response){ console.log(response.data); @@ -276,10 +276,10 @@ amadeus.shopping.seatmaps.get({ }); // Flight Availabilities Search -amadeus.shopping.availability.flightAvailabilities.post(JSON.stringify((body)); +amadeus.shopping.availability.flightAvailabilities.post(body); // Branded Fares Upsell -amadeus.shopping.flightOffers.upselling.post(JSON.stringify(body)); +amadeus.shopping.flightOffers.upselling.post(body); // Flight Choice Prediction amadeus.shopping.flightOffersSearch.get({ @@ -288,9 +288,7 @@ amadeus.shopping.flightOffersSearch.get({ departureDate: '2022-11-01', adults: '2' }).then(function(response){ - return amadeus.shopping.flightOffers.prediction.post( - JSON.stringify(response) - ); + return amadeus.shopping.flightOffers.prediction.post(response); }).then(function(response){ console.log(response.data); }).catch(function(responseError){ @@ -346,24 +344,24 @@ amadeus.travel.analytics.airTraffic.busiestPeriod.get({ // parse information from flight, hotel, rail, and rental car confirmation emails // Parse directly from your confirmation file by using helper `fromFile` amadeus.travel.tripParser.post( - JSON.stringify({ + { 'payload': amadeus.travel.tripParser.fromFile(fs.readFileSync('confirmation.eml')), "metadata": { "documentType": "eml", "name": "BOOKING_DOCUMENT", "encoding": "BASE_64" } -})) +}) // Alternatively Parse from a string encoded in BASE_64 amadeus.travel.tripParser.post( - JSON.stringify({ + { 'payload': "STRING in BASE_64" "metadata": { "documentType": "html", "name": "BOOKING_DOCUMENT", "encoding": "BASE_64" } -})) +}) // City Search API // finds cities that match a specific word or string of letters. @@ -407,26 +405,28 @@ amadeus.shopping.hotelOfferSearch('XXX').get() // Hotel Booking API v2 amadeus.booking.hotelOrders.post( - JSON.stringfy({ + { 'data': { 'type': 'hotel-order', 'guests': [], 'travelAgent': {}, 'roomAssociations': [], 'payment': {} - }}) + } + } ) // Hotel Booking API v1 amadeus.booking.hotelBookings.post( - JSON.stringify({ + { 'data': { 'offerId': 'XXXX', 'guests': [], 'payments': [], 'rooms': [] - }}) + } + } ) // On-Demand Flight Status @@ -533,13 +533,13 @@ amadeus.analytics.itineraryPriceMetrics.get({ //Cars & Transfers APIs // Transfer Search API: Search Transfer -amadeus.shopping.transferOffers.post(JSON.stringify(body)); +amadeus.shopping.transferOffers.post(body); // Transfer Book API: Book a transfer based on the offer id -amadeus.ordering.transferOrders.post(JSON.stringify(body),offerId='2094123123'); +amadeus.ordering.transferOrders.post(body, offerId='2094123123'); // Transfer Management API: Cancel a transfer based on the order id & confirmation number -amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), confirmNbr='12345'); +amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, confirmNbr='12345'); ``` diff --git a/src/amadeus/namespaces/shopping/seatmaps.js b/src/amadeus/namespaces/shopping/seatmaps.js index 7b8f61a..a176c8f 100644 --- a/src/amadeus/namespaces/shopping/seatmaps.js +++ b/src/amadeus/namespaces/shopping/seatmaps.js @@ -51,9 +51,9 @@ class Seatmaps { * departureDate: '2020-08-01' * }).then(function(response){ * return amadeus.shopping.flightOffers.seatmaps.post( - * JSON.stringify({ - * 'data': response.data - * }) + * { + * data: response.data + * } * ); * }); * ``` From 18b604a5dde759dd91a027ca62302bab71c5b49d Mon Sep 17 00:00:00 2001 From: darseen Date: Sat, 21 Sep 2024 18:13:04 +0300 Subject: [PATCH 5/6] updated tests --- spec/amadeus/namespaces.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/amadeus/namespaces.test.js b/spec/amadeus/namespaces.test.js index cd7741d..00b178c 100644 --- a/spec/amadeus/namespaces.test.js +++ b/spec/amadeus/namespaces.test.js @@ -337,7 +337,7 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffers.prediction.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v2/shopping/flight-offers/prediction', {}); + .toHaveBeenCalledWith('/v2/shopping/flight-offers/prediction', JSON.stringify({})); }); it('.amadeus.booking.flightOrders.post', () => { @@ -445,14 +445,14 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.booking.hotelBookings.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/booking/hotel-bookings', {}); + .toHaveBeenCalledWith('/v1/booking/hotel-bookings', JSON.stringify({})); }); it('.amadeus.booking.hotelOrders.post', () => { amadeus.client.post = jest.fn(); amadeus.booking.hotelOrders.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v2/booking/hotel-orders', {}); + .toHaveBeenCalledWith('/v2/booking/hotel-orders', JSON.stringify({})); }); it('.amadeus.eReputation.hotelSentiments.get', () => { From 7b2d050b0661bfa311fc98ecadc83d05ae6e212b Mon Sep 17 00:00:00 2001 From: darseen Date: Mon, 7 Oct 2024 23:22:17 +0300 Subject: [PATCH 6/6] stringified params while maintaining backwards compatibility --- README.md | 16 ++++++------- spec/amadeus/client.test.js | 4 ++-- spec/amadeus/namespaces.test.js | 24 +++++++++---------- src/amadeus/client.js | 3 ++- .../namespaces/booking/flight_orders.js | 2 +- .../namespaces/booking/hotel_bookings.js | 2 +- .../namespaces/booking/hotel_orders.js | 2 +- .../namespaces/ordering/transfer_orders.js | 2 +- .../transfer_orders/transfers/cancellation.js | 4 ++-- .../availability/flight_availabilities.js | 2 +- .../flight_offers/flight_choice_prediction.js | 2 +- .../shopping/flight_offers/pricing.js | 2 +- .../shopping/flight_offers/upselling.js | 2 +- .../shopping/flight_offers_search.js | 2 +- src/amadeus/namespaces/shopping/seatmaps.js | 2 +- .../namespaces/shopping/transfer_offers.js | 2 +- 16 files changed, 37 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 8caddc7..bdcc39f 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ npm install amadeus --save To make your first API call, you will need to [register](https://developers.amadeus.com/register) for an Amadeus Developer Account and [set up your first application](https://developers.amadeus.com/my-apps). ```js -var Amadeus = require('amadeus'); +const Amadeus = require('amadeus'); -var amadeus = new Amadeus({ +const amadeus = new Amadeus({ clientId: 'REPLACE_BY_YOUR_API_KEY', clientSecret: 'REPLACE_BY_YOUR_API_SECRET' }); @@ -50,7 +50,7 @@ The client can be initialized directly. ```js // Initialize using parameters -var amadeus = new Amadeus({ +const amadeus = new Amadeus({ clientId: 'REPLACE_BY_YOUR_API_KEY', clientSecret: 'REPLACE_BY_YOUR_API_SECRET' }); @@ -59,7 +59,7 @@ var amadeus = new Amadeus({ Alternatively, it can be initialized without any parameters if the environment variables `AMADEUS_CLIENT_ID` and `AMADEUS_CLIENT_SECRET` are present. ```js -var amadeus = new Amadeus(); +const amadeus = new Amadeus(); ``` Your credentials can be found on the [Amadeus dashboard](https://developers.amadeus.com/my-apps). @@ -67,7 +67,7 @@ Your credentials can be found on the [Amadeus dashboard](https://developers.amad By default, the SDK environment is set to `test` environment. To switch to a `production` (pay-as-you-go) environment, please switch the hostname as follows: ```js -var amadeus = new Amadeus({ +const amadeus = new Amadeus({ hostname: 'production' }); ``` @@ -104,7 +104,7 @@ amadeus.client.get('/v2/reference-data/urls/checkin-links', { airlineCode: 'BA' Or, with a `POST` using `.client.post` method: ```js -amadeus.client.post('/v1/shopping/flight-offers/pricing', JSON.stringify({ data })); +amadeus.client.post('/v1/shopping/flight-offers/pricing', { data }); ``` ## Promises @@ -152,7 +152,7 @@ If a page is not available, the response will resolve to `null`. The SDK makes it easy to add your own logger that is compatible with the default `console`. ```js -var amadeus = new Amadeus({ +const amadeus = new Amadeus({ clientId: 'REPLACE_BY_YOUR_API_KEY', clientSecret: 'REPLACE_BY_YOUR_API_SECRET', logger: new MyConsole() @@ -162,7 +162,7 @@ var amadeus = new Amadeus({ Additionally, to enable more verbose logging, you can set the appropriate level on your own logger. The easiest way would be to enable debugging via a parameter during initialization, or using the `AMADEUS_LOG_LEVEL` environment variable. The available options are `silent` (default), `warn`, and `debug`. ```js -var amadeus = new Amadeus({ +const amadeus = new Amadeus({ clientId: 'REPLACE_BY_YOUR_API_KEY', clientSecret: 'REPLACE_BY_YOUR_API_SECRET', logLevel: 'debug' diff --git a/spec/amadeus/client.test.js b/spec/amadeus/client.test.js index 0221418..4a2b894 100644 --- a/spec/amadeus/client.test.js +++ b/spec/amadeus/client.test.js @@ -110,7 +110,7 @@ describe('Client', () => { // make an authenticated POST call client.post(path, params); // ensure Client.call() was called with the right parameters - expect(call).toHaveBeenCalledWith('POST', path, params, 'token'); + expect(call).toHaveBeenCalledWith('POST', path, JSON.stringify(params), 'token'); }); it('should work without params', () => { @@ -119,7 +119,7 @@ describe('Client', () => { return { then: resolve => resolve('token') }; }}; client.post(path); - expect(call).toHaveBeenCalledWith('POST', path, {}, 'token'); + expect(call).toHaveBeenCalledWith('POST', path, JSON.stringify({}), 'token'); }); }); diff --git a/spec/amadeus/namespaces.test.js b/spec/amadeus/namespaces.test.js index 23f0750..f579498 100644 --- a/spec/amadeus/namespaces.test.js +++ b/spec/amadeus/namespaces.test.js @@ -322,21 +322,21 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffers.prediction.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v2/shopping/flight-offers/prediction', JSON.stringify({})); + .toHaveBeenCalledWith('/v2/shopping/flight-offers/prediction', {}); }); it('.amadeus.booking.flightOrders.post', () => { amadeus.client.post = jest.fn(); amadeus.booking.flightOrders.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/booking/flight-orders', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/booking/flight-orders', {}); }); it('.amadeus.shopping.flightOffers.pricing.post', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffers.pricing.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/flight-offers/pricing', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/shopping/flight-offers/pricing', {}); }); it('.amadeus.shopping.flightOffersSearch.get', () => { @@ -350,7 +350,7 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffersSearch.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v2/shopping/flight-offers', JSON.stringify({})); + .toHaveBeenCalledWith('/v2/shopping/flight-offers', {}); }); it('.amadeus.shopping.seatmaps.get', () => { @@ -364,7 +364,7 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.seatmaps.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/seatmaps', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/shopping/seatmaps', {}); }); it('.amadeus.shopping.hotelOfferSearch().get', () => { @@ -430,14 +430,14 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.booking.hotelBookings.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/booking/hotel-bookings', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/booking/hotel-bookings', {}); }); it('.amadeus.booking.hotelOrders.post', () => { amadeus.client.post = jest.fn(); amadeus.booking.hotelOrders.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v2/booking/hotel-orders', JSON.stringify({})); + .toHaveBeenCalledWith('/v2/booking/hotel-orders', {}); }); it('.amadeus.eReputation.hotelSentiments.get', () => { @@ -479,14 +479,14 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.availability.flightAvailabilities.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/availability/flight-availabilities', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/shopping/availability/flight-availabilities', {}); }); it('.amadeus.shopping.flight_offers.upselling.post', () => { amadeus.client.post = jest.fn(); amadeus.shopping.flightOffers.upselling.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/flight-offers/upselling', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/shopping/flight-offers/upselling', {}); }); it('.amadeus.airline.destinations.get', () => { @@ -500,21 +500,21 @@ describe('Namespaces', () => { amadeus.client.post = jest.fn(); amadeus.shopping.transferOffers.post(); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/shopping/transfer-offers', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/shopping/transfer-offers', {}); }); it('.amadeus.ordering.transferOrders.post', () => { amadeus.client.post = jest.fn(); amadeus.ordering.transferOrders.post({}, '1234123123'); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/ordering/transfer-orders?offerId=1234123123', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/ordering/transfer-orders?offerId=1234123123', {}); }); it('.amadeus.ordering.transferOrders().transfers.cancellation.post', () => { amadeus.client.post = jest.fn(); amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, 12345); expect(amadeus.client.post) - .toHaveBeenCalledWith('/v1/ordering/transfer-orders/XXX/transfers/cancellation?confirmNbr=12345', JSON.stringify({})); + .toHaveBeenCalledWith('/v1/ordering/transfer-orders/XXX/transfers/cancellation?confirmNbr=12345', {}); }); }); diff --git a/src/amadeus/client.js b/src/amadeus/client.js index 9d06277..957af49 100644 --- a/src/amadeus/client.js +++ b/src/amadeus/client.js @@ -73,7 +73,8 @@ class Client { * @return {Promise.} a Promise */ post(path, params = {}) { - return this.request('POST', path, params); + const stringifiedParams = typeof params === 'string' ? params : JSON.stringify(params); + return this.request('POST', path, stringifiedParams); } /** diff --git a/src/amadeus/namespaces/booking/flight_orders.js b/src/amadeus/namespaces/booking/flight_orders.js index b13d01e..886883c 100644 --- a/src/amadeus/namespaces/booking/flight_orders.js +++ b/src/amadeus/namespaces/booking/flight_orders.js @@ -33,7 +33,7 @@ class FlightOrders { * ``` */ post(params = {}) { - return this.client.post('/v1/booking/flight-orders', JSON.stringify(params)); + return this.client.post('/v1/booking/flight-orders', params); } } diff --git a/src/amadeus/namespaces/booking/hotel_bookings.js b/src/amadeus/namespaces/booking/hotel_bookings.js index 0ebac11..be813f4 100644 --- a/src/amadeus/namespaces/booking/hotel_bookings.js +++ b/src/amadeus/namespaces/booking/hotel_bookings.js @@ -37,7 +37,7 @@ class HotelBookings { * ``` */ post(params = {}) { - return this.client.post('/v1/booking/hotel-bookings', JSON.stringify(params)); + return this.client.post('/v1/booking/hotel-bookings', params); } } diff --git a/src/amadeus/namespaces/booking/hotel_orders.js b/src/amadeus/namespaces/booking/hotel_orders.js index 64e0c65..d132764 100644 --- a/src/amadeus/namespaces/booking/hotel_orders.js +++ b/src/amadeus/namespaces/booking/hotel_orders.js @@ -39,7 +39,7 @@ class HotelOrders { */ post(params = {}) { - return this.client.post('/v2/booking/hotel-orders', JSON.stringify(params)); + return this.client.post('/v2/booking/hotel-orders', params); } } diff --git a/src/amadeus/namespaces/ordering/transfer_orders.js b/src/amadeus/namespaces/ordering/transfer_orders.js index 9d73c1f..91e872f 100644 --- a/src/amadeus/namespaces/ordering/transfer_orders.js +++ b/src/amadeus/namespaces/ordering/transfer_orders.js @@ -29,7 +29,7 @@ class TransferOrders { * ``` */ post(body, offerId) { - return this.client.post(`/v1/ordering/transfer-orders?offerId=${offerId}`, JSON.stringify(body)); + return this.client.post(`/v1/ordering/transfer-orders?offerId=${offerId}`, body); } } diff --git a/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js b/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js index 73776e6..305c995 100644 --- a/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js +++ b/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js @@ -6,7 +6,7 @@ * * ```js * let amadeus = new Amadeus(); - * amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), '12345');; + * amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, '12345');; * ``` * * @param {Client} client @@ -29,7 +29,7 @@ class Cancellation { */ post(body, confirmNbr) { return this.client.post( - `/v1/ordering/transfer-orders/${this.orderId}/transfers/cancellation?confirmNbr=${confirmNbr}`, JSON.stringify(body)); + `/v1/ordering/transfer-orders/${this.orderId}/transfers/cancellation?confirmNbr=${confirmNbr}`, body); } } diff --git a/src/amadeus/namespaces/shopping/availability/flight_availabilities.js b/src/amadeus/namespaces/shopping/availability/flight_availabilities.js index 59e6da5..8b41300 100644 --- a/src/amadeus/namespaces/shopping/availability/flight_availabilities.js +++ b/src/amadeus/namespaces/shopping/availability/flight_availabilities.js @@ -27,7 +27,7 @@ class FlightAvailabilities { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/availability/flight-availabilities', JSON.stringify(params)); + return this.client.post('/v1/shopping/availability/flight-availabilities', params); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js b/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js index b5f0e70..3d358b7 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js +++ b/src/amadeus/namespaces/shopping/flight_offers/flight_choice_prediction.js @@ -40,7 +40,7 @@ class FlightChoicePrediction { * ``` */ post(params = {}) { - return this.client.post('/v2/shopping/flight-offers/prediction', JSON.stringify(params)); + return this.client.post('/v2/shopping/flight-offers/prediction', params); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers/pricing.js b/src/amadeus/namespaces/shopping/flight_offers/pricing.js index 68b47bc..3d8db6e 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/pricing.js +++ b/src/amadeus/namespaces/shopping/flight_offers/pricing.js @@ -48,7 +48,7 @@ class Pricing { url += '?' + queryString; } - return this.client.post(url, JSON.stringify(params)); + return this.client.post(url, params); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers/upselling.js b/src/amadeus/namespaces/shopping/flight_offers/upselling.js index 393f993..258816b 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/upselling.js +++ b/src/amadeus/namespaces/shopping/flight_offers/upselling.js @@ -27,7 +27,7 @@ class Upselling { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/flight-offers/upselling', JSON.stringify(params)); + return this.client.post('/v1/shopping/flight-offers/upselling', params); } } diff --git a/src/amadeus/namespaces/shopping/flight_offers_search.js b/src/amadeus/namespaces/shopping/flight_offers_search.js index 0aaf2ef..9f00b21 100644 --- a/src/amadeus/namespaces/shopping/flight_offers_search.js +++ b/src/amadeus/namespaces/shopping/flight_offers_search.js @@ -118,7 +118,7 @@ class FlightOffersSearch { * ``` */ post(params = {}) { - return this.client.post('/v2/shopping/flight-offers', JSON.stringify(params)); + return this.client.post('/v2/shopping/flight-offers', params); } } diff --git a/src/amadeus/namespaces/shopping/seatmaps.js b/src/amadeus/namespaces/shopping/seatmaps.js index a176c8f..ce50f64 100644 --- a/src/amadeus/namespaces/shopping/seatmaps.js +++ b/src/amadeus/namespaces/shopping/seatmaps.js @@ -59,7 +59,7 @@ class Seatmaps { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/seatmaps', JSON.stringify(params)); + return this.client.post('/v1/shopping/seatmaps', params); } } diff --git a/src/amadeus/namespaces/shopping/transfer_offers.js b/src/amadeus/namespaces/shopping/transfer_offers.js index f3d3c55..951a462 100644 --- a/src/amadeus/namespaces/shopping/transfer_offers.js +++ b/src/amadeus/namespaces/shopping/transfer_offers.js @@ -31,7 +31,7 @@ class TransferOffers { * ``` */ post(params = {}) { - return this.client.post('/v1/shopping/transfer-offers', JSON.stringify(params)); + return this.client.post('/v1/shopping/transfer-offers', params); } }