Skip to content

Commit 5ab60eb

Browse files
authored
Adding support for Safe Places API
Adding support for Safe Places API
2 parents 4e10a99 + 53404ce commit 5ab60eb

File tree

7 files changed

+201
-0
lines changed

7 files changed

+201
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,21 @@ amadeus.airport.predictions.onTime.get({
425425
airportCode: 'JFK',
426426
date: '2020-08-01'
427427
})
428+
429+
// How safe is Barcelona? (based a geo location and a radius)
430+
amadeus.safety.safetyRatedLocations.get({
431+
latitude: 41.397158,
432+
longitude: 2.160873
433+
})
434+
// How safe is Barcelona? (based on a square)
435+
amadeus.safety.safetyRatedLocations.bySquare.get({
436+
north: 41.397158,
437+
west: 2.160873,
438+
south: 41.394582,
439+
east: 2.177181
440+
})
441+
// What is the safety information of a location based on it's Id?
442+
amadeus.safety.safetyRatedLocation('Q930400801').get()
428443
```
429444

430445
## Development & Contributing

spec/amadeus/namespaces.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ describe('Namespaces', () => {
6868
expect(amadeus.airport).toBeDefined();
6969
expect(amadeus.airport.predictions).toBeDefined();
7070
expect(amadeus.airport.predictions.onTime).toBeDefined();
71+
72+
expect(amadeus.safety).toBeDefined();
73+
expect(amadeus.safety.safetyRatedLocations).toBeDefined();
74+
expect(amadeus.safety.safetyRatedLocations.bySquare).toBeDefined();
75+
expect(amadeus.safety.safetyRatedLocation).toBeDefined();
7176
});
7277

7378
it('should define all expected .get methods', () => {
@@ -103,6 +108,10 @@ describe('Namespaces', () => {
103108

104109
expect(amadeus.media.files.generatedPhotos.get).toBeDefined();
105110
expect(amadeus.airport.predictions.onTime.get).toBeDefined();
111+
112+
expect(amadeus.safety.safetyRatedLocations.get).toBeDefined();
113+
expect(amadeus.safety.safetyRatedLocations.bySquare.get).toBeDefined();
114+
expect(amadeus.safety.safetyRatedLocation('XXX').get).toBeDefined();
106115
});
107116

108117
it('should define all expected .post methods', () => {
@@ -356,5 +365,26 @@ describe('Namespaces', () => {
356365
expect(amadeus.client.get)
357366
.toHaveBeenCalledWith('/v1/airport/predictions/on-time', {});
358367
});
368+
369+
it('.amadeus.safety.safetyRatedLocations.get', () => {
370+
amadeus.client.get = jest.fn();
371+
amadeus.safety.safetyRatedLocations.get();
372+
expect(amadeus.client.get)
373+
.toHaveBeenCalledWith('/v1/safety/safety-rated-locations', {});
374+
});
375+
376+
it('.amadeus.safety.safetyRatedLocations.bySquare.get', () => {
377+
amadeus.client.get = jest.fn();
378+
amadeus.safety.safetyRatedLocations.bySquare.get();
379+
expect(amadeus.client.get)
380+
.toHaveBeenCalledWith('/v1/safety/safety-rated-locations/by-square', {});
381+
});
382+
383+
it('.amadeus.safety.safetyRatedLocation().get', () => {
384+
amadeus.client.get = jest.fn();
385+
amadeus.safety.safetyRatedLocation('XXX').get();
386+
expect(amadeus.client.get)
387+
.toHaveBeenCalledWith('/v1/safety/safety-rated-locations/XXX');
388+
});
359389
});
360390
});

src/amadeus.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Travel from './amadeus/namespaces/travel';
88
import EReputation from './amadeus/namespaces/e_reputation';
99
import Media from './amadeus/namespaces/media';
1010
import Airport from './amadeus/namespaces/airport';
11+
import Safety from './amadeus/namespaces/safety';
1112

1213
/**
1314
* The Amadeus client library for accessing the travel APIs.
@@ -67,6 +68,7 @@ class Amadeus {
6768
this.media = new Media(this.client);
6869
this.airport = new Airport(this.client);
6970
this.pagination = new Pagination(this.client);
71+
this.safety = new Safety(this.client);
7072
}
7173

7274
/**

src/amadeus/namespaces/safety.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import SafetyRatedLocations from './safety/safety_rated_locations';
2+
import SafetyRatedLocation from './safety/safety_rated_location';
3+
4+
/**
5+
* A namespaced client for the
6+
* `/v1/safety` endpoints
7+
*
8+
* Access via the {@link Amadeus} object
9+
*
10+
* ```js
11+
* let amadeus = new Amadeus();
12+
* amadeus.safety;
13+
* ```
14+
*
15+
* @param {Client} client
16+
* @property {SafetyRatedLocations} safetyRatedLocations
17+
*/
18+
class Safety {
19+
constructor(client) {
20+
this.client = client;
21+
this.safetyRatedLocations = new SafetyRatedLocations(client);
22+
}
23+
24+
safetyRatedLocation(locationId) {
25+
return new SafetyRatedLocation(this.client, locationId);
26+
}
27+
}
28+
29+
export default Safety;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* A namespaced client for the
3+
* `/v1/safety/safety-rated-locations` endpoints
4+
*
5+
* Access via the {@link Amadeus} object
6+
*
7+
* ```js
8+
* let amadeus = new Amadeus();
9+
* amadeus.safety.safetyRatedLocation;
10+
* ```
11+
*
12+
* @param {Client} client
13+
*/
14+
class SafetyRatedLocation {
15+
constructor(client, locationId) {
16+
this.client = client;
17+
this.locationId = locationId;
18+
}
19+
20+
/**
21+
* Retieve safety information of a location by its Id.
22+
*
23+
* What is the safety information of a location with Id Q930400801?
24+
* ```js
25+
* amadeus.safety.safetyRatedLocation('Q930400801').get();
26+
* ```
27+
*/
28+
get() {
29+
return this.client.get(`/v1/safety/safety-rated-locations/${this.locationId}`);
30+
}
31+
}
32+
33+
export default SafetyRatedLocation;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import BySquare from './safety_rated_locations/by_square';
2+
3+
/**
4+
* A namespaced client for the
5+
* `/v1/safety/safety-rated-locations` endpoints
6+
*
7+
* Access via the {@link Amadeus} object
8+
*
9+
* ```js
10+
* let amadeus = new Amadeus();
11+
* amadeus.safety.safetyRatedLocations;
12+
* ```
13+
*
14+
* @param {Client} client
15+
*/
16+
class SafetyRatedLocations {
17+
constructor(client) {
18+
this.client = client;
19+
this.bySquare = new BySquare(client);
20+
}
21+
22+
/**
23+
* /safety/safety-rated-locations
24+
*
25+
* @param {Object} params
26+
* @param {Double} params.latitude latitude location to be at the center of
27+
* the search circle - required
28+
* @param {Double} params.longitude longitude location to be at the center of
29+
* the search circle - required
30+
* @param {Double} params.radius radius of the search in Kilometer - optional
31+
* @return {Promise.<Response,ResponseError>} a Promise
32+
*
33+
* How safe is Barcelona? (based a geo location and a radius)
34+
*
35+
* ```js
36+
* amadeus.safety.safetyRatedLocations.get({
37+
* longitude: 2.160873,
38+
* latitude: 41.397158
39+
* });
40+
* ```
41+
*/
42+
get(params = {}) {
43+
return this.client.get('/v1/safety/safety-rated-locations', params);
44+
}
45+
}
46+
47+
export default SafetyRatedLocations;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* A namespaced client for the
3+
* `/v1/safety/safety-rated-locations/by-square` endpoints
4+
*
5+
* Access via the {@link Amadeus} object
6+
*
7+
* ```js
8+
* let amadeus = new Amadeus();
9+
* amadeus.safety.safetyRatedLocations.bySquare;
10+
* ```
11+
*
12+
* @param {Client} client
13+
*/
14+
class bySquare {
15+
constructor(client) {
16+
this.client = client;
17+
}
18+
19+
/**
20+
* Returns the safety rating of a given area
21+
*
22+
* @param {Object} params
23+
* @param {Double} params.north latitude north of bounding box - required
24+
* @param {Double} params.west longitude west of bounding box - required
25+
* @param {Double} params.south latitude south of bounding box - required
26+
* @param {Double} params.east longitude east of bounding box - required
27+
* @return {Promise.<Response,ResponseError>} a Promise
28+
*
29+
* How safe is Barcelona? (based on a square)
30+
*
31+
* ```js
32+
* amadeus.safety.safetyRatedLocations.bySquare.get({
33+
* north: 41.397158,
34+
* west: 2.160873,
35+
* south: 41.394582,
36+
* east: 2.177181
37+
* });
38+
* ```
39+
*/
40+
get(params = {}) {
41+
return this.client.get('/v1/safety/safety-rated-locations/by-square', params);
42+
}
43+
}
44+
45+
export default bySquare;

0 commit comments

Comments
 (0)