diff --git a/README.rst b/README.rst index 4552ff36..51f7f045 100644 --- a/README.rst +++ b/README.rst @@ -279,6 +279,9 @@ List of supported endpoints # The offerId comes from the hotel_offer above amadeus.booking.hotel_bookings.post(offerId, guests, payments) + # Hotel Orders + amadeus.booking.hotel_orders.post(guests=guests, travel_agent=travel_agent) + # Hotel Ratings # What travelers think about this hotel? amadeus.e_reputation.hotel_sentiments.get(hotelIds = 'ADNYCCTB') diff --git a/amadeus/booking/__init__.py b/amadeus/booking/__init__.py index 1efb8e6e..30f095b5 100644 --- a/amadeus/booking/__init__.py +++ b/amadeus/booking/__init__.py @@ -1,5 +1,6 @@ from ._flight_orders import FlightOrders from ._flight_order import FlightOrder from ._hotel_bookings import HotelBookings +from ._hotel_orders import HotelOrders -__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings'] +__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings', 'HotelOrders'] diff --git a/amadeus/booking/_hotel_orders.py b/amadeus/booking/_hotel_orders.py new file mode 100644 index 00000000..eb512d6c --- /dev/null +++ b/amadeus/booking/_hotel_orders.py @@ -0,0 +1,45 @@ +from amadeus.client.decorator import Decorator + + +class HotelOrders(Decorator, object): + def post(self, + guests, + travel_agent, + room_associations, + payment, + arrival_information): + ''' + Create Hotel Order + + .. code-block:: python + + amadeus.booking.hotel_orders.post(guests, + travel_agent, + room_associations, + payment, + arrival_information) + + The parameters guests and room_associations can be passed as dictionary + or list of dictionaries. If they are dictionary in this method they are + converted to a list of dictionaries. + + :rtype: amadeus.Response + :raises amadeus.ResponseError: if the request could not be completed + ''' + guests_info = [] + room_associations_info = [] + if not isinstance(guests, list): + guests_info.append(guests) + else: + guests_info.extend(guests) + if not isinstance(room_associations, list): + room_associations_info.append(room_associations) + else: + room_associations_info.extend(room_associations) + body = {'data': {'type': 'hotel-order', + 'guests': guests_info, + 'travelAgent': travel_agent, + 'roomAssociations': room_associations_info, + 'arrivalInformation': arrival_information, + 'payment': payment}} + return self.client.post('/v2/booking/hotel-orders', body) diff --git a/amadeus/namespaces/_booking.py b/amadeus/namespaces/_booking.py index 94e64e3f..332b3f5a 100644 --- a/amadeus/namespaces/_booking.py +++ b/amadeus/namespaces/_booking.py @@ -1,6 +1,7 @@ from amadeus.booking._flight_orders import FlightOrders from amadeus.booking._flight_order import FlightOrder from amadeus.booking._hotel_bookings import HotelBookings +from amadeus.booking._hotel_orders import HotelOrders from amadeus.client.decorator import Decorator @@ -9,9 +10,10 @@ def __init__(self, client): Decorator.__init__(self, client) self.flight_orders = FlightOrders(client) self.hotel_bookings = HotelBookings(client) + self.hotel_orders = HotelOrders(client) def flight_order(self, flight_order_id): return FlightOrder(self.client, flight_order_id) -__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings'] +__all__ = ['FlightOrders', 'FlightOrder', 'HotelBookings', 'HotelOrders'] diff --git a/docs/index.rst b/docs/index.rst index 96fe572d..364cfa56 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -218,6 +218,10 @@ Booking .. autoclass:: amadeus.booking.HotelBookings :members: post +.. autoclass:: amadeus.booking.HotelOrders + :members: post + + Schedule/Flights ================ diff --git a/specs/namespaces/test_namespaces.py b/specs/namespaces/test_namespaces.py index 4687e9a6..89427357 100644 --- a/specs/namespaces/test_namespaces.py +++ b/specs/namespaces/test_namespaces.py @@ -55,6 +55,7 @@ def test_expected_paths(client): assert client.travel.from_base64 is not None assert client.booking.flight_orders is not None assert client.booking.flight_order is not None + assert client.booking.hotel_orders is not None assert client.schedule is not None assert client.schedule.flights is not None assert client.analytics is not None @@ -435,6 +436,33 @@ def test_shopping_booking_hotel_bookings_post_list(client_setup): ) +def test_booking_hotel_orders_post(client_setup): + client_setup.booking.hotel_orders.post({'foo': 'bar'}, + {'bar': 'foo'}) + client_setup.post.assert_called_with( + '/v2/booking/hotel-orders', + {'data': {'type': 'hotel-order', + 'guests': [{'foo': 'bar'}], + 'travelAgent': {'bar': 'foo'}, + 'roomAssociations': [], + 'payment': None}} + ) + + +def test_booking_hotel_orders_post_list(client_setup): + client_setup.booking.hotel_orders.post([{'foo': 'bar'}], + {'bar': 'foo'}, + [{'a': 'b'}],) + client_setup.post.assert_called_with( + '/v2/booking/hotel-orders', + {'data': {'type': 'hotel-order', + 'guests': [{'foo': 'bar'}], + 'travelAgent': {'bar': 'foo'}, + 'roomAssociations': [{'a': 'b'}], + 'payment': None}} + ) + + def test_schedule_flights_get(client_setup): client_setup.schedule.flights.get(a='b') client_setup.get.assert_called_with(