From 3c84af48732d140af27ddc85c56a0ff3eae5fad0 Mon Sep 17 00:00:00 2001 From: Siddhartha Dutta Date: Thu, 13 Jun 2024 18:36:44 +0530 Subject: [PATCH 1/4] Add Support for Hotel Booking V2 --- README.rst | 3 ++ amadeus/booking/__init__.py | 3 +- amadeus/booking/_hotel_orders.py | 45 +++++++++++++++++++++++++++++ amadeus/namespaces/_booking.py | 4 ++- docs/index.rst | 4 +++ specs/namespaces/test_namespaces.py | 30 +++++++++++++++++++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 amadeus/booking/_hotel_orders.py 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..7dd3507e --- /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..856a702f 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,35 @@ 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': {}, + 'arrivalInformation': {}}} + ) + + +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': {}, + 'arrivalInformation': {}}} + ) + + def test_schedule_flights_get(client_setup): client_setup.schedule.flights.get(a='b') client_setup.get.assert_called_with( From a42eba1c5144d79614ad68e5f48124e34de34cd6 Mon Sep 17 00:00:00 2001 From: minjikarin Date: Mon, 17 Jun 2024 10:51:02 +0200 Subject: [PATCH 2/4] modified example --- README.rst | 13 +++++++++---- amadeus/booking/_hotel_orders.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 51f7f045..316e79b9 100644 --- a/README.rst +++ b/README.rst @@ -275,12 +275,17 @@ List of supported endpoints # Hotel Name Autocomplete amadeus.reference_data.locations.hotel.get(keyword='PARI', subType=[Hotel.HOTEL_GDS, Hotel.HOTEL_LEISURE]) - # Hotel Booking + # Hotel Booking V2 # The offerId comes from the hotel_offer above - amadeus.booking.hotel_bookings.post(offerId, guests, payments) + response = amadeus.booking.hotel_orders.post( + guests=guests, + travel_agent=travel_agent, + room_associations=room_associations, + payment=payment) - # Hotel Orders - amadeus.booking.hotel_orders.post(guests=guests, travel_agent=travel_agent) + # Hotel Booking V1 + # The offerId comes from the hotel_offer above + amadeus.booking.hotel_bookings.post(offerId, guests, payments) # Hotel Ratings # What travelers think about this hotel? diff --git a/amadeus/booking/_hotel_orders.py b/amadeus/booking/_hotel_orders.py index 7dd3507e..8e4aa168 100644 --- a/amadeus/booking/_hotel_orders.py +++ b/amadeus/booking/_hotel_orders.py @@ -9,7 +9,7 @@ def post(self, payment={}, arrival_information={}): ''' - Create Hotel Order + Book hotel(s) via Hotel Booking API V2 .. code-block:: python From d996d0969f936a97c7d695608833a5435b22bc79 Mon Sep 17 00:00:00 2001 From: minjikarin Date: Mon, 17 Jun 2024 10:52:13 +0200 Subject: [PATCH 3/4] typo in readme --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 316e79b9..db8340fe 100644 --- a/README.rst +++ b/README.rst @@ -277,7 +277,7 @@ List of supported endpoints # Hotel Booking V2 # The offerId comes from the hotel_offer above - response = amadeus.booking.hotel_orders.post( + amadeus.booking.hotel_orders.post( guests=guests, travel_agent=travel_agent, room_associations=room_associations, From 42642571149627bfdbd39c3d7c6666ee09de8ef2 Mon Sep 17 00:00:00 2001 From: Siddhartha Dutta Date: Mon, 17 Jun 2024 16:45:17 +0530 Subject: [PATCH 4/4] Update README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index db8340fe..0c1d78a6 100644 --- a/README.rst +++ b/README.rst @@ -275,7 +275,7 @@ List of supported endpoints # Hotel Name Autocomplete amadeus.reference_data.locations.hotel.get(keyword='PARI', subType=[Hotel.HOTEL_GDS, Hotel.HOTEL_LEISURE]) - # Hotel Booking V2 + # Hotel Booking v2 # The offerId comes from the hotel_offer above amadeus.booking.hotel_orders.post( guests=guests, @@ -283,7 +283,7 @@ List of supported endpoints room_associations=room_associations, payment=payment) - # Hotel Booking V1 + # Hotel Booking v1 # The offerId comes from the hotel_offer above amadeus.booking.hotel_bookings.post(offerId, guests, payments)