Skip to content

Commit 2758456

Browse files
committed
Add locations APIs
1 parent bbcc6a4 commit 2758456

File tree

5 files changed

+248
-0
lines changed

5 files changed

+248
-0
lines changed

src/main/java/com/amadeus/ReferenceData.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.amadeus;
22

3+
import com.amadeus.referenceData.Location;
4+
import com.amadeus.referenceData.Locations;
35
import com.amadeus.referenceData.Urls;
46

57
/**
@@ -19,6 +21,8 @@
1921
* @hide
2022
*/
2123
public class ReferenceData {
24+
private Amadeus client;
25+
2226
/**
2327
* <p>
2428
* A namespaced client for the
@@ -27,11 +31,31 @@ public class ReferenceData {
2731
*/
2832
public Urls urls;
2933

34+
/**
35+
* <p>
36+
* A namespaced client for the
37+
* <code>/v2/reference-data/locations</code> endpoints.
38+
* </p>
39+
*/
40+
public Locations locations;
41+
3042
/**
3143
* Constructor.
3244
* @hide
3345
*/
3446
public ReferenceData(Amadeus client) {
47+
this.client = client;
3548
this.urls = new Urls(client);
49+
this.locations = new Locations(client);
50+
}
51+
52+
/**
53+
* <p>
54+
* A namespaced client for the
55+
* <code>/v2/reference-data/location/:hotel_id</code> endpoints.
56+
* </p>
57+
*/
58+
public Location location(String locationId) {
59+
return new Location(client, locationId);
3660
}
3761
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.amadeus.referenceData;
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.Airports;
8+
9+
/**
10+
* <p>
11+
* A namespaced client for the
12+
* <code>/v2/reference-data/locations/:location_id</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.location(locationId);</pre>
22+
*
23+
* @hide
24+
*/
25+
public class Location {
26+
private Amadeus client;
27+
private String locationId;
28+
29+
/**
30+
* Constructor.
31+
* @hide
32+
*/
33+
public Location(Amadeus client, String locationId) {
34+
this.locationId = locationId;
35+
this.client = client;
36+
}
37+
38+
/**
39+
* <p>
40+
* Returns details for a specific airport.
41+
* </p>
42+
*
43+
* <pre>
44+
* amadeus.referenceData.locations("ALHR').get();</pre>
45+
*
46+
* @param params the parameters to send to the API
47+
* @return an API response object
48+
* @throws ResponseException when an exception occurs
49+
*/
50+
public Response get(Params params) throws ResponseException {
51+
String path = String.format("/v1/reference-data/locations/%s", locationId);
52+
return client.get(path, params);
53+
}
54+
55+
/**
56+
* Convenience method for calling <code>get</code> without any parameters.
57+
* @see Airports#get()
58+
*/
59+
public Response get() throws ResponseException {
60+
return get(null);
61+
}
62+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.amadeus.referenceData;
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.Airports;
8+
import com.amadeus.referenceData.urls.CheckinLinks;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v2/reference-data/locations</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.referenceData.locations;</pre>
23+
*
24+
* @hide
25+
*/
26+
public class Locations {
27+
public static String ANY = "AIRPORT,CITY";
28+
public static String AIRPORT = "AIRPORT";
29+
public static String CITY = "CITY";
30+
31+
private Amadeus client;
32+
33+
/**
34+
* <p>
35+
* A namespaced client for the
36+
* <code>/v2/reference-data/urls/checkin-links</code> endpoints.
37+
* </p>
38+
*/
39+
public Airports airports;
40+
41+
/**
42+
* Constructor.
43+
* @hide
44+
*/
45+
public Locations(Amadeus client) {
46+
this.client = client;
47+
this.airports = new Airports(client);
48+
}
49+
50+
/**
51+
* <p>
52+
* Returns a list of airports and cities matching a given keyword.
53+
* </p>
54+
*
55+
* <pre>
56+
* amadeus.referenceData.locations.get(Params
57+
* .with("keyword", "lon)
58+
* .and("subType", Locations.ANY));</pre>
59+
*
60+
* @param params the parameters to send to the API
61+
* @return an API response object
62+
* @throws ResponseException when an exception occurs
63+
*/
64+
public Response get(Params params) throws ResponseException {
65+
return client.get("/v1/reference-data/locations", params);
66+
}
67+
68+
/**
69+
* Convenience method for calling <code>get</code> without any parameters.
70+
* @see Airports#get()
71+
*/
72+
public Response get() throws ResponseException {
73+
return get(null);
74+
}
75+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
8+
/**
9+
* <p>
10+
* A namespaced client for the
11+
* <code>/v1/reference-data/locations/airports</code> endpoints.
12+
* </p>
13+
*
14+
* <p>
15+
* Access via the Amadeus client object.
16+
* </p>
17+
*
18+
* <pre>
19+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
20+
* amadeus.referenceData.locations.airports;</pre>
21+
*/
22+
public class Airports {
23+
private Amadeus client;
24+
25+
/**
26+
* Constructor.
27+
* @hide
28+
*/
29+
public Airports(Amadeus client) {
30+
this.client = client;
31+
}
32+
33+
/**
34+
* <p>
35+
* Returns a list of relevant airports near to a given point.
36+
* </p>
37+
*
38+
* <pre>
39+
* amadeus.referenceData.locations.airports.get(Params
40+
* .with("longitude", 49.0000)
41+
* .and("latitude", 2.55));</pre>
42+
*
43+
* @param params the parameters to send to the API
44+
* @return an API response object
45+
* @throws ResponseException when an exception occurs
46+
*/
47+
public Response get(Params params) throws ResponseException {
48+
return client.get("/v1/reference-data/locations/airports", params);
49+
}
50+
51+
/**
52+
* Convenience method for calling <code>get</code> without any parameters.
53+
* @see Airports#get()
54+
*/
55+
public Response get() throws ResponseException {
56+
return get(null);
57+
}
58+
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import static org.mockito.Mockito.when;
77

88
import com.amadeus.exceptions.ResponseException;
9+
import com.amadeus.referenceData.Location;
10+
import com.amadeus.referenceData.Locations;
11+
import com.amadeus.referenceData.locations.Airports;
912
import com.amadeus.referenceData.urls.CheckinLinks;
1013
import com.amadeus.shopping.FlightDates;
1114
import com.amadeus.shopping.FlightDestinations;
@@ -20,6 +23,8 @@ public class NamespaceTest {
2023
@Test public void testAllNamespacesExist() {
2124
Amadeus client = Amadeus.builder("id", "secret").build();
2225
assertNotNull(client.referenceData.urls.checkinLinks);
26+
assertNotNull(client.referenceData.locations.airports);
27+
assertNotNull(client.referenceData.location("123"));
2328
assertNotNull(client.travel.analytics.airTraffic.traveled);
2429
assertNotNull(client.travel.analytics.fareSearches);
2530
assertNotNull(client.shopping.flightDates);
@@ -42,6 +47,30 @@ public class NamespaceTest {
4247
assertTrue(checkinLinks.get() instanceof Response);
4348
assertTrue(checkinLinks.get(params) instanceof Response);
4449

50+
when(client.get("/v1/reference-data/locations", null))
51+
.thenReturn(mock(Response.class));
52+
when(client.get("/v1/reference-data/locations", params))
53+
.thenReturn(mock(Response.class));
54+
Locations locations = new Locations(client);
55+
assertTrue(locations.get() instanceof Response);
56+
assertTrue(locations.get(params) instanceof Response);
57+
58+
when(client.get("/v1/reference-data/locations/airports", null))
59+
.thenReturn(mock(Response.class));
60+
when(client.get("/v1/reference-data/locations/airports", params))
61+
.thenReturn(mock(Response.class));
62+
Airports airports = new Airports(client);
63+
assertTrue(airports.get() instanceof Response);
64+
assertTrue(airports.get(params) instanceof Response);
65+
66+
when(client.get("/v1/reference-data/locations/ALHR", null))
67+
.thenReturn(mock(Response.class));
68+
when(client.get("/v1/reference-data/locations/ALHR", params))
69+
.thenReturn(mock(Response.class));
70+
Location location = new Location(client, "ALHR");
71+
assertTrue(location.get() instanceof Response);
72+
assertTrue(location.get(params) instanceof Response);
73+
4574
when(client.get("/v1/travel/analytics/air-traffic/traveled", null))
4675
.thenReturn(mock(Response.class));
4776
when(client.get("/v1/travel/analytics/air-traffic/traveled", params))

0 commit comments

Comments
 (0)