Skip to content

Commit 6dc0a23

Browse files
authored
Merge pull request #93 from amadeus4dev/safe-place
Add support for Safe Place
2 parents 568728a + bdc1675 commit 6dc0a23

File tree

10 files changed

+156
-2
lines changed

10 files changed

+156
-2
lines changed

README.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,20 @@ List of supported endpoints
271271
# What are the popular places in Barcelona (based a geo location and a radius)
272272
amadeus.reference_data.locations.points_of_interest.get(latitude=41.397158, longitude=2.160873)
273273
# What are the popular places in Barcelona? (based on a square)
274-
amadeus.reference_data.locations.points_of_interest.by_square.get(north=41.397158, west=2.160873, south=41.394582, east=2.177181)
274+
amadeus.reference_data.locations.points_of_interest.by_square.get(north=41.397158, west=2.160873,
275+
south=41.394582, east=2.177181)
275276
# Returns a single Point of Interest from a given id
276277
amadeus.reference_data.locations.point_of_interest('9CB40CB5D0').get()
277278
279+
# Safe Place
280+
# How safe is Barcelona? (based a geo location and a radius)
281+
amadeus.safety.safety_rated_locations.get(latitude=41.397158, longitude=2.160873)
282+
# How safe is Barcelona? (based on a square)
283+
amadeus.safety.safety_rated_locations.by_square.get(north=41.397158, west=2.160873,
284+
south=41.394582, east=2.177181)
285+
# What is the safety information of a location based on it's Id?
286+
amadeus.safety.safety_rated_location('Q930400801').get()
287+
278288
# Trip Purpose Prediction
279289
amadeus.travel.predictions.trip_purpose.get(originLocationCode='ATH', destinationLocationCode='MAD', departureDate='2020-08-01', returnDate='2020-08-12', searchDate='2020-06-11')
280290

amadeus/namespaces/_safety.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from amadeus.client.decorator import Decorator
2+
from amadeus.safety._safety_rated_locations import SafetyRatedLocations
3+
from amadeus.safety._safety_rated_location import SafetyRatedLocation
4+
5+
6+
class Safety(Decorator, object):
7+
def __init__(self, client):
8+
Decorator.__init__(self, client)
9+
self.safety_rated_locations = SafetyRatedLocations(client)
10+
11+
def safety_rated_location(self, safety_id):
12+
return SafetyRatedLocation(self.client, safety_id)

amadeus/namespaces/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from amadeus.namespaces._airport import Airport
66
from amadeus.namespaces._media import Media
77
from amadeus.namespaces._booking import Booking
8+
from amadeus.namespaces._safety import Safety
89

910

1011
class Core(object):
@@ -16,3 +17,4 @@ def __init__(self):
1617
self.airport = Airport(self)
1718
self.media = Media(self)
1819
self.booking = Booking(self)
20+
self.safety = Safety(self)

amadeus/safety/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from ._safety_rated_locations import SafetyRatedLocations
2+
from ._safety_rated_location import SafetyRatedLocation
3+
4+
__all__ = ['SafetyRatedLocations', 'SafetyRatedLocation']
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 SafetyRatedLocation(Decorator, object):
5+
def __init__(self, client, safety_id):
6+
Decorator.__init__(self, client)
7+
self.safety_id = safety_id
8+
9+
def get(self, **params):
10+
'''
11+
Returns safety information of a location by its Id.
12+
13+
.. code-block:: python
14+
15+
amadeus.safety.safety_rated_location('Q930400801').get()
16+
17+
:rtype: amadeus.Response
18+
:raises amadeus.ResponseError: if the request could not be completed
19+
'''
20+
return self.client.get('/v1/safety/safety-rated-locations/{0}'
21+
.format(self.safety_id), **params)
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.safety.safety_rated_locations._by_square import BySquare
3+
4+
5+
class SafetyRatedLocations(Decorator, object):
6+
def __init__(self, client):
7+
Decorator.__init__(self, client)
8+
self.by_square = BySquare(client)
9+
10+
def get(self, **params):
11+
'''
12+
Returns the overall safety ranking and a detailed safety
13+
ranking of all the districts within the given radius.
14+
15+
.. code-block:: python
16+
17+
18+
amadeus.safety.safety_rated_locations.get(
19+
longitude=2.160873,
20+
latitude=41.397158
21+
)
22+
23+
:param latitude: latitude of the location to safety ranking search.
24+
For example: ``41.397158``
25+
:param longitude: longitude of the location to safety ranking search.
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/safety/safety-rated-locations', **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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from amadeus.client.decorator import Decorator
2+
3+
4+
class BySquare(Decorator, object):
5+
def get(self, **params):
6+
'''
7+
Returns detailed safety ranking of all the districts
8+
within the designated area.
9+
10+
.. code-block:: python
11+
12+
amadeus.safety.safety_rated_locations.by_square.get(
13+
north=41.397158,
14+
west=2.160873,
15+
south=41.394582,
16+
east=2.177181
17+
)
18+
19+
:param north: latitude north of bounding box.
20+
For example: ``41.397158``
21+
:param west: longitude west of bounding box.
22+
For example: ``2.160873``
23+
:param south: latitude south of bounding box.
24+
For example: ``41.394582``
25+
:param east: longitude east of bounding box.
26+
For example: ``2.177181``
27+
28+
:rtype: amadeus.Response
29+
:raises amadeus.ResponseError: if the request could not be completed
30+
'''
31+
return self.client.get(
32+
'/v1/safety/safety-rated-locations/by-square', **params)

docs/index.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,16 @@ Booking
161161
:members: delete
162162

163163
.. autoclass:: amadeus.booking.HotelBookings
164-
:members: post
164+
:members: post
165+
166+
Safety/SafetyRatedLocations
167+
=======================
168+
169+
.. autoclass:: amadeus.safety.SafetyRatedLocations
170+
:members: get
171+
172+
.. autoclass:: amadeus.safety.safety_rated_locations.BySquare
173+
:members: get
174+
175+
.. autoclass:: amadeus.safety.safety_rated_locations.SafetyRatedLocation
176+
:members: get

specs/namespaces/namespaces_spec.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
expect(client.booking.flight_orders).not_to(be_none)
6969
expect(client.booking.flight_order).not_to(be_none)
7070

71+
expect(client.safety.safety_rated_locations).not_to(be_none)
72+
expect(client.safety.safety_rated_locations.by_square).not_to(be_none)
73+
expect(client.safety.safety_rated_location).not_to(be_none)
74+
7175
with it('should define all expected .get methods'):
7276
client = self.client
7377
expect(client.reference_data.urls.checkin_links.get).not_to(be_none)
@@ -114,6 +118,10 @@
114118
expect(client.booking.flight_order('123').get).not_to(be_none)
115119
expect(client.booking.flight_order('123').delete).not_to(be_none)
116120

121+
expect(client.safety.safety_rated_locations.by_square.get).not_to(be_none)
122+
expect(client.safety.safety_rated_location('Q930402719').get).not_to(
123+
be_none)
124+
117125
with it('should define all expected .delete methods'):
118126
client = self.client
119127
expect(client.booking.flight_order('123').delete).not_to(be_none)
@@ -393,3 +401,22 @@
393401
'payments': [{'bar': 'foo'}]
394402
}}
395403
))
404+
405+
with it('.safety.safety_rated_locations.get'):
406+
self.client.safety.safety_rated_locations.get(a='b')
407+
expect(self.client.get).to(have_been_called_with(
408+
'/v1/safety/safety-rated-locations', a='b'
409+
))
410+
411+
with it('.safety.safety_rated_locations.by_square.get'):
412+
self.client.safety.safety_rated_locations.by_square.get(
413+
a='b')
414+
expect(self.client.get).to(have_been_called_with(
415+
'/v1/safety/safety-rated-locations/by-square', a='b'
416+
))
417+
418+
with it('.safety.safety_rated_location().get'):
419+
self.client.safety.safety_rated_location('XXX').get(a='b')
420+
expect(self.client.get).to(have_been_called_with(
421+
'/v1/safety/safety-rated-locations/XXX', a='b'
422+
))

0 commit comments

Comments
 (0)