Skip to content

Commit 56a9522

Browse files
authored
Merge pull request #155 from siddydutta/hotel-name-autocomplete
Add Support of Hotel Name Autocomplete API
2 parents 7e8b399 + 69be55f commit 56a9522

File tree

8 files changed

+71
-2
lines changed

8 files changed

+71
-2
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ List of supported endpoints
277277
# Get list of hotels by a geocode
278278
amadeus.reference_data.locations.hotels.by_geocode.get(longitude=2.160873,latitude=41.397158)
279279
280+
# Hotel Name Autocomplete
281+
amadeus.reference_data.locations.hotel.get(keyword='PARI', subType=[Hotel.HOTEL_GDS, Hotel.HOTEL_LEISURE])
282+
280283
# Hotel Booking
281284
# The offerId comes from the hotel_offer above
282285
amadeus.booking.hotel_bookings.post(offerId, guests, payments)

amadeus/client/hotel.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
class Hotel(object):
3+
'''
4+
A list of hotel sub types, as used in Hotel Name Autocomplete
5+
6+
.. code-block:: python
7+
8+
9+
from amadeus import Hotel
10+
11+
amadeus.reference_data.locations.hotel.get(
12+
keyword='PARI',
13+
subType=[Hotel.HOTEL_LEISURE, Hotel.HOTEL_GDS]
14+
)
15+
16+
:cvar HOTEL_LEISURE: ``"HOTEL_LEISURE"``
17+
:cvar HOTEL_GDS: ``"HOTEL_GDS"``
18+
'''
19+
# Hotel Leisure
20+
HOTEL_LEISURE = 'HOTEL_LEISURE'
21+
# Hotel GDS
22+
HOTEL_GDS = 'HOTEL_GDS'

amadeus/client/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __port_matches_scheme(self):
138138

139139
# Helper method to prepare the parameter encoding
140140
def _urlencode(self, d):
141-
return urlencode(self._flatten_keys(d, '', {}))
141+
return urlencode(self._flatten_keys(d, '', {}), doseq=True)
142142

143143
# Flattens the hash keys, so page: { offset: 1 } becomes page[offet] = 1
144144
def _flatten_keys(self, d, key, out):

amadeus/reference_data/_locations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from amadeus.reference_data.locations._points_of_interest import PointsOfInterest
44
from amadeus.reference_data.locations._point_of_interest import PointOfInterest
55
from amadeus.reference_data.locations._hotels import Hotels
6+
from amadeus.reference_data.locations._hotel import Hotel
67

78

89
class Locations(Decorator, object):
@@ -11,6 +12,7 @@ def __init__(self, client):
1112
self.airports = Airports(client)
1213
self.points_of_interest = PointsOfInterest(client)
1314
self.hotels = Hotels(client)
15+
self.hotel = Hotel(client)
1416

1517
def point_of_interest(self, poi_id):
1618
return PointOfInterest(self.client, poi_id)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from ._airports import Airports
22
from ._points_of_interest import PointsOfInterest
3-
__all__ = ['Airports', 'PointsOfInterest']
3+
from ._hotel import Hotel
4+
5+
__all__ = ['Airports', 'PointsOfInterest', 'Hotel']
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from amadeus.client.decorator import Decorator
2+
3+
4+
class Hotel(Decorator, object):
5+
def get(self, **params):
6+
'''
7+
Returns a list of hotels matching a given keyword.
8+
9+
.. code-block:: python
10+
11+
12+
amadeus.reference_data.locations.hotel.get(
13+
keyword='PARI',
14+
subType=[Hotel.HOTEL_LEISURE, Hotel.HOTEL_GDS]
15+
)
16+
17+
:param keyword: location query keyword.
18+
For example: ``PARI``
19+
:param subType: category of search.
20+
For example: ``[Hotel.HOTEL_LEISURE, Hotel.HOTEL_GDS]``
21+
22+
:rtype: amadeus.Response
23+
:raises amadeus.ResponseError: if the request could not be completed
24+
'''
25+
return self.client.get(
26+
'/v1/reference-data/locations/hotel', **params)

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ ReferenceData/Locations/Hotels
179179
.. autoclass:: amadeus.reference_data.hotels.ByGeocode
180180
:members: get
181181

182+
ReferenceData/Locations/Hotel
183+
=======================
184+
185+
.. autoclass:: amadeus.reference_data.locations.Hotel
186+
:members: get
187+
182188
Helper/Location
183189
==================
184190

specs/namespaces/namespaces_spec.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
expect(client.reference_data.locations.hotels.by_hotels).not_to(be_none)
2929
expect(client.reference_data.locations.hotels.by_city).not_to(be_none)
3030
expect(client.reference_data.locations.hotels.by_geocode).not_to(be_none)
31+
expect(client.reference_data.locations.hotel).not_to(be_none)
3132
expect(client.travel).not_to(be_none)
3233
expect(client.travel.analytics).not_to(be_none)
3334
expect(client.travel.analytics.air_traffic.traveled).not_to(be_none)
@@ -114,6 +115,7 @@
114115
client.reference_data.locations.hotels.by_hotels.get).not_to(be_none)
115116
expect(
116117
client.reference_data.locations.hotels.by_geocode.get).not_to(be_none)
118+
expect(client.reference_data.locations.hotel.get).not_to(be_none)
117119
expect(client.travel.analytics.air_traffic.traveled.get).not_to(be_none)
118120
expect(client.travel.analytics.air_traffic.booked.get).not_to(be_none)
119121
expect(
@@ -555,3 +557,9 @@
555557
expect(self.client.get).to(have_been_called_with(
556558
'/v1/reference-data/locations/hotels/by-geocode', a='b'
557559
))
560+
561+
with it('.reference_data.locations.hotel.get'):
562+
self.client.reference_data.locations.hotel.get(a='b')
563+
expect(self.client.get).to(have_been_called_with(
564+
'/v1/reference-data/locations/hotel', a='b'
565+
))

0 commit comments

Comments
 (0)