Skip to content

Commit

Permalink
Add Support for Hotel Booking V2
Browse files Browse the repository at this point in the history
  • Loading branch information
siddydutta committed Jun 13, 2024
1 parent 314395f commit 21d1fa8
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')
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,
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)
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
28 changes: 28 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,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(
Expand Down

0 comments on commit 21d1fa8

Please sign in to comment.