Skip to content

Commit a397178

Browse files
authored
Merge pull request #104 from amadeus4dev/tours-activities-support
Add support for Tours and Activities API
2 parents ae11f15 + 038351c commit a397178

9 files changed

Lines changed: 138 additions & 1 deletion

File tree

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ List of supported endpoints
316316
# Retrieve status of a given flight
317317
amadeus.schedule.flights.get(carrierCode='AZ', flightNumber='319', scheduledDepartureDate='2021-03-13')
318318
319+
# Tours and Activities
320+
# What are the popular activities in Madrid (based a geo location and a radius)
321+
amadeus.shopping.activities.get(latitude=40.41436995, longitude=-3.69170868)
322+
# What are the popular activities in Barcelona? (based on a square)
323+
amadeus.shopping.activities.by_square.get(north=41.397158, west=2.160873,
324+
south=41.394582, east=2.177181)
325+
# Returns a single activity from a given id
326+
amadeus.shopping.activity('4615').get()
327+
319328
Development & Contributing
320329
--------------------------
321330

amadeus/namespaces/_shopping.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from amadeus.shopping._hotel_offers_by_hotel import HotelOffersByHotel
88
from amadeus.shopping._hotel_offer import HotelOffer
99
from amadeus.shopping._seatmaps import Seatmaps
10+
from amadeus.shopping._activities import Activities
11+
from amadeus.shopping._activity import Activity
1012

1113

1214
class Shopping(Decorator, object):
@@ -19,10 +21,14 @@ def __init__(self, client):
1921
self.hotel_offers_by_hotel = HotelOffersByHotel(client)
2022
self.flight_offers_search = FlightOffersSearch(client)
2123
self.seatmaps = Seatmaps(client)
24+
self.activities = Activities(client)
2225

2326
def hotel_offer(self, offer_id):
2427
return HotelOffer(self.client, offer_id)
2528

29+
def activity(self, activity_id):
30+
return Activity(self.client, activity_id)
31+
2632

2733
__all__ = ['FlightDates', 'FlightDestinations', 'FlightOffers',
2834
'FlightOffersSearch']

amadeus/shopping/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from ._hotel_offers import HotelOffers
66
from ._hotel_offers_by_hotel import HotelOffersByHotel
77
from ._hotel_offer import HotelOffer
8+
from ._activities import Activities
89

910
__all__ = ['FlightOffers', 'FlightDates',
1011
'FlightDestinations', 'FlightOffersSearch',
11-
'HotelOffers', 'HotelOffersByHotel', 'HotelOffer']
12+
'HotelOffers', 'HotelOffersByHotel',
13+
'HotelOffer', 'Activities']

amadeus/shopping/_activities.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from amadeus.client.decorator import Decorator
2+
from amadeus.shopping.activities._by_square \
3+
import BySquare
4+
5+
6+
class Activities(Decorator, object):
7+
def __init__(self, client):
8+
Decorator.__init__(self, client)
9+
self.by_square = BySquare(client)
10+
11+
def get(self, **params):
12+
'''
13+
Returns activities for a given location
14+
15+
.. code-block:: python
16+
17+
18+
client.shopping.activities.get(
19+
longitude=2.160873,
20+
latitude=41.397158
21+
)
22+
23+
:param latitude: latitude of geographic location to search around.
24+
For example: ``41.397158``
25+
:param longitude: longitude of geographic location to search around.
26+
For example: ``2.160873``
27+
28+
:rtype: amadeus.Response
29+
:raises amadeus.ResponseError: if the request could not be completed
30+
'''
31+
return self.client.get(
32+
'/v1/shopping/activities', **params)

amadeus/shopping/_activity.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from amadeus.client.decorator import Decorator
2+
3+
4+
class Activity(Decorator, object):
5+
def __init__(self, client, activity_id):
6+
Decorator.__init__(self, client)
7+
self.activity_id = activity_id
8+
9+
def get(self, **params):
10+
'''
11+
Returns a single activity from a given id.
12+
13+
.. code-block:: python
14+
15+
client.shopping.activities('4615').get()
16+
17+
:rtype: amadeus.Response
18+
:raises amadeus.ResponseError: if the request could not be completed
19+
'''
20+
return self.client.get('/v1/shopping/activities/{0}'
21+
.format(self.activity_id), **params)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from ._by_square import BySquare
2+
__all__ = ['BySquare']
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 BySquare(Decorator, object):
5+
def get(self, **params):
6+
'''
7+
Returns a list of activities
8+
around a defined square (4 points).
9+
10+
.. code-block:: python
11+
12+
13+
client.shopping.activities.by_square.get(
14+
north=41.397158,
15+
west=2.160873,
16+
south=41.394582,
17+
east=2.177181
18+
)
19+
20+
:param north: latitude north of bounding box.
21+
For example: ``41.397158``
22+
:param west: longitude west of bounding box.
23+
For example: ``2.160873``
24+
:param south: latitude south of bounding box.
25+
For example: ``41.394582``
26+
:param east: longitude east of bounding box.
27+
For example: ``2.177181``
28+
29+
:rtype: amadeus.Response
30+
:raises amadeus.ResponseError: if the request could not be completed
31+
'''
32+
return self.client.get(
33+
'/v1/shopping/activities/by-square', **params)

docs/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ Shopping/FlightOffers
6868
.. autoclass:: amadeus.shopping.FlightOffersPrice
6969
:members: post
7070

71+
Shopping/Activities
72+
===============
73+
74+
.. autoclass:: amadeus.shopping.Activities
75+
:members: get
76+
77+
.. autoclass:: amadeus.shopping.activities.BySquare
78+
:members: get
79+
80+
.. autoclass:: amadeus.shopping.Activity
81+
:members: get
82+
7183
Travel/Analytics
7284
================
7385

specs/namespaces/namespaces_spec.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
expect(client.shopping.hotel_offer).not_to(be_none)
4949
expect(client.shopping.hotel_offers_by_hotel).not_to(be_none)
5050

51+
expect(client.shopping.activities).not_to(be_none)
52+
5153
expect(client.e_reputation.hotel_sentiments).not_to(be_none)
5254

5355
expect(client.airport).not_to(be_none)
@@ -438,3 +440,21 @@
438440
expect(self.client.get).to(have_been_called_with(
439441
'/v2/schedule/flights', a='b'
440442
))
443+
with it('.shopping.activities.get'):
444+
self.client.shopping.activities.get(a='b')
445+
expect(self.client.get).to(have_been_called_with(
446+
'/v1/shopping/activities', a='b'
447+
))
448+
449+
with it('.shopping.activities.by_square.get'):
450+
self.client.shopping.activities.by_square.get(
451+
a='b')
452+
expect(self.client.get).to(have_been_called_with(
453+
'/v1/shopping/activities/by-square', a='b'
454+
))
455+
456+
with it('.shopping.activity().get'):
457+
self.client.shopping.activity('XXX').get(a='b')
458+
expect(self.client.get).to(have_been_called_with(
459+
'/v1/shopping/activities/XXX', a='b'
460+
))

0 commit comments

Comments
 (0)