Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Hotel booking v2 #216

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,16 @@ amadeus.shopping.hotelOffersSearch.get({
// Check offer conditions of a specific offer id
amadeus.shopping.hotelOfferSearch('XXX').get()

// Hotel Booking API
// Hotel Booking API V2
minjikarin marked this conversation as resolved.
Show resolved Hide resolved
amadeus.booking.hotelOrders.post({
guests: [],
travelAgent: {},
roomAssociations: [],
payment: {}
})


// Hotel Booking API V1
minjikarin marked this conversation as resolved.
Show resolved Hide resolved
amadeus.booking.hotelBookings.post(
JSON.stringify({
'offerId': 'XXX',
Expand Down
17 changes: 17 additions & 0 deletions spec/amadeus/namespaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ describe('Namespaces', () => {
expect(amadeus.shopping.flightOffers.pricing.post).toBeDefined();
expect(amadeus.shopping.seatmaps.post).toBeDefined();
expect(amadeus.booking.hotelBookings.post).toBeDefined();
expect(amadeus.booking.hotelOrders.post).toBeDefined();
expect(amadeus.shopping.transferOffers.post).toBeDefined();
expect(amadeus.ordering.transferOrders.post).toBeDefined();
expect(amadeus.ordering.transferOrder('XXX').transfers.cancellation.post).toBeDefined();
Expand Down Expand Up @@ -447,6 +448,22 @@ describe('Namespaces', () => {
.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({
data: {
type: 'hotel-order',
guests: [],
travelAgent: {},
roomAssociations: [],
payment: {},
arrivalInformation: {}
}
}));
});

it('.amadeus.eReputation.hotelSentiments.get', () => {
amadeus.client.get = jest.fn();
amadeus.eReputation.hotelSentiments.get();
Expand Down
3 changes: 3 additions & 0 deletions src/amadeus/namespaces/booking.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import FlightOrders from './booking/flight_orders';
import FlightOrder from './booking/flight_order';
import HotelBookings from './booking/hotel_bookings';
import HotelOrders from './booking/hotel_orders';

/**
* A namespaced client for the
Expand All @@ -17,13 +18,15 @@ import HotelBookings from './booking/hotel_bookings';
* @property {FlightOrders} flightOrders
* @property {FlightOrder} flightOrder
* @property {HotelBookings} hotelBookings
* @property {HotelOrders} hotelOrders
* @protected
*/
class Booking {
constructor(client) {
this.client = client;
this.flightOrders = new FlightOrders(client);
this.hotelBookings = new HotelBookings(client);
this.hotelOrders = new HotelOrders(client);
}

flightOrder (orderId) {
Expand Down
2 changes: 1 addition & 1 deletion src/amadeus/namespaces/booking/flight_orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FlightOrders {
* amadeus.booking.flightOrders.post({
* 'type': 'flight-order',
* 'flightOffers': [],
* 'travelers_info': []
* 'traveler': []
minjikarin marked this conversation as resolved.
Show resolved Hide resolved
* });
* ```
*/
Expand Down
53 changes: 53 additions & 0 deletions src/amadeus/namespaces/booking/hotel_orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* A namespaced client for the
* `/v2/booking/hotel-orders` endpoints
*
* Access via the {@link Amadeus} object
*
* ```js
* let amadeus = new Amadeus();
* amadeus.booking.hotelOrders;
* ```
*
* @param {Client} client
*/
class HotelOrders {
constructor(client) {
this.client = client;
}

/**
* To book the offer retrieved from Hotel Search API.
*
* @param {Object} params
* @return {Promise.<Response,ResponseError>} a Promise
*
* To book the hotel offer with ID 'XXX' with guests, travel agents and payment info
*
* ```js
* amadeus.booking.hotelOrders.post({
minjikarin marked this conversation as resolved.
Show resolved Hide resolved
* 'guests': [],
* 'travel_agent: {},
* 'room_associations: [],
* 'payment': {},
* 'arrivalInformation': {}
* });
* ```
*/
post(params = {}) {
minjikarin marked this conversation as resolved.
Show resolved Hide resolved
const body = {
data: {
type: 'hotel-order',
guests: params.guests || [],
travelAgent: params.travelAgent || {},
roomAssociations: params.roomAssociations || [],
payment: params.payment || {},
arrivalInformation: params.arrivalInformation || {}
}
};

return this.client.post('/v2/booking/hotel-orders', JSON.stringify(body));
}
}

export default HotelOrders;
Loading