Skip to content

Commit 6bd1777

Browse files
committed
Added Hotel booking v2
1 parent 04c6938 commit 6bd1777

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

spec/amadeus/namespaces.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@ describe('Namespaces', () => {
447447
.toHaveBeenCalledWith('/v1/booking/hotel-bookings', {});
448448
});
449449

450+
it('.amadeus.booking.hotelOrders.post', () => {
451+
amadeus.client.post = jest.fn();
452+
amadeus.booking.hotelOrders.post();
453+
expect(amadeus.client.post)
454+
.toHaveBeenCalledWith('/v2/booking/hotel-orders', {});
455+
});
456+
450457
it('.amadeus.eReputation.hotelSentiments.get', () => {
451458
amadeus.client.get = jest.fn();
452459
amadeus.eReputation.hotelSentiments.get();

src/amadeus/namespaces/booking.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import FlightOrders from './booking/flight_orders';
22
import FlightOrder from './booking/flight_order';
33
import HotelBookings from './booking/hotel_bookings';
4+
import HotelOrders from './booking/hotel_orders';
45

56
/**
67
* A namespaced client for the
@@ -17,13 +18,15 @@ import HotelBookings from './booking/hotel_bookings';
1718
* @property {FlightOrders} flightOrders
1819
* @property {FlightOrder} flightOrder
1920
* @property {HotelBookings} hotelBookings
21+
* @property {HotelOrders} hotelOrders
2022
* @protected
2123
*/
2224
class Booking {
2325
constructor(client) {
2426
this.client = client;
2527
this.flightOrders = new FlightOrders(client);
2628
this.hotelBookings = new HotelBookings(client);
29+
this.hotelOrders = new HotelOrders(client);
2730
}
2831

2932
flightOrder (orderId) {

src/amadeus/namespaces/booking/flight_orders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FlightOrders {
2828
* amadeus.booking.flightOrders.post({
2929
* 'type': 'flight-order',
3030
* 'flightOffers': [],
31-
* 'travelers_info': []
31+
* 'traveler': []
3232
* });
3333
* ```
3434
*/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* A namespaced client for the
3+
* `/v2/booking/hotel-orders` endpoints
4+
*
5+
* Access via the {@link Amadeus} object
6+
*
7+
* ```js
8+
* let amadeus = new Amadeus();
9+
* amadeus.booking.hotelOrders;
10+
* ```
11+
*
12+
* @param {Client} client
13+
*/
14+
class HotelOrders {
15+
constructor(client) {
16+
this.client = client;
17+
}
18+
19+
/**
20+
* To book the offer retrieved from Hotel Search API.
21+
*
22+
* @param {Object} params
23+
* @return {Promise.<Response,ResponseError>} a Promise
24+
*
25+
* To book the hotel offer with ID 'XXX' with guests, travel agents and payment info
26+
*
27+
* ```js
28+
* amadeus.booking.hotelOrders.post({
29+
* 'guests': [],
30+
* 'travel_agent: {},
31+
* 'room_associations: [],
32+
* 'payment': {}
33+
* });
34+
* ```
35+
*/
36+
post(params = {}) {
37+
const body = {
38+
data: {
39+
type: 'hotel-order',
40+
guests: params.guests || [],
41+
travelAgent: params.travelAgent || {},
42+
roomAssociations: params.roomAssociations || [],
43+
payment: params.payment || {},
44+
arrivalInformation: params.arrivalInformation || {}
45+
}
46+
};
47+
48+
return this.client.post('/v2/booking/hotel-orders', JSON.stringify(body));
49+
}
50+
}
51+
52+
export default HotelOrders;

test1copy.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var Amadeus = require('./lib/amadeus');
2+
3+
var amadeus = new Amadeus({
4+
clientId: '8nO6oq4ywwDlqZG3btuBy7bkSoAjZGdn',
5+
clientSecret: 'BJyF3fvNG9frmkAE',
6+
logLevel: 'debug'
7+
});
8+
9+
body = {
10+
"originDestinations": [
11+
{
12+
"id": "1",
13+
"originLocationCode": "BOS",
14+
"destinationLocationCode": "MAD",
15+
"departureDateTime": {
16+
"date": "{{departureDate}}",
17+
"time": "21:15:00"
18+
}
19+
}
20+
],
21+
"travelers": [
22+
{
23+
"id": "1",
24+
"travelerType": "ADULT"
25+
},
26+
{
27+
"id": "2",
28+
"travelerType": "CHILD"
29+
}
30+
],
31+
"sources": [
32+
"GDS"
33+
]
34+
}
35+
36+
amadeus.shopping.availability.flightAvailabilities.post(body).then(function (response) {
37+
console.log(response);
38+
}).catch(function (response) {
39+
console.error(response);
40+
});

0 commit comments

Comments
 (0)