Skip to content

Commit 3c84af4

Browse files
committed
Add Support for Hotel Booking V2
1 parent 314395f commit 3c84af4

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ List of supported endpoints
279279
# The offerId comes from the hotel_offer above
280280
amadeus.booking.hotel_bookings.post(offerId, guests, payments)
281281
282+
# Hotel Orders
283+
amadeus.booking.hotel_orders.post(guests=guests, travel_agent=travel_agent)
284+
282285
# Hotel Ratings
283286
# What travelers think about this hotel?
284287
amadeus.e_reputation.hotel_sentiments.get(hotelIds = 'ADNYCCTB')

amadeus/booking/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ._flight_orders import FlightOrders
22
from ._flight_order import FlightOrder
33
from ._hotel_bookings import HotelBookings
4+
from ._hotel_orders import HotelOrders
45

5-
__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings']
6+
__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings', 'HotelOrders']

amadeus/booking/_hotel_orders.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from amadeus.client.decorator import Decorator
2+
3+
4+
class HotelOrders(Decorator, object):
5+
def post(self,
6+
guests,
7+
travel_agent,
8+
room_associations=[],
9+
payment={},
10+
arrival_information={}):
11+
'''
12+
Create Hotel Order
13+
14+
.. code-block:: python
15+
16+
amadeus.booking.hotel_orders.post(guests,
17+
travel_agent,
18+
room_associations,
19+
payment,
20+
arrival_information)
21+
22+
The parameters guests and room_associations can be passed as dictionary
23+
or list of dictionaries. If they are dictionary in this method they are
24+
converted to a list of dictionaries.
25+
26+
:rtype: amadeus.Response
27+
:raises amadeus.ResponseError: if the request could not be completed
28+
'''
29+
guests_info = []
30+
room_associations_info = []
31+
if not isinstance(guests, list):
32+
guests_info.append(guests)
33+
else:
34+
guests_info.extend(guests)
35+
if not isinstance(room_associations, list):
36+
room_associations_info.append(room_associations)
37+
else:
38+
room_associations_info.extend(room_associations)
39+
body = {'data': {'type': 'hotel-order',
40+
'guests': guests_info,
41+
'travelAgent': travel_agent,
42+
'roomAssociations': room_associations_info,
43+
'arrivalInformation': arrival_information,
44+
'payment': payment}}
45+
return self.client.post('/v2/booking/hotel-orders', body)

amadeus/namespaces/_booking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from amadeus.booking._flight_orders import FlightOrders
22
from amadeus.booking._flight_order import FlightOrder
33
from amadeus.booking._hotel_bookings import HotelBookings
4+
from amadeus.booking._hotel_orders import HotelOrders
45
from amadeus.client.decorator import Decorator
56

67

@@ -9,9 +10,10 @@ def __init__(self, client):
910
Decorator.__init__(self, client)
1011
self.flight_orders = FlightOrders(client)
1112
self.hotel_bookings = HotelBookings(client)
13+
self.hotel_orders = HotelOrders(client)
1214

1315
def flight_order(self, flight_order_id):
1416
return FlightOrder(self.client, flight_order_id)
1517

1618

17-
__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings']
19+
__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings', 'HotelOrders']

docs/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ Booking
218218
.. autoclass:: amadeus.booking.HotelBookings
219219
:members: post
220220

221+
.. autoclass:: amadeus.booking.HotelOrders
222+
:members: post
223+
224+
221225
Schedule/Flights
222226
================
223227

specs/namespaces/test_namespaces.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def test_expected_paths(client):
5555
assert client.travel.from_base64 is not None
5656
assert client.booking.flight_orders is not None
5757
assert client.booking.flight_order is not None
58+
assert client.booking.hotel_orders is not None
5859
assert client.schedule is not None
5960
assert client.schedule.flights is not None
6061
assert client.analytics is not None
@@ -435,6 +436,35 @@ def test_shopping_booking_hotel_bookings_post_list(client_setup):
435436
)
436437

437438

439+
def test_booking_hotel_orders_post(client_setup):
440+
client_setup.booking.hotel_orders.post({'foo': 'bar'},
441+
{'bar': 'foo'})
442+
client_setup.post.assert_called_with(
443+
'/v2/booking/hotel-orders',
444+
{'data': {'type': 'hotel-order',
445+
'guests': [{'foo': 'bar'}],
446+
'travelAgent': {'bar': 'foo'},
447+
'roomAssociations': [],
448+
'payment': {},
449+
'arrivalInformation': {}}}
450+
)
451+
452+
453+
def test_booking_hotel_orders_post_list(client_setup):
454+
client_setup.booking.hotel_orders.post([{'foo': 'bar'}],
455+
{'bar': 'foo'},
456+
[{'a': 'b'}],)
457+
client_setup.post.assert_called_with(
458+
'/v2/booking/hotel-orders',
459+
{'data': {'type': 'hotel-order',
460+
'guests': [{'foo': 'bar'}],
461+
'travelAgent': {'bar': 'foo'},
462+
'roomAssociations': [{'a': 'b'}],
463+
'payment': {},
464+
'arrivalInformation': {}}}
465+
)
466+
467+
438468
def test_schedule_flights_get(client_setup):
439469
client_setup.schedule.flights.get(a='b')
440470
client_setup.get.assert_called_with(

0 commit comments

Comments
 (0)