Skip to content

Commit 17dee21

Browse files
authored
Merge pull request #23 from alnacle/feature/points-of-interest
Add Points of Interest API
2 parents 6ddfe01 + a580428 commit 17dee21

File tree

6 files changed

+222
-2
lines changed

6 files changed

+222
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@ HotelOffer[] offers = amadeus.shopping.hotelOffers.get(Params
284284
HotelOffer hotelOffer = amadeus.shopping.hotelOffersByHotel.get(Params.with("hotelId", "BGLONBGB"));
285285
// Confirm the availability of a specific offer
286286
HotelOffer offer = amadeus.shopping.hotelOffer("4BA070CE929E135B3268A9F2D0C51E9D4A6CF318BA10485322FA2C7E78C7852E").get();
287+
288+
// Points of Interest
289+
// What are the popular places in Barcelona (based a geo location and a radius)
290+
PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInterest.get(Params
291+
.with("latitude", "41.39715")
292+
.and("longitude", "2.160873"));
293+
294+
// What are the popular places in Barcelona? (based on a square)
295+
PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInterest.bySquare.get(Params
296+
.with("norh", "41.397158")
297+
.and("west", "2.160873")
298+
.and("south", "41.394582")
299+
.and("east", "2.177181"));
287300
```
288301

289302
## Development & Contributing

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
77
import com.amadeus.referenceData.locations.Airports;
8+
import com.amadeus.referenceData.locations.PointsOfInterest;
89
import com.amadeus.resources.Location;
910
import com.amadeus.resources.Resource;
1011
import com.google.gson.Gson;
@@ -35,18 +36,28 @@ public class Locations {
3536
/**
3637
* <p>
3738
* A namespaced client for the
38-
* <code>/v2/reference-data/urls/checkin-links</code> endpoints.
39+
* <code>/v2/reference-data/locations/airports</code> endpoints.
3940
* </p>
4041
*/
4142
public Airports airports;
4243

44+
/**
45+
* <p>
46+
* A namespaced client for the
47+
* <code>/v2/reference-data/locations/pois</code> endpoints.
48+
* </p>
49+
*/
50+
public PointsOfInterest pointsOfInterest;
51+
52+
4353
/**
4454
* Constructor.
4555
* @hide
4656
*/
4757
public Locations(Amadeus client) {
4858
this.client = client;
4959
this.airports = new Airports(client);
60+
this.pointsOfInterest = new PointsOfInterest(client);
5061
}
5162

5263
/**
@@ -70,7 +81,7 @@ public Location[] get(Params params) throws ResponseException {
7081

7182
/**
7283
* Convenience method for calling <code>get</code> without any parameters.
73-
* @see Airports#get()
84+
* @see Locations#get()
7485
*/
7586
public Location[] get() throws ResponseException {
7687
return get(null);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.referenceData.locations.pointsOfInterest.BySquare;
8+
import com.amadeus.resources.PointOfInterest;
9+
import com.amadeus.resources.Resource;
10+
import com.google.gson.Gson;
11+
12+
/**
13+
* <p>
14+
* A namespaced client for the
15+
* <code>/v1/reference-data/locations/pois</code> endpoints.
16+
* </p>
17+
*
18+
* <p>
19+
* Access via the Amadeus client object.
20+
* </p>
21+
*
22+
* <pre>
23+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
24+
* amadeus.referenceData.locations.pointsOfInterest;</pre>
25+
*/
26+
public class PointsOfInterest {
27+
private Amadeus client;
28+
29+
30+
/**
31+
* <p>
32+
* A namespaced client for the
33+
* <code>/v1/reference-data/locations/pois/by-square</code> endpoints.
34+
* </p>
35+
*/
36+
public BySquare bySquare;
37+
38+
/**
39+
* Constructor.
40+
* @hide
41+
*/
42+
public PointsOfInterest(Amadeus client) {
43+
this.client = client;
44+
this.bySquare = new BySquare(client);
45+
}
46+
47+
48+
/**
49+
* <p>
50+
* Returns a list of relevant point of interests near to a given point.
51+
* </p>
52+
*
53+
* <pre>
54+
* amadeus.referenceData.locations.pointsOfInterest.get(Params
55+
* .with("longitude", 2.160873)
56+
* .and("latitude", 41.397158));</pre>
57+
*
58+
* @param params the parameters to send to the API
59+
* @return an API response object
60+
* @throws ResponseException when an exception occurs
61+
*/
62+
public PointOfInterest[] get(Params params) throws ResponseException {
63+
Response response = client.get("/v1/reference-data/locations/pois", params);
64+
return (PointOfInterest[]) Resource.fromArray(response, PointOfInterest[].class);
65+
}
66+
67+
/**
68+
* Convenience method for calling <code>get</code> without any parameters.
69+
* @see PointsOfInterest#get()
70+
*/
71+
public PointOfInterest[] get() throws ResponseException {
72+
return get(null);
73+
}
74+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.amadeus.referenceData.locations.pointsOfInterest;
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.PointOfInterest;
8+
import com.amadeus.resources.Resource;
9+
import com.google.gson.Gson;
10+
11+
/**
12+
* <p>
13+
* A namespaced client for the
14+
* <code>/v1/reference-data/locations/pois/by-square</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.referenceData.locations.pointsOfInterest.bySquare;</pre>
24+
*/
25+
public class BySquare {
26+
private Amadeus client;
27+
28+
/**
29+
* Constructor.
30+
* @hide
31+
*/
32+
public BySquare(Amadeus client) {
33+
this.client = client;
34+
}
35+
36+
/**
37+
* <p>
38+
* Returns a list of relevant point of interests within a square defined by
39+
* cardinal points.
40+
* </p>
41+
*
42+
* <pre>
43+
* amadeus.referenceData.locations.pointsOfInterest.bySquare.get(Params
44+
* .with("north", 41.397158)
45+
* .and("west", 2.160873)
46+
* .and("south", 41.394582)
47+
* .and("east", 2.177181));</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 PointOfInterest[] get(Params params) throws ResponseException {
54+
Response response = client.get("/v1/reference-data/locations/pois/by-square", params);
55+
return (PointOfInterest[]) Resource.fromArray(response, PointOfInterest[].class);
56+
}
57+
58+
/**
59+
* Convenience method for calling <code>get</code> without any parameters.
60+
* @see PointsOfInterest#get()
61+
*/
62+
public PointOfInterest[] get() throws ResponseException {
63+
return get(null);
64+
}
65+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* An PointOfInterest object as returned by the Locaion API.
8+
* @see com.amadeus.referenceData.locations.PointOfInterest#get()
9+
*/
10+
@ToString
11+
public class PointOfInterest extends Resource {
12+
protected PointOfInterest() {}
13+
14+
private @Getter String type;
15+
private @Getter String subType;
16+
private @Getter String name;
17+
private @Getter GeoCode geoCode;
18+
private @Getter String category;
19+
private @Getter String[] tags;
20+
21+
/**
22+
* An PointOfInterest-related object as returned by the PointOfInterest API.
23+
* @see com.amadeus.referenceData.locations.PointOfInterest#get()
24+
*/
25+
@ToString
26+
public class GeoCode {
27+
protected GeoCode() {}
28+
29+
private @Getter double latitude;
30+
private @Getter double longitude;
31+
}
32+
33+
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.amadeus.referenceData.Location;
66
import com.amadeus.referenceData.Locations;
77
import com.amadeus.referenceData.locations.Airports;
8+
import com.amadeus.referenceData.locations.PointsOfInterest;
9+
import com.amadeus.referenceData.locations.pointsOfInterest.BySquare;
810
import com.amadeus.referenceData.urls.CheckinLinks;
911
import com.amadeus.shopping.FlightDates;
1012
import com.amadeus.shopping.FlightDestinations;
@@ -36,6 +38,8 @@ public void testAllNamespacesExist() {
3638
Amadeus client = Amadeus.builder("id", "secret").build();
3739
TestCase.assertNotNull(client.referenceData.urls.checkinLinks);
3840
TestCase.assertNotNull(client.referenceData.locations.airports);
41+
TestCase.assertNotNull(client.referenceData.locations.pointsOfInterest);
42+
TestCase.assertNotNull(client.referenceData.locations.pointsOfInterest.bySquare);
3943
TestCase.assertNotNull(client.referenceData.location("123"));
4044
TestCase.assertNotNull(client.referenceData.airlines);
4145
TestCase.assertNotNull(client.travel.analytics.airTraffic.traveled);
@@ -104,6 +108,26 @@ public void testGetMethods() throws ResponseException {
104108
TestCase.assertNotNull(airports.get(params));
105109
TestCase.assertEquals(airports.get().length, 2);
106110

111+
// Testing points of interest
112+
Mockito.when(client.get("/v1/reference-data/locations/pois", null))
113+
.thenReturn(multiResponse);
114+
Mockito.when(client.get("/v1/reference-data/locations/pois", params))
115+
.thenReturn(multiResponse);
116+
PointsOfInterest pois = new PointsOfInterest(client);
117+
TestCase.assertNotNull(pois.get());
118+
TestCase.assertNotNull(pois.get(params));
119+
TestCase.assertEquals(pois.get().length, 2);
120+
121+
// Testing points of interest by square
122+
Mockito.when(client.get("/v1/reference-data/locations/pois/by-square", null))
123+
.thenReturn(multiResponse);
124+
Mockito.when(client.get("/v1/reference-data/locations/pois/by-square", params))
125+
.thenReturn(multiResponse);
126+
PointsOfInterest poisSquare = new PointsOfInterest(client);
127+
TestCase.assertNotNull(poisSquare.get());
128+
TestCase.assertNotNull(poisSquare.get(params));
129+
TestCase.assertEquals(poisSquare.get().length, 2);
130+
107131
// Testing fetching a single location
108132
Mockito.when(client.get("/v1/reference-data/locations/ALHR", null))
109133
.thenReturn(singleResponse);

0 commit comments

Comments
 (0)