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

Add Support for Hotel Booking V2 #212

Merged
merged 4 commits into from
Jun 18, 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
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,15 @@ 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
siddydutta marked this conversation as resolved.
Show resolved Hide resolved
# The offerId comes from the hotel_offer above
amadeus.booking.hotel_orders.post(
guests=guests,
travel_agent=travel_agent,
room_associations=room_associations,
payment=payment)

# Hotel Booking V1
siddydutta marked this conversation as resolved.
Show resolved Hide resolved
# The offerId comes from the hotel_offer above
amadeus.booking.hotel_bookings.post(offerId, guests, payments)

Expand Down
3 changes: 2 additions & 1 deletion amadeus/booking/__init__.py
Original file line number Diff line number Diff line change
@@ -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']
45 changes: 45 additions & 0 deletions amadeus/booking/_hotel_orders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from amadeus.client.decorator import Decorator


class HotelOrders(Decorator, object):
def post(self,
tsolakoua marked this conversation as resolved.
Show resolved Hide resolved
guests,
travel_agent,
room_associations=[],
payment={},
arrival_information={}):
'''
Book hotel(s) via Hotel Booking API V2

.. 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)
4 changes: 3 additions & 1 deletion amadeus/namespaces/_booking.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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']
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ Booking
.. autoclass:: amadeus.booking.HotelBookings
:members: post

.. autoclass:: amadeus.booking.HotelOrders
:members: post


Schedule/Flights
================

Expand Down
30 changes: 30 additions & 0 deletions specs/namespaces/test_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading