Skip to content

Commit b25b792

Browse files
authored
Add Support for Hotel Booking (#67)
* initial commit * update impl and tests * remove extra line from readme * update readme and code samples * update examples * fix offer parameter * remove pragma for coverage * update readme
1 parent 6ecd32f commit b25b792

File tree

7 files changed

+68
-10
lines changed

7 files changed

+68
-10
lines changed

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ List of supported endpoints
266266
# Get list of offers for a specific hotel
267267
amadeus.shopping.hotel_offers_by_hotel.get(hotelId = 'BGLONBGB')
268268
# Confirm the availability of a specific offer
269-
amadeus.shopping.hotel_offer('8123DD9DE5102DADF5DA3B55C8C575F54114336EE718578753888747FE0652FC').get()
269+
offerId = amadeus.shopping.hotel_offer('8123DD9DE5102DADF5DA3B55C8C575F54114336EE718578753888747FE0652FC').get()
270+
271+
# Hotel Booking
272+
# The offerId comes from the hotel_offer above
273+
amadeus.booking.hotel_bookings.post(offerId, guests, payments)
270274
271275
# Hotel Ratings
272276
# What travelers think about this hotel?

amadeus/booking/__init__.py

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

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

amadeus/booking/_hotel_bookings.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from amadeus.client.decorator import Decorator
2+
3+
4+
class HotelBookings(Decorator, object):
5+
def post(self, hotel_offer_id, guests, payments):
6+
'''
7+
Books a hotel
8+
9+
.. code-block:: python
10+
11+
amadeus.booking.hotel_bookings.post(hotel_offer_id, guests, payments)
12+
13+
The parameters guests and payments can be passed as dictionary
14+
or list of dictionaries. If they are dictionary in this method they are
15+
converted to a list of dictionaries.
16+
17+
:rtype: amadeus.Response
18+
:raises amadeus.ResponseError: if the request could not be completed
19+
'''
20+
guests_info = []
21+
payment_info = []
22+
if type(guests) is not list:
23+
guests_info.append(guests)
24+
else:
25+
guests_info.extend(guests)
26+
if type(payments) is not list:
27+
payment_info.append(payments)
28+
else:
29+
payment_info.extend(payments)
30+
body = {'data': {'offerId': hotel_offer_id,
31+
'guests': guests_info,
32+
'payments': payment_info}}
33+
return self.client.post('/v1/booking/hotel-bookings', body)

amadeus/namespaces/_booking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from amadeus.booking._flight_orders import FlightOrders
22
from amadeus.booking._flight_order import FlightOrder
3+
from amadeus.booking._hotel_bookings import HotelBookings
34
from amadeus.client.decorator import Decorator
45

56

67
class Booking(Decorator, object):
78
def __init__(self, client):
89
Decorator.__init__(self, client)
910
self.flight_orders = FlightOrders(client)
11+
self.hotel_bookings = HotelBookings(client)
1012

1113
def flight_order(self, flight_order_id):
1214
return FlightOrder(self.client, flight_order_id)
1315

1416

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

docs/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,7 @@ Booking
146146
:members: post
147147

148148
.. autoclass:: amadeus.booking.FlightOrder
149-
:members: get
149+
:members: get
150+
151+
.. autoclass:: amadeus.booking.HotelBookings
152+
:members: post

examples/hotel_search/hotel_search.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
hotels_by_city = amadeus.shopping.hotel_offers.get(cityCode='LON')
88
# print(hotels_by_city.data)
99
# Get list of offers for a specific hotel
10-
hotel_offers = amadeus.shopping.hotel_offers_by_hotel.get(hotelId = 'BGLONBGB')
10+
hotel_offers = amadeus.shopping.hotel_offers_by_hotel.get(hotelId = 'HSMADAMI')
1111
# print(hotel_offers.data)
1212
# Confirm the availability of a specific offer
13-
# print(hotel_offers.data)
14-
offer_availability = amadeus.shopping.hotel_offer(hotel_offers.data['offers'][0]['id']).get()
13+
offer = hotel_offers.data['offers'][0]['id']
14+
offer_availability = amadeus.shopping.hotel_offer(offer).get()
1515
# print(offer_availability.data)
16-
17-
except ResponseError as error:
18-
raise error
16+
guests = [{'id': 1, 'name': { 'title': 'MR', 'firstName': 'BOB', 'lastName': 'SMITH' }, 'contact': { 'phone': '+33679278416', 'email': '[email protected]'}}]
17+
payments = { 'id': 1, 'method': 'creditCard', 'card': { 'vendorCode': 'VI', 'cardNumber': '4151289722471370', 'expiryDate': '2021-08' } }
18+
hotel_booking = amadeus.booking.hotel_bookings.post(offer, guests, payments)
19+
# print(hotel_booking.data)
20+
except ResponseError:
21+
pass

specs/namespaces/namespaces_spec.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,15 @@
327327
expect(self.client.get).to(have_been_called_with(
328328
'/v1/booking/flight-orders/123', a='b'
329329
))
330+
331+
with it('.shopping.booking.hotel_bookings.post'):
332+
self.client.booking.hotel_bookings.post('123',
333+
{'foo': 'bar'},
334+
{'bar': 'foo'})
335+
expect(self.client.post).to(have_been_called_with(
336+
'/v1/booking/hotel-bookings',
337+
{'data': {'offerId': '123',
338+
'guests': [{'foo': 'bar'}],
339+
'payments': [{'bar': 'foo'}]
340+
}}
341+
))

0 commit comments

Comments
 (0)