Skip to content

Commit 3d3ae83

Browse files
authored
Add support for Airport on Time (#50)
* support and tests * change import order * handle ontime as object and not array * update readme * fix indentation * fix indent in bracket * fix typo
1 parent a075523 commit 3d3ae83

File tree

7 files changed

+179
-0
lines changed

7 files changed

+179
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt
325325
.and("west", "2.160873")
326326
.and("south", "41.394582")
327327
.and("east", "2.177181"));
328+
329+
// What's the likelihood flights from this airport will leave on time?
330+
OnTime AirportOnTime = amadeus.airport.predictions.onTime.get(Params
331+
.with("airportCode", "NCE")
332+
.and("date", "2020-09-01"));
328333

329334
Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
330335
.with("originLocationCode", "NCE")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.amadeus;
2+
3+
import com.amadeus.airport.predictions.Predictions;
4+
5+
/**
6+
* <p>
7+
* A namespaced client for the
8+
* <code>/v1/airport</code> endpoints.
9+
* </p>
10+
*
11+
* <p>
12+
* Access via the Amadeus client object.
13+
* </p>
14+
*
15+
* <pre>
16+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
17+
* amadeus.airport</pre>
18+
*
19+
* @hide
20+
*/
21+
public class Airport {
22+
/**
23+
* <p>
24+
* A namespaced client for the
25+
* <code>/v1/airport/predictions</code> endpoints.
26+
* </p>
27+
*/
28+
public Predictions predictions;
29+
30+
/**
31+
* Constructor.
32+
* @hide
33+
*/
34+
public Airport(Amadeus client) {
35+
this.predictions = new Predictions(client);
36+
}
37+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,20 @@ public class Amadeus extends HTTPClient {
5555
*/
5656
public EReputation ereputation;
5757

58+
/**
59+
* <p>
60+
* A namespaced client for the <code>/v1/airport</code> endpoints.
61+
* </p>
62+
*/
63+
public Airport airport;
64+
5865
protected Amadeus(Configuration configuration) {
5966
super(configuration);
6067
this.referenceData = new ReferenceData(this);
6168
this.travel = new Travel(this);
6269
this.shopping = new Shopping(this);
6370
this.ereputation = new EReputation(this);
71+
this.airport = new Airport(this);
6472
}
6573

6674
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.amadeus.airport.predictions;
2+
3+
import com.amadeus.Amadeus;
4+
5+
/**
6+
* <p>
7+
* A namespaced client for the
8+
* <code>/v1/airport/predictions</code> endpoints.
9+
* </p>
10+
*
11+
* <p>
12+
* Access via the Amadeus client object.
13+
* </p>
14+
*
15+
* <pre>
16+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
17+
* amadeus.airport.predictions;</pre>
18+
*
19+
* @hide
20+
*/
21+
public class Predictions {
22+
/**
23+
* <p>
24+
* A namespaced client for the
25+
* <code>/v1/airport/predictions/on-time</code> endpoints.
26+
* </p>
27+
*/
28+
public AirportOnTime onTime;
29+
30+
31+
/**
32+
* Constructor.
33+
* @hide
34+
*/
35+
public Predictions(Amadeus client) {
36+
this.onTime = new AirportOnTime(client);
37+
}
38+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.amadeus.airport.predictions;
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.OnTime;
8+
import com.amadeus.resources.Resource;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v1/airport/predictions/on-time</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.airport.predictions.onTime;</pre>
23+
*/
24+
public class AirportOnTime {
25+
private Amadeus client;
26+
27+
/**
28+
* Constructor.
29+
* @hide
30+
*/
31+
public AirportOnTime(Amadeus client) {
32+
this.client = client;
33+
}
34+
35+
/**
36+
* <p>
37+
* Returns a percentage of on-time flight from a given airport.
38+
* </p>
39+
*
40+
* <pre>
41+
* OnTime airportOnTime = amadeus.airport.predictions.onTime.get(Params
42+
* .with("airportCode", "NCE")
43+
* .and("date", "2020-09-01"));
44+
* </pre>
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 OnTime get(Params params) throws ResponseException {
50+
Response response = client.get("/v1/airport/predictions/on-time", params);
51+
return (OnTime) Resource.fromObject(response, OnTime.class);
52+
}
53+
54+
/**
55+
* Convenience method for calling <code>get</code> without any parameters.
56+
* @see AirportOnTime#get()
57+
*/
58+
public OnTime get() throws ResponseException {
59+
return get(null);
60+
}
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* An OnTime object as returned by the AirportOnTime API.
8+
* @see com.amadeus.airport.predictions.AirportOnTime#get()
9+
*/
10+
@ToString
11+
public class OnTime extends Resource {
12+
protected OnTime() {}
13+
14+
private @Getter String id;
15+
private @Getter String probability;
16+
private @Getter String result;
17+
private @Getter String subType;
18+
private @Getter String type;
19+
}

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

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

3+
import com.amadeus.airport.predictions.AirportOnTime;
34
import com.amadeus.ereputation.HotelSentiments;
45
import com.amadeus.exceptions.ResponseException;
56
import com.amadeus.referenceData.Airlines;
@@ -62,6 +63,7 @@ public void testAllNamespacesExist() {
6263
TestCase.assertNotNull(client.shopping.hotelOffersByHotel);
6364
TestCase.assertNotNull(client.ereputation.hotelSentiments);
6465
TestCase.assertNotNull(client.shopping.hotelOffer("XXX"));
66+
TestCase.assertNotNull(client.airport.predictions.onTime);
6567
}
6668

6769
@Before
@@ -281,6 +283,15 @@ public void testGetMethods() throws ResponseException {
281283
HotelSentiments hotelSentiments = new HotelSentiments(client);
282284
TestCase.assertNotNull(hotelSentiments.get(params));
283285

286+
// Test airport-on-time
287+
Mockito.when(client.get("/v1/airport/predictions/on-time", null))
288+
.thenReturn(singleResponse);
289+
Mockito.when(client.get("/v1/airport/predictions/on-time", params))
290+
.thenReturn(singleResponse);
291+
AirportOnTime airportOnTime = new AirportOnTime(client);
292+
TestCase.assertNotNull(airportOnTime.get());
293+
TestCase.assertNotNull(airportOnTime.get(params));
294+
284295
// Test flight delay predictions
285296
Mockito.when(client.get("/v1/travel/predictions/flight-delay", null))
286297
.thenReturn(multiResponse);

0 commit comments

Comments
 (0)