Skip to content

Commit c0a6dfd

Browse files
authored
Merge pull request #65 from amadeus4dev/pois-retrieve
Add support for Points of Interest retrieve
2 parents b248c59 + 1b6cf57 commit c0a6dfd

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt
330330
.and("south", "41.394582")
331331
.and("east", "2.177181"));
332332

333+
// Returns a single Point of Interest from a given id
334+
PointOfInterest pointOfInterest = amadeus.referenceData.locations.pointOfInterest("9CB40CB5D0").get();
335+
333336
// What's the likelihood flights from this airport will leave on time?
334337
Prediction AirportOnTime = amadeus.airport.predictions.onTime.get(Params
335338
.with("airportCode", "NCE")

src/main/java/com/amadeus/referenceData/Locations.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
77
import com.amadeus.referenceData.locations.Airports;
8+
import com.amadeus.referenceData.locations.PointOfInterest;
89
import com.amadeus.referenceData.locations.PointsOfInterest;
910
import com.amadeus.resources.Location;
1011
import com.amadeus.resources.Resource;
11-
import com.google.gson.Gson;
1212

1313
/**
1414
* <p>
@@ -49,6 +49,13 @@ public class Locations {
4949
*/
5050
public PointsOfInterest pointsOfInterest;
5151

52+
/**
53+
* <p>
54+
* A namespaced client for the
55+
* <code>/v2/reference-data/locations/pois</code> endpoints.
56+
* </p>
57+
*/
58+
public PointOfInterest pointOfInterest;
5259

5360
/**
5461
* Constructor.
@@ -86,4 +93,8 @@ public Location[] get(Params params) throws ResponseException {
8693
public Location[] get() throws ResponseException {
8794
return get(null);
8895
}
96+
97+
public PointOfInterest pointOfInterest(String id) {
98+
return new PointOfInterest(client, id);
99+
}
89100
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.amadeus.referenceData.locations;
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+
9+
/**
10+
* <p>
11+
* A namespaced client for the
12+
* <code>/v1/reference-data/locations/pois</code> endpoints.
13+
* </p>
14+
*
15+
* <p>
16+
* Access via the Amadeus client object.
17+
* </p>
18+
*
19+
* <pre>
20+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
21+
* amadeus.referenceData.locations.pointOfInterest;</pre>
22+
*/
23+
public class PointOfInterest {
24+
private Amadeus client;
25+
private String id;
26+
27+
28+
/**
29+
* Constructor.
30+
* @hide
31+
*/
32+
public PointOfInterest(Amadeus client, String id) {
33+
this.client = client;
34+
this.id = id;
35+
}
36+
37+
/**
38+
* <p>
39+
* Returns a single Point of Interest from a given id.
40+
* </p>
41+
*
42+
* <pre>
43+
* amadeus.referenceData.locations.pointOfInterest("9CB40CB5D0").get();</pre>
44+
*
45+
* @param params the parameters to send to the API
46+
* @return an API response object
47+
* @throws ResponseException when an exception occurs
48+
*/
49+
public com.amadeus.resources.PointOfInterest get(Params params) throws ResponseException {
50+
String path = String.format("/v1/reference-data/locations/pois/%s", id);
51+
Response response = client.get(path, params);
52+
return (com.amadeus.resources.PointOfInterest) Resource.fromObject(
53+
response, com.amadeus.resources.PointOfInterest.class);
54+
}
55+
56+
/**
57+
* Convenience method for calling <code>get</code> without any parameters.
58+
* @see PointOfInterest#get()
59+
*/
60+
public com.amadeus.resources.PointOfInterest get() throws ResponseException {
61+
return get(null);
62+
}
63+
}

src/main/java/com/amadeus/resources/PointOfInterest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import lombok.ToString;
55

66
/**
7-
* An PointOfInterest object as returned by the Location API.
7+
* A PointOfInterest object as returned by the Location API.
88
* @see com.amadeus.referenceData.locations.PointOfInterest#get()
99
*/
1010
@ToString

src/test/java/com/amadeus/NamespaceTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void testAllNamespacesExist() {
5151
TestCase.assertNotNull(client.referenceData.locations.airports);
5252
TestCase.assertNotNull(client.referenceData.locations.pointsOfInterest);
5353
TestCase.assertNotNull(client.referenceData.locations.pointsOfInterest.bySquare);
54+
TestCase.assertNotNull(client.referenceData.locations.pointOfInterest("XXX"));
5455
TestCase.assertNotNull(client.referenceData.location("123"));
5556
TestCase.assertNotNull(client.referenceData.airlines);
5657
TestCase.assertNotNull(client.travel.analytics.airTraffic.traveled);
@@ -149,6 +150,16 @@ public void testGetMethods() throws ResponseException {
149150
TestCase.assertNotNull(poisSquare.get(params));
150151
TestCase.assertEquals(poisSquare.get().length, 2);
151152

153+
// Testing retrieving point of interest
154+
Mockito.when(client.get("/v1/reference-data/locations/pois/XXX", null))
155+
.thenReturn(multiResponse);
156+
Mockito.when(client.get("/v1/reference-data/locations/pois/XXX", params))
157+
.thenReturn(multiResponse);
158+
PointsOfInterest poi = new PointsOfInterest(client);
159+
TestCase.assertNotNull(poi.get());
160+
TestCase.assertNotNull(poi.get(params));
161+
TestCase.assertEquals(poi.get().length, 2);
162+
152163
// Testing fetching a single location
153164
Mockito.when(client.get("/v1/reference-data/locations/ALHR", null))
154165
.thenReturn(singleResponse);

0 commit comments

Comments
 (0)