Skip to content

Commit 10fddd5

Browse files
authored
Add support for Safe Place API (#51)
Add support for Safe Place API and for the last endpoint of Points of Interest
1 parent 990e611 commit 10fddd5

File tree

15 files changed

+413
-3
lines changed

15 files changed

+413
-3
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,22 @@ amadeus.booking.hotel_bookings.post(offerId, guests, payments)
213213
# What are the reviews for the Holiday INN Manhattan and the Hilton London Paddington
214214
amadeus.e_reputation.hotel_sentiments.get(hotelIds: 'SJNYCAJA,TELONMFS')
215215

216-
# Point of Interest
216+
# Points of Interest
217217
# What are the popular places in Barcelona (based a geo location and a radius)
218218
amadeus.reference_data.locations.points_of_interest.get(latitude: 41.397158, longitude: 2.160873)
219219
# What are the popular places in Barcelona? (based on a square)
220220
amadeus.reference_data.locations.points_of_interest.by_square.get(north: 41.397158, west: 2.160873, south: 41.394582, east: 2.177181)
221+
# Returns a single Point of Interest from a given id
222+
amadeus.reference_data.locations.point_of_interest('9CB40CB5D0').get()
223+
224+
225+
# Safe Place
226+
# How safe is Barcelona? (based a geo location and a radius)
227+
amadeus.safety.safety_rated_locations.get(latitude: 41.397158, longitude: 2.160873)
228+
# How safe is Barcelona? (based on a square)
229+
amadeus.safety.safety_rated_locations.by_square.get(north: 41.397158, west: 2.160873, south: 41.394582, east: 2.177181)
230+
# What is the safety information of a location based on it's Id?
231+
amadeus.safety.safety_rated_location('Q930402753').get()
221232

222233
# Airport On-Time Performance
223234
amadeus.airport.predictions.on_time.get(airportCode: 'JFK', date: '2020-08-01')

lib/amadeus.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
require 'amadeus/namespaces/e_reputation'
1616
require 'amadeus/namespaces/booking'
1717
require 'amadeus/namespaces/airport'
18+
require 'amadeus/namespaces/safety'
1819
require 'amadeus/namespaces/airport/predictions'
1920
require 'amadeus/namespaces/airport/predictions/on_time'
2021
require 'amadeus/namespaces/e_reputation/hotel_sentiments'
@@ -25,8 +26,12 @@
2526
require 'amadeus/namespaces/reference_data/location'
2627
require 'amadeus/namespaces/reference_data/locations'
2728
require 'amadeus/namespaces/reference_data/locations/airports'
29+
require 'amadeus/namespaces/reference_data/locations/point_of_interest'
2830
require 'amadeus/namespaces/reference_data/locations/points_of_interest'
2931
require 'amadeus/namespaces/reference_data/locations/points_of_interest/by_square'
32+
require 'amadeus/namespaces/safety/safety_rated_location'
33+
require 'amadeus/namespaces/safety/safety_rated_locations'
34+
require 'amadeus/namespaces/safety/safety_rated_locations/by_square'
3035
require 'amadeus/namespaces/shopping/flight_destinations'
3136
require 'amadeus/namespaces/shopping/flight_offers_search'
3237
require 'amadeus/namespaces/shopping/flight_offers_search/prediction'

lib/amadeus/namespaces/core.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,15 @@ def e_reputation
7777
def airport
7878
Airport.new(self)
7979
end
80+
81+
# The namespace for the Safety related APIs:
82+
#
83+
# @return [Amadeus::Namespaces::Safety]
84+
# @example Some of the further namespaces available
85+
# amadeus.safety.safety_rated_locations
86+
#
87+
def safety
88+
Safety.new(self)
89+
end
8090
end
8191
end

lib/amadeus/namespaces/reference_data/locations.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def airports
2222
Amadeus::Namespaces::ReferenceData::Locations::Airports.new(client)
2323
end
2424

25-
# The namespace for the Point Of Interest API:
25+
# The namespace for the Points Of Interest API:
2626
#
2727
# @return [Amadeus::Namespaces::ReferenceData::Locations::PointsOfInterest]
2828
# @example
@@ -32,6 +32,18 @@ def points_of_interest
3232
Amadeus::Namespaces::ReferenceData::Locations::PointsOfInterest.new(client)
3333
end
3434

35+
# The namespace for the Point Of Interest API:
36+
#
37+
# @return [Amadeus::Namespaces::ReferenceData::Locations::PointOfInterest]
38+
# @example
39+
# amadeus.reference_data.locations.point_of_interest
40+
#
41+
def point_of_interest(location_id)
42+
Amadeus::Namespaces::ReferenceData::Locations::PointOfInterest.new(
43+
client, location_id
44+
)
45+
end
46+
3547
# Returns a list of airports and cities matching a given keyword.
3648
#
3749
# @option params [String] :keyword keyword that should represent the
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
module Amadeus
4+
module Namespaces
5+
class ReferenceData
6+
class Locations
7+
# A namespaced client for the
8+
# +/v1/reference-data/locations/pois/:location_id+ endpoints
9+
#
10+
# Access via the +Amadeus::Client+ object
11+
#
12+
# amadeus = Amadeus::Client.new
13+
# amadeus.reference_data.locations.point_of_interest('9CB40CB5D0')
14+
#
15+
class PointOfInterest < Amadeus::Client::Decorator
16+
# the Location ID
17+
attr_reader :poi_location_id
18+
19+
# Initialize this namespaced client with an
20+
# {Amadeus::Client} instance and an optional Location ID
21+
#
22+
# @param [Amadeus::Client] client
23+
# @param [Number] poi_location_id
24+
#
25+
def initialize(client, poi_location_id = nil)
26+
super(client)
27+
@poi_location_id = poi_location_id
28+
end
29+
30+
# Returns details for a specific poi
31+
#
32+
# @return [Amadeus::Response] a parsed response
33+
# @raise [Amadeus::Base] an exception if the call failed
34+
# @example Retrieve poi information of '9CB40CB5D0'
35+
# amadeus.reference_data.locations.point_of_interest('9CB40CB5D0').get
36+
#
37+
def get(params = {})
38+
client.get("/v1/reference-data/locations/pois/#{@poi_location_id}", params)
39+
end
40+
end
41+
end
42+
end
43+
end
44+
end

lib/amadeus/namespaces/safety.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
module Amadeus
4+
module Namespaces
5+
# A namespaced client for the
6+
# +/v1/safety+ endpoints
7+
#
8+
# Access via the +Amadeus::Client+ object
9+
#
10+
# amadeus = Amadeus::Client.new
11+
# amadeus.safety
12+
#
13+
class Safety < Amadeus::Client::Decorator
14+
# The namespace for the Safety APIs:
15+
#
16+
# @return [Amadeus::Namespaces::Safety::SafetyRetedLocations]
17+
# @example
18+
# amadeus.safety.safety_rated_locations
19+
#
20+
def safety_rated_locations
21+
Amadeus::Namespaces::Safety::SafetyRatedLocations.new(client)
22+
end
23+
24+
#
25+
# @return [Amadeus::Namespaces::Safety::SafetyRetedLocation]
26+
# @example
27+
# amadeus.safety.safety_rated_location
28+
#
29+
def safety_rated_location(location_id)
30+
Amadeus::Namespaces::Safety::SafetyRatedLocation.new(client, location_id)
31+
end
32+
end
33+
end
34+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
module Amadeus
4+
module Namespaces
5+
class Safety
6+
# amadeus.safety.safety_rated_location('Q930400801').get()
7+
class SafetyRatedLocation < Amadeus::Client::Decorator
8+
attr_reader :safe_location_id
9+
10+
#
11+
# @param [Amadeus::Client] client
12+
# @param [Number] safe_location_id
13+
#
14+
def initialize(client, safe_location_id = nil)
15+
super(client)
16+
@safe_location_id = safe_location_id
17+
end
18+
19+
# Returns details for a specific place
20+
#
21+
# @return [Amadeus::Response] a parsed response
22+
# @raise [Amadeus::Base] an exception if the call failed
23+
# @example Retrieve safety information of 'Q930402753'
24+
# amadeus.safety.safety_rated_location('Q930402753').get
25+
#
26+
def get(params = {})
27+
client.get("/v1/safety/safety-rated-locations/#{@safe_location_id}", params)
28+
end
29+
end
30+
end
31+
end
32+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
module Amadeus
4+
module Namespaces
5+
class Safety
6+
# A namespaced client for the
7+
# +/v1/safety/safety_rated_locations/+ endpoints
8+
#
9+
# Access via the +Amadeus::Client+ object
10+
#
11+
# amadeus = Amadeus::Client.new
12+
# amadeus.safety.safety_rated_locations
13+
#
14+
class SafetyRatedLocations < Amadeus::Client::Decorator
15+
# The namespace for the Safe Place API:
16+
#
17+
# @return [Amadeus::Namespaces::Safety::SafetyRatedLocations]
18+
# @example
19+
# amadeus.safety.safety_rated_locations.by_square
20+
#
21+
def by_square
22+
Amadeus::Namespaces::Safety::SafetyRatedLocations::BySquare.new(client)
23+
end
24+
25+
# Returns a list of relevant safety information near to a given point.
26+
#
27+
# @option params [Double] :latitude latitude location to be at the
28+
# center of the search circle - required
29+
# @option params [Double] :longitude longitude location to be at the
30+
# center of the search circle - required
31+
# @return [Amadeus::Response] a parsed response
32+
# @raise [Amadeus::Base] an exception if the call
33+
# failed
34+
# @example What are the different safety information in Barcelona
35+
# amadeus.safety.safety_rated_locations.get(
36+
# latitude: 41.397158,
37+
# longitude: 2.160873
38+
# )
39+
#
40+
def get(params = {})
41+
client.get('/v1/safety/safety-rated-locations', params)
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
module Amadeus
4+
module Namespaces
5+
class Safety
6+
class SafetyRatedLocations
7+
# A namespaced client for the
8+
# +/v1/safety/safety_rated_locations/by-square+ endpoints
9+
#
10+
# Access via the +Amadeus::Client+ object
11+
#
12+
# amadeus = Amadeus::Client.new
13+
# amadeus.safety.safety_rated_locations.by_square
14+
#
15+
class BySquare < Amadeus::Client::Decorator
16+
# Returns a list of relevant safety information
17+
# around a defined square (4 points).
18+
#
19+
# @option params [Double] :north Latitude north of bounding box - required
20+
# @option params [Double] :west Longitude west of bounding box - required
21+
# @option params [Double] :south Latitude south of bounding box - required
22+
# @option params [Double] :east Longitude east of bounding box - required
23+
# @return [Amadeus::Response] a parsed response
24+
# @raise [Amadeus::Base] an exception if the call
25+
# failed
26+
# @example How safe is Barcelona?
27+
# amadeus.safety.safety_rated_locations.by_square.get(
28+
# north: 41.397158,
29+
# west: 2.160873,
30+
# south: 41.394582,
31+
# east: 2.177181
32+
# )
33+
#
34+
def get(params = {})
35+
client.get('/v1/safety/safety-rated-locations/by-square', params)
36+
end
37+
end
38+
end
39+
end
40+
end
41+
end

spec/namespaces/namespaces_spec.rb

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
end
7474
end
7575

76-
describe '.reference_data.locations..points_of_interest.by_square' do
76+
describe '.reference_data.locations.points_of_interest.by_square' do
7777
it 'should return a PointsOfInterest::BySquare object' do
7878
expect(@amadeus.reference_data.locations.points_of_interest.by_square).to(
7979
be_instance_of(
@@ -83,6 +83,46 @@
8383
end
8484
end
8585

86+
describe '.reference_data.locations.point_of_interest' do
87+
it 'should return a PointOfInterest object' do
88+
expect(@amadeus.reference_data.locations.point_of_interest('9CB40CB5D0')).to(
89+
be_instance_of Amadeus::Namespaces::ReferenceData::Locations::PointOfInterest
90+
)
91+
end
92+
end
93+
94+
describe '.shopping' do
95+
it 'should return a Safety object' do
96+
expect(@amadeus.safety).to(
97+
be_instance_of Amadeus::Namespaces::Safety
98+
)
99+
end
100+
end
101+
102+
describe '.safety.safety_rated_locations' do
103+
it 'should return a SafetyRatedLocations object' do
104+
expect(@amadeus.safety.safety_rated_locations).to(
105+
be_instance_of Amadeus::Namespaces::Safety::SafetyRatedLocations
106+
)
107+
end
108+
end
109+
110+
describe '.safety.safety_rated_location' do
111+
it 'should return a SafetyRatedLocation object' do
112+
expect(@amadeus.safety.safety_rated_location('CXXXX')).to(
113+
be_instance_of Amadeus::Namespaces::Safety::SafetyRatedLocation
114+
)
115+
end
116+
end
117+
118+
describe '.safety.safety_rated_locations.by_square' do
119+
it 'should return a BySquare object' do
120+
expect(@amadeus.safety.safety_rated_locations.by_square).to(
121+
be_instance_of Amadeus::Namespaces::Safety::SafetyRatedLocations::BySquare
122+
)
123+
end
124+
end
125+
86126
describe '.shopping' do
87127
it 'should return a Shopping object' do
88128
expect(@amadeus.shopping).to(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Amadeus::Namespaces::ReferenceData::Locations::PointOfInterest do
6+
before do
7+
@client = double('Amadeus::Client')
8+
@location_id = '9CB40CB5D0'
9+
@api = Amadeus::Namespaces::ReferenceData::Locations::PointOfInterest.new(
10+
@client, @location_id
11+
)
12+
end
13+
14+
describe '.get' do
15+
it 'should call client.get with the right params' do
16+
params = {}
17+
18+
expect(@client).to receive(:get).with(
19+
'/v1/reference-data/locations/pois/9CB40CB5D0', params
20+
)
21+
22+
@api.get(params)
23+
end
24+
25+
it 'should default to an empty hash' do
26+
expect(@client).to receive(:get).with(
27+
'/v1/reference-data/locations/pois/9CB40CB5D0', {}
28+
)
29+
30+
@api.get
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)