Skip to content

Commit 7b2d050

Browse files
committed
stringified params while maintaining backwards compatibility
1 parent f6fb447 commit 7b2d050

File tree

16 files changed

+37
-36
lines changed

16 files changed

+37
-36
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ npm install amadeus --save
2121
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).
2222

2323
```js
24-
var Amadeus = require('amadeus');
24+
const Amadeus = require('amadeus');
2525

26-
var amadeus = new Amadeus({
26+
const amadeus = new Amadeus({
2727
clientId: 'REPLACE_BY_YOUR_API_KEY',
2828
clientSecret: 'REPLACE_BY_YOUR_API_SECRET'
2929
});
@@ -50,7 +50,7 @@ The client can be initialized directly.
5050

5151
```js
5252
// Initialize using parameters
53-
var amadeus = new Amadeus({
53+
const amadeus = new Amadeus({
5454
clientId: 'REPLACE_BY_YOUR_API_KEY',
5555
clientSecret: 'REPLACE_BY_YOUR_API_SECRET'
5656
});
@@ -59,15 +59,15 @@ var amadeus = new Amadeus({
5959
Alternatively, it can be initialized without any parameters if the environment variables `AMADEUS_CLIENT_ID` and `AMADEUS_CLIENT_SECRET` are present.
6060

6161
```js
62-
var amadeus = new Amadeus();
62+
const amadeus = new Amadeus();
6363
```
6464

6565
Your credentials can be found on the [Amadeus dashboard](https://developers.amadeus.com/my-apps).
6666

6767
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:
6868

6969
```js
70-
var amadeus = new Amadeus({
70+
const amadeus = new Amadeus({
7171
hostname: 'production'
7272
});
7373
```
@@ -104,7 +104,7 @@ amadeus.client.get('/v2/reference-data/urls/checkin-links', { airlineCode: 'BA'
104104

105105
Or, with a `POST` using `.client.post` method:
106106
```js
107-
amadeus.client.post('/v1/shopping/flight-offers/pricing', JSON.stringify({ data }));
107+
amadeus.client.post('/v1/shopping/flight-offers/pricing', { data });
108108
```
109109

110110
## Promises
@@ -152,7 +152,7 @@ If a page is not available, the response will resolve to `null`.
152152
The SDK makes it easy to add your own logger that is compatible with the default `console`.
153153

154154
```js
155-
var amadeus = new Amadeus({
155+
const amadeus = new Amadeus({
156156
clientId: 'REPLACE_BY_YOUR_API_KEY',
157157
clientSecret: 'REPLACE_BY_YOUR_API_SECRET',
158158
logger: new MyConsole()
@@ -162,7 +162,7 @@ var amadeus = new Amadeus({
162162
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`.
163163

164164
```js
165-
var amadeus = new Amadeus({
165+
const amadeus = new Amadeus({
166166
clientId: 'REPLACE_BY_YOUR_API_KEY',
167167
clientSecret: 'REPLACE_BY_YOUR_API_SECRET',
168168
logLevel: 'debug'

spec/amadeus/client.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('Client', () => {
110110
// make an authenticated POST call
111111
client.post(path, params);
112112
// ensure Client.call() was called with the right parameters
113-
expect(call).toHaveBeenCalledWith('POST', path, params, 'token');
113+
expect(call).toHaveBeenCalledWith('POST', path, JSON.stringify(params), 'token');
114114
});
115115

116116
it('should work without params', () => {
@@ -119,7 +119,7 @@ describe('Client', () => {
119119
return { then: resolve => resolve('token') };
120120
}};
121121
client.post(path);
122-
expect(call).toHaveBeenCalledWith('POST', path, {}, 'token');
122+
expect(call).toHaveBeenCalledWith('POST', path, JSON.stringify({}), 'token');
123123
});
124124
});
125125

spec/amadeus/namespaces.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,21 +322,21 @@ describe('Namespaces', () => {
322322
amadeus.client.post = jest.fn();
323323
amadeus.shopping.flightOffers.prediction.post();
324324
expect(amadeus.client.post)
325-
.toHaveBeenCalledWith('/v2/shopping/flight-offers/prediction', JSON.stringify({}));
325+
.toHaveBeenCalledWith('/v2/shopping/flight-offers/prediction', {});
326326
});
327327

328328
it('.amadeus.booking.flightOrders.post', () => {
329329
amadeus.client.post = jest.fn();
330330
amadeus.booking.flightOrders.post();
331331
expect(amadeus.client.post)
332-
.toHaveBeenCalledWith('/v1/booking/flight-orders', JSON.stringify({}));
332+
.toHaveBeenCalledWith('/v1/booking/flight-orders', {});
333333
});
334334

335335
it('.amadeus.shopping.flightOffers.pricing.post', () => {
336336
amadeus.client.post = jest.fn();
337337
amadeus.shopping.flightOffers.pricing.post();
338338
expect(amadeus.client.post)
339-
.toHaveBeenCalledWith('/v1/shopping/flight-offers/pricing', JSON.stringify({}));
339+
.toHaveBeenCalledWith('/v1/shopping/flight-offers/pricing', {});
340340
});
341341

342342
it('.amadeus.shopping.flightOffersSearch.get', () => {
@@ -350,7 +350,7 @@ describe('Namespaces', () => {
350350
amadeus.client.post = jest.fn();
351351
amadeus.shopping.flightOffersSearch.post();
352352
expect(amadeus.client.post)
353-
.toHaveBeenCalledWith('/v2/shopping/flight-offers', JSON.stringify({}));
353+
.toHaveBeenCalledWith('/v2/shopping/flight-offers', {});
354354
});
355355

356356
it('.amadeus.shopping.seatmaps.get', () => {
@@ -364,7 +364,7 @@ describe('Namespaces', () => {
364364
amadeus.client.post = jest.fn();
365365
amadeus.shopping.seatmaps.post();
366366
expect(amadeus.client.post)
367-
.toHaveBeenCalledWith('/v1/shopping/seatmaps', JSON.stringify({}));
367+
.toHaveBeenCalledWith('/v1/shopping/seatmaps', {});
368368
});
369369

370370
it('.amadeus.shopping.hotelOfferSearch().get', () => {
@@ -430,14 +430,14 @@ describe('Namespaces', () => {
430430
amadeus.client.post = jest.fn();
431431
amadeus.booking.hotelBookings.post();
432432
expect(amadeus.client.post)
433-
.toHaveBeenCalledWith('/v1/booking/hotel-bookings', JSON.stringify({}));
433+
.toHaveBeenCalledWith('/v1/booking/hotel-bookings', {});
434434
});
435435

436436
it('.amadeus.booking.hotelOrders.post', () => {
437437
amadeus.client.post = jest.fn();
438438
amadeus.booking.hotelOrders.post();
439439
expect(amadeus.client.post)
440-
.toHaveBeenCalledWith('/v2/booking/hotel-orders', JSON.stringify({}));
440+
.toHaveBeenCalledWith('/v2/booking/hotel-orders', {});
441441
});
442442

443443
it('.amadeus.eReputation.hotelSentiments.get', () => {
@@ -479,14 +479,14 @@ describe('Namespaces', () => {
479479
amadeus.client.post = jest.fn();
480480
amadeus.shopping.availability.flightAvailabilities.post();
481481
expect(amadeus.client.post)
482-
.toHaveBeenCalledWith('/v1/shopping/availability/flight-availabilities', JSON.stringify({}));
482+
.toHaveBeenCalledWith('/v1/shopping/availability/flight-availabilities', {});
483483
});
484484

485485
it('.amadeus.shopping.flight_offers.upselling.post', () => {
486486
amadeus.client.post = jest.fn();
487487
amadeus.shopping.flightOffers.upselling.post();
488488
expect(amadeus.client.post)
489-
.toHaveBeenCalledWith('/v1/shopping/flight-offers/upselling', JSON.stringify({}));
489+
.toHaveBeenCalledWith('/v1/shopping/flight-offers/upselling', {});
490490
});
491491

492492
it('.amadeus.airline.destinations.get', () => {
@@ -500,21 +500,21 @@ describe('Namespaces', () => {
500500
amadeus.client.post = jest.fn();
501501
amadeus.shopping.transferOffers.post();
502502
expect(amadeus.client.post)
503-
.toHaveBeenCalledWith('/v1/shopping/transfer-offers', JSON.stringify({}));
503+
.toHaveBeenCalledWith('/v1/shopping/transfer-offers', {});
504504
});
505505

506506
it('.amadeus.ordering.transferOrders.post', () => {
507507
amadeus.client.post = jest.fn();
508508
amadeus.ordering.transferOrders.post({}, '1234123123');
509509
expect(amadeus.client.post)
510-
.toHaveBeenCalledWith('/v1/ordering/transfer-orders?offerId=1234123123', JSON.stringify({}));
510+
.toHaveBeenCalledWith('/v1/ordering/transfer-orders?offerId=1234123123', {});
511511
});
512512

513513
it('.amadeus.ordering.transferOrders().transfers.cancellation.post', () => {
514514
amadeus.client.post = jest.fn();
515515
amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, 12345);
516516
expect(amadeus.client.post)
517-
.toHaveBeenCalledWith('/v1/ordering/transfer-orders/XXX/transfers/cancellation?confirmNbr=12345', JSON.stringify({}));
517+
.toHaveBeenCalledWith('/v1/ordering/transfer-orders/XXX/transfers/cancellation?confirmNbr=12345', {});
518518
});
519519

520520
});

src/amadeus/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class Client {
7373
* @return {Promise.<Response,ResponseError>} a Promise
7474
*/
7575
post(path, params = {}) {
76-
return this.request('POST', path, params);
76+
const stringifiedParams = typeof params === 'string' ? params : JSON.stringify(params);
77+
return this.request('POST', path, stringifiedParams);
7778
}
7879

7980
/**

src/amadeus/namespaces/booking/flight_orders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FlightOrders {
3333
* ```
3434
*/
3535
post(params = {}) {
36-
return this.client.post('/v1/booking/flight-orders', JSON.stringify(params));
36+
return this.client.post('/v1/booking/flight-orders', params);
3737
}
3838
}
3939

src/amadeus/namespaces/booking/hotel_bookings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class HotelBookings {
3737
* ```
3838
*/
3939
post(params = {}) {
40-
return this.client.post('/v1/booking/hotel-bookings', JSON.stringify(params));
40+
return this.client.post('/v1/booking/hotel-bookings', params);
4141
}
4242
}
4343

src/amadeus/namespaces/booking/hotel_orders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class HotelOrders {
3939
4040
*/
4141
post(params = {}) {
42-
return this.client.post('/v2/booking/hotel-orders', JSON.stringify(params));
42+
return this.client.post('/v2/booking/hotel-orders', params);
4343
}
4444
}
4545

src/amadeus/namespaces/ordering/transfer_orders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TransferOrders {
2929
* ```
3030
*/
3131
post(body, offerId) {
32-
return this.client.post(`/v1/ordering/transfer-orders?offerId=${offerId}`, JSON.stringify(body));
32+
return this.client.post(`/v1/ordering/transfer-orders?offerId=${offerId}`, body);
3333
}
3434
}
3535

src/amadeus/namespaces/ordering/transfer_orders/transfers/cancellation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* ```js
88
* let amadeus = new Amadeus();
9-
* amadeus.ordering.transferOrder('XXX').transfers.cancellation.post(JSON.stringify({}), '12345');;
9+
* amadeus.ordering.transferOrder('XXX').transfers.cancellation.post({}, '12345');;
1010
* ```
1111
*
1212
* @param {Client} client
@@ -29,7 +29,7 @@ class Cancellation {
2929
*/
3030
post(body, confirmNbr) {
3131
return this.client.post(
32-
`/v1/ordering/transfer-orders/${this.orderId}/transfers/cancellation?confirmNbr=${confirmNbr}`, JSON.stringify(body));
32+
`/v1/ordering/transfer-orders/${this.orderId}/transfers/cancellation?confirmNbr=${confirmNbr}`, body);
3333
}
3434
}
3535

src/amadeus/namespaces/shopping/availability/flight_availabilities.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FlightAvailabilities {
2727
* ```
2828
*/
2929
post(params = {}) {
30-
return this.client.post('/v1/shopping/availability/flight-availabilities', JSON.stringify(params));
30+
return this.client.post('/v1/shopping/availability/flight-availabilities', params);
3131
}
3232
}
3333

0 commit comments

Comments
 (0)