Skip to content

Commit f216d34

Browse files
authored
Add support for safe place API (#79)
* add support for safe place API * change import order * add tests * fix typo
1 parent 58d7544 commit f216d34

File tree

8 files changed

+364
-0
lines changed

8 files changed

+364
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,22 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt
291291
// Returns a single Point of Interest from a given id
292292
PointOfInterest pointOfInterest = amadeus.referenceData.locations.pointOfInterest("9CB40CB5D0").get();
293293

294+
// Safe Place
295+
// How safe is Barcelona? (based a geo location and a radius)
296+
SafePlace[] safetyScore = amadeus.safety.safetyRatedLocations.get(Params
297+
.with("latitude", "41.39715")
298+
.and("longitude", "2.160873"));
299+
300+
// How safe is Barcelona? (based on a square)
301+
SafePlace[] safetyScore = amadeus.safety.safetyRatedLocations.bySquare.get(Params
302+
.with("north", "41.397158")
303+
.and("west", "2.160873")
304+
.and("south", "41.394582")
305+
.and("east", "2.177181"));
306+
307+
// What is the safety information of a location based on it's Id?
308+
SafePlace safetyScore = amadeus.safety.safetyRatedLocation("Q930400801").get();
309+
294310
// What's the likelihood flights from this airport will leave on time?
295311
Prediction AirportOnTime = amadeus.airport.predictions.onTime.get(Params
296312
.with("airportCode", "NCE")

src/main/java/com/amadeus/Amadeus.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public class Amadeus extends HTTPClient {
7676
*/
7777
public Media media;
7878

79+
/**
80+
* <p>
81+
* A namespaced client for the <code>/v1/safety</code> endpoints.
82+
* </p>
83+
*/
84+
public Safety safety;
85+
7986
protected Amadeus(Configuration configuration) {
8087
super(configuration);
8188
this.referenceData = new ReferenceData(this);
@@ -85,6 +92,7 @@ protected Amadeus(Configuration configuration) {
8592
this.airport = new Airport(this);
8693
this.booking = new Booking(this);
8794
this.media = new Media(this);
95+
this.safety = new Safety(this);
8896

8997
}
9098

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.amadeus;
2+
3+
import com.amadeus.safety.SafetyRatedLocation;
4+
import com.amadeus.safety.SafetyRatedLocations;
5+
6+
/**
7+
* <p>
8+
* A namespaced client for the
9+
* <code>/v1/safety</code> endpoints.
10+
* </p>
11+
*
12+
* <p>
13+
* Access via the Amadeus client object.
14+
* </p>
15+
*
16+
* <pre>
17+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
18+
* amadeus.safety;</pre>
19+
*
20+
* @hide
21+
*/
22+
public class Safety {
23+
private Amadeus client;
24+
25+
/**
26+
* <p>
27+
* A namespaced client for the
28+
* <code>/v1/safety/safety-rated-locations</code> endpoints.
29+
* </p>
30+
*/
31+
public SafetyRatedLocations safetyRatedLocations;
32+
33+
/**
34+
* Constructor.
35+
* @hide
36+
*/
37+
public Safety(Amadeus client) {
38+
this.safetyRatedLocations = new SafetyRatedLocations(client);
39+
}
40+
41+
/**
42+
* <p>
43+
* A namespaced client for the
44+
* <code>/v1/safety/safety-rated-locations/:safetyRatedLocationId</code> endpoints.
45+
* </p>
46+
*/
47+
public SafetyRatedLocation safetyRatedLocation(String safetyRatedLocationId) {
48+
return new SafetyRatedLocation(client, safetyRatedLocationId);
49+
}
50+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* A SafePlace object as returned by the Safe Place API.
8+
* @see com.amadeus.safety.safety_rated_locations.SafePlace#get()
9+
*/
10+
@ToString
11+
public class SafePlace extends Resource {
12+
protected SafePlace() {}
13+
14+
private @Getter String type;
15+
private @Getter String id;
16+
private @Getter String subType;
17+
private @Getter String name;
18+
private @Getter GeoCode geoCode;
19+
private @Getter SafetyRating safetyRating;
20+
21+
22+
/**
23+
* An SafePlace-related object as returned by the SafePlace API.
24+
* @see com.amadeus.safety.safety_rated_locations.SafePlace#get()
25+
*/
26+
@ToString
27+
public class GeoCode {
28+
protected GeoCode() {}
29+
30+
private @Getter double latitude;
31+
private @Getter double longitude;
32+
}
33+
34+
/**
35+
* An SafePlace-related object as returned by the SafePlace API.
36+
* @see com.amadeus.safety.safety_rated_locations.SafePlace#get()
37+
*/
38+
@ToString
39+
public class SafetyRating {
40+
protected SafetyRating() {}
41+
42+
private @Getter int women;
43+
private @Getter int physicalHarm;
44+
private @Getter int theft;
45+
private @Getter int politicalFreedom;
46+
private @Getter int lgbtq;
47+
private @Getter int medical;
48+
private @Getter int overall;
49+
50+
}
51+
52+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.amadeus.safety;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Resource;
8+
import com.amadeus.resources.SafePlace;
9+
import com.google.gson.Gson;
10+
11+
/**
12+
* <p>
13+
* A namespaced client for the
14+
* <code>/v1/safety/safety-rated-locations</code> endpoints.
15+
* </p>
16+
*
17+
* <p>
18+
* Access via the Amadeus client object.
19+
* </p>
20+
*
21+
* <pre>
22+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
23+
* amadeus.safety.safetyRatedLocations;</pre>
24+
*/
25+
public class SafetyRatedLocation {
26+
private Amadeus client;
27+
private String safetyRatedLocationId;
28+
29+
/**
30+
* Constructor.
31+
* @hide
32+
*/
33+
public SafetyRatedLocation(Amadeus client, String safetyRatedLocationId) {
34+
this.client = client;
35+
this.safetyRatedLocationId = safetyRatedLocationId;
36+
}
37+
38+
39+
/**
40+
* <p>
41+
* Returns safety information of a location based on it's Id.
42+
* </p>
43+
*
44+
* <pre>
45+
* amadeus.safety.safetyRatedLocations.get(Params
46+
* .with("longitude", 2.160873)
47+
* .and("latitude", 41.397158));</pre>
48+
*
49+
* @param params the parameters to send to the API
50+
* @return an API response object
51+
* @throws ResponseException when an exception occurs
52+
*/
53+
public SafePlace get(Params params) throws ResponseException {
54+
String path = String.format("/v1/safety/safety-rated-locations/%s", safetyRatedLocationId);
55+
Response response = client.get(path, params);
56+
return (SafePlace) Resource.fromObject(
57+
response, com.amadeus.resources.SafePlace.class);
58+
}
59+
60+
/**
61+
* Convenience method for calling <code>get</code> without any parameters.
62+
* @see SafetyRatedLocation#get()
63+
*/
64+
public SafePlace get() throws ResponseException {
65+
return get(null);
66+
}
67+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.amadeus.safety;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Resource;
8+
import com.amadeus.resources.SafePlace;
9+
import com.amadeus.safety.safetyRatedLocations.BySquare;
10+
11+
/**
12+
* <p>
13+
* A namespaced client for the
14+
* <code>/v1/safety/safety-rated-locations</code> endpoints.
15+
* </p>
16+
*
17+
* <p>
18+
* Access via the Amadeus client object.
19+
* </p>
20+
*
21+
* <pre>
22+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
23+
* amadeus.safety.safetyRatedLocations;</pre>
24+
*/
25+
public class SafetyRatedLocations {
26+
private Amadeus client;
27+
28+
29+
/**
30+
* <p>
31+
* A namespaced client for the
32+
* <code>/v1/safety/safety-rated-locations/by-square</code> endpoints.
33+
* </p>
34+
*/
35+
public BySquare bySquare;
36+
37+
/**
38+
* Constructor.
39+
* @hide
40+
*/
41+
public SafetyRatedLocations(Amadeus client) {
42+
this.client = client;
43+
this.bySquare = new BySquare(client);
44+
}
45+
46+
47+
/**
48+
* <p>
49+
* Returns a list of safety information near to a given point.
50+
* </p>
51+
*
52+
* <pre>
53+
* amadeus.safety.safetyRatedLocations.get(Params
54+
* .with("longitude", 2.160873)
55+
* .and("latitude", 41.397158));</pre>
56+
*
57+
* @param params the parameters to send to the API
58+
* @return an API response object
59+
* @throws ResponseException when an exception occurs
60+
*/
61+
public SafePlace[] get(Params params) throws ResponseException {
62+
Response response = client.get("/v1/safety/safety-rated-locations", params);
63+
return (SafePlace[]) Resource.fromArray(response, SafePlace[].class);
64+
}
65+
66+
/**
67+
* Convenience method for calling <code>get</code> without any parameters.
68+
* @see SafetyRatedLocations#get()
69+
*/
70+
public SafePlace[] get() throws ResponseException {
71+
return get(null);
72+
}
73+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.amadeus.safety.safetyRatedLocations;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Resource;
8+
import com.amadeus.resources.SafePlace;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v1/safety/safety-rated-locations/by-square</code> endpoints.
14+
* </p>
15+
*
16+
* <p>
17+
* Access via the Amadeus client object.
18+
* </p>
19+
*
20+
* <pre>
21+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
22+
* amadeus.safety.safetyRatedLocations.bySquare;</pre>
23+
*/
24+
public class BySquare {
25+
private Amadeus client;
26+
27+
/**
28+
* Constructor.
29+
* @hide
30+
*/
31+
public BySquare(Amadeus client) {
32+
this.client = client;
33+
}
34+
35+
/**
36+
* <p>
37+
* Returns a list of safety information within a square defined by
38+
* cardinal points.
39+
* </p>
40+
*
41+
* <pre>
42+
* amadeus.safety.safetyRatedLocations.bySquare.get(Params
43+
* .with("north", 41.397158)
44+
* .and("west", 2.160873)
45+
* .and("south", 41.394582)
46+
* .and("east", 2.177181));</pre>
47+
*
48+
* @param params the parameters to send to the API
49+
* @return an API response object
50+
* @throws ResponseException when an exception occurs
51+
*/
52+
public SafePlace[] get(Params params) throws ResponseException {
53+
Response response = client.get("/v1/safety/safety-rated-locations/by-square", params);
54+
return (SafePlace[]) Resource.fromArray(response, SafePlace[].class);
55+
}
56+
57+
/**
58+
* Convenience method for calling <code>get</code> without any parameters.
59+
* @see SafetyRatedLocations#get()
60+
*/
61+
public SafePlace[] get() throws ResponseException {
62+
return get(null);
63+
}
64+
}

0 commit comments

Comments
 (0)