From 8ab506d090e84f64640e51e9857b20b9387ae08a Mon Sep 17 00:00:00 2001 From: MinjiK Date: Tue, 5 Dec 2023 15:37:22 +0100 Subject: [PATCH 1/6] update pricing endpoint --- .../namespaces/shopping/flight_offers/pricing.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/amadeus/namespaces/shopping/flight_offers/pricing.js b/src/amadeus/namespaces/shopping/flight_offers/pricing.js index 2658b34..3214447 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/pricing.js +++ b/src/amadeus/namespaces/shopping/flight_offers/pricing.js @@ -38,8 +38,20 @@ class Pricing { * }); * ``` */ - post(params = {}) { - return this.client.post('/v1/shopping/flight-offers/pricing', params); + post(params = {}, additionalParams = {}) { + // Check if params is an array + if (Array.isArray(params)) { + // If it is, wrap it in the required structure + params = { + 'data': { + 'type': 'flight-offers-pricing', + 'flightOffers': params + } + }; + } + // Convert additionalParams object to query string + const queryString = Object.keys(additionalParams).map(key => key + '=' + additionalParams[key]).join('&'); + return this.client.post('/v1/shopping/flight-offers/pricing?' + queryString, JSON.stringify(params)); } } From c35e09ab9b5b7a84dd314771860ee642df62c4b2 Mon Sep 17 00:00:00 2001 From: MinjiK Date: Tue, 5 Dec 2023 16:49:55 +0100 Subject: [PATCH 2/6] post method support JSON.springify --- src/amadeus/namespaces/booking/flight_orders.js | 2 +- src/amadeus/namespaces/ordering/transfer_orders.js | 2 +- .../ordering/transfer_orders/transfers/cancellation.js | 6 +++--- .../shopping/availability/flight_availabilities.js | 2 +- src/amadeus/namespaces/shopping/flight_offers/upselling.js | 2 +- src/amadeus/namespaces/shopping/flight_offers_search.js | 6 +++--- src/amadeus/namespaces/shopping/seatmaps.js | 6 +++--- src/amadeus/namespaces/shopping/transfer_offers.js | 2 +- src/amadeus/namespaces/travel/trip_parser.js | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/amadeus/namespaces/booking/flight_orders.js b/src/amadeus/namespaces/booking/flight_orders.js index 94554f1..e8d564d 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..61c0d84 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}`, 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 99288a9..73c2f8d 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 @@ -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/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..5f461f2 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..225a613 100644 --- a/src/amadeus/namespaces/shopping/seatmaps.js +++ b/src/amadeus/namespaces/shopping/seatmaps.js @@ -51,15 +51,15 @@ class Seatmaps { * departureDate: '2020-08-01' * }).then(function(response){ * return amadeus.shopping.flightOffers.seatmaps.post( - * JSON.stringify({ + * { * 'data': response.data - * }) + * } * ); * }); * ``` */ 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 8bd94afc34375316f9bb1eace8b0b33b6e63bddd Mon Sep 17 00:00:00 2001 From: MinjiK Date: Tue, 5 Dec 2023 17:48:18 +0100 Subject: [PATCH 3/6] remove json.stringify --- src/amadeus/namespaces/shopping/flight_offers/pricing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amadeus/namespaces/shopping/flight_offers/pricing.js b/src/amadeus/namespaces/shopping/flight_offers/pricing.js index 3214447..b862c80 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/pricing.js +++ b/src/amadeus/namespaces/shopping/flight_offers/pricing.js @@ -51,7 +51,7 @@ class Pricing { } // Convert additionalParams object to query string const queryString = Object.keys(additionalParams).map(key => key + '=' + additionalParams[key]).join('&'); - return this.client.post('/v1/shopping/flight-offers/pricing?' + queryString, JSON.stringify(params)); + return this.client.post('/v1/shopping/flight-offers/pricing?' + queryString, params); } } From 96bc0ee548989a6ddcfd3d7d36ff05087de5f1b1 Mon Sep 17 00:00:00 2001 From: MinjiK Date: Tue, 5 Dec 2023 17:52:02 +0100 Subject: [PATCH 4/6] fallback json.stringify --- src/amadeus/namespaces/booking/flight_orders.js | 2 +- src/amadeus/namespaces/ordering/transfer_orders.js | 2 +- .../ordering/transfer_orders/transfers/cancellation.js | 2 +- src/amadeus/namespaces/shopping/flight_offers/upselling.js | 2 +- src/amadeus/namespaces/shopping/flight_offers_search.js | 2 +- src/amadeus/namespaces/shopping/seatmaps.js | 2 +- src/amadeus/namespaces/shopping/transfer_offers.js | 2 +- src/amadeus/namespaces/travel/trip_parser.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/amadeus/namespaces/booking/flight_orders.js b/src/amadeus/namespaces/booking/flight_orders.js index e8d564d..94554f1 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/ordering/transfer_orders.js b/src/amadeus/namespaces/ordering/transfer_orders.js index 61c0d84..ff4871f 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 73c2f8d..305c995 100644 --- a/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js +++ b/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js @@ -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/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 5f461f2..e7b407e 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 225a613..2774cb7 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); } } diff --git a/src/amadeus/namespaces/travel/trip_parser.js b/src/amadeus/namespaces/travel/trip_parser.js index 660cd5b..382a8a1 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', JSON.stringify(params)); + return this.client.post('/v3/travel/trip-parser', params); } /** * Helper method to convert file contents in UTF-8 encoded string From 316873a1ddb47cb307145365b9790b82e7c8efae Mon Sep 17 00:00:00 2001 From: MinjiK Date: Tue, 5 Dec 2023 17:55:20 +0100 Subject: [PATCH 5/6] fallback2 --- .../ordering/transfer_orders/transfers/cancellation.js | 4 ++-- .../shopping/availability/flight_availabilities.js | 2 +- src/amadeus/namespaces/shopping/flight_offers_search.js | 6 +++--- src/amadeus/namespaces/shopping/seatmaps.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js b/src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js index 305c995..64a1952 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({}, '12345');; + * amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), '12345');; * ``` * * @param {Client} client @@ -24,7 +24,7 @@ class Cancellation { * To cancel a transfer order with ID 'XXX' and confirmation number '12345' * * ```js - * amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, '12345');; + * amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), '12345');; * ``` */ post(body, confirmNbr) { 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_search.js b/src/amadeus/namespaces/shopping/flight_offers_search.js index e7b407e..d2198d6 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 ({ + * amadeus.shopping.flightOffersSearch.post (JSON.stringify({ "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', params); } } diff --git a/src/amadeus/namespaces/shopping/seatmaps.js b/src/amadeus/namespaces/shopping/seatmaps.js index 2774cb7..749d180 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 - * } + * }) * ); * }); * ``` From 0e6b43bffd5ab97476852f99f70a3be8507d72cd Mon Sep 17 00:00:00 2001 From: MinjiK Date: Tue, 5 Dec 2023 18:38:09 +0100 Subject: [PATCH 6/6] remove unnecessary changes --- .../shopping/flight_offers/pricing.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/amadeus/namespaces/shopping/flight_offers/pricing.js b/src/amadeus/namespaces/shopping/flight_offers/pricing.js index b862c80..3d8db6e 100644 --- a/src/amadeus/namespaces/shopping/flight_offers/pricing.js +++ b/src/amadeus/namespaces/shopping/flight_offers/pricing.js @@ -39,19 +39,16 @@ class Pricing { * ``` */ post(params = {}, additionalParams = {}) { - // Check if params is an array - if (Array.isArray(params)) { - // If it is, wrap it in the required structure - params = { - 'data': { - 'type': 'flight-offers-pricing', - 'flightOffers': params - } - }; - } // Convert additionalParams object to query string const queryString = Object.keys(additionalParams).map(key => key + '=' + additionalParams[key]).join('&'); - return this.client.post('/v1/shopping/flight-offers/pricing?' + queryString, params); + + // Check if queryString is empty before appending it to the URL + let url = '/v1/shopping/flight-offers/pricing'; + if (queryString !== '') { + url += '?' + queryString; + } + + return this.client.post(url, params); } }