Skip to content

Commit a075523

Browse files
authored
Support for Flight Delay Prediction (#48)
* initial commit for flight delay prediction * fix build errors * fix syntax error readme * add tests * update test * fix typo
1 parent b5a74c3 commit a075523

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,18 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt
325325
.and("west", "2.160873")
326326
.and("south", "41.394582")
327327
.and("east", "2.177181"));
328+
329+
Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
330+
.with("originLocationCode", "NCE")
331+
.and("destinationLocationCode", "IST")
332+
.and("departureDate", "2020-08-01")
333+
.and("departureTime", "18:20:00")
334+
.and("arrivalDate", "2020-08-01")
335+
.and("arrivalTime", "22:15:00")
336+
.and("aircraftCode", "321")
337+
.and("carrierCode", "TK")
338+
.and("flightNumber", "1816")
339+
.and("duration", "PT31H10M"));
328340
```
329341

330342
## Development & Contributing

src/main/java/com/amadeus/Travel.java

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

33
import com.amadeus.travel.analytics.Analytics;
4+
import com.amadeus.travel.predictions.Predictions;
45

56
/**
67
* <p>
@@ -26,12 +27,20 @@ public class Travel {
2627
* </p>
2728
*/
2829
public Analytics analytics;
30+
/**
31+
* <p>
32+
* A namespaced client for the
33+
* <code>/v1/travel/predictions</code> endpoints.
34+
* </p>
35+
*/
36+
public Predictions predictions;
2937

3038
/**
3139
* Constructor.
3240
* @hide
3341
*/
3442
public Travel(Amadeus client) {
3543
this.analytics = new Analytics(client);
44+
this.predictions = new Predictions(client);
3645
}
3746
}
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+
* A Delay object as returned by the FlightDelay API.
8+
* @see com.amadeus.travel.predictions.FlightDelay#get()
9+
*/
10+
@ToString
11+
public class Delay extends Resource {
12+
protected Delay() {}
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+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.amadeus.travel.predictions;
2+
3+
import com.amadeus.Amadeus;
4+
5+
/**
6+
* <p>
7+
* A namespaced client for the
8+
* <code>/v1/travel/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.travel.predictions;</pre>
18+
*
19+
* @hide
20+
*/
21+
public class Predictions {
22+
/**
23+
* <p>
24+
* A namespaced client for the
25+
* <code>/v1/travel/predictions/flight-delay</code> endpoints.
26+
* </p>
27+
*/
28+
public FlightDelay flightDelay;
29+
30+
31+
/**
32+
* Constructor.
33+
* @hide
34+
*/
35+
public Predictions(Amadeus client) {
36+
this.flightDelay = new FlightDelay(client);
37+
}
38+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.amadeus.travel.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.Delay;
8+
import com.amadeus.resources.Resource;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v1/travel/predictions/flight-delay</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.travel.predictions.flightDelay;</pre>
23+
*/
24+
public class FlightDelay {
25+
private Amadeus client;
26+
27+
/**
28+
* Constructor.
29+
* @hide
30+
*/
31+
public FlightDelay(Amadeus client) {
32+
this.client = client;
33+
}
34+
35+
/**
36+
* <p>
37+
* Predicts delay of a given flight.
38+
* </p>
39+
*
40+
* <pre>
41+
* Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
42+
* .with("originLocationCode", "NCE")
43+
* .and("destinationLocationCode", "IST")
44+
* .and("departureDate", "2020-08-01")
45+
* .and("departureTime", "18:20:00"))
46+
* .and("arrivalDate", "2020-08-01")
47+
* .and("arrivalTime", "22:15:00")
48+
* .and("aircraftCode", "321"))
49+
* .and("carrierCode", "TK")
50+
* .and("flightNumber", "1816")
51+
* .and("duration", "PT31H10M"));
52+
* </pre>
53+
* @param params the parameters to send to the API
54+
* @return an API response object
55+
* @throws ResponseException when an exception occurs
56+
*/
57+
public Delay[] get(Params params) throws ResponseException {
58+
Response response = client.get("/v1/travel/predictions/flight-delay", params);
59+
return (Delay[]) Resource.fromArray(response, Delay[].class);
60+
}
61+
62+
/**
63+
* Convenience method for calling <code>get</code> without any parameters.
64+
* @see FlightDelay#get()
65+
*/
66+
public Delay[] get() throws ResponseException {
67+
return get(null);
68+
}
69+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.amadeus.referenceData.locations.Airports;
99
import com.amadeus.referenceData.locations.PointsOfInterest;
1010
import com.amadeus.referenceData.urls.CheckinLinks;
11+
import com.amadeus.resources.Delay;
1112
import com.amadeus.shopping.FlightDates;
1213
import com.amadeus.shopping.FlightDestinations;
1314
import com.amadeus.shopping.FlightOffers;
@@ -21,6 +22,7 @@
2122
import com.amadeus.travel.analytics.airTraffic.Searched;
2223
import com.amadeus.travel.analytics.airTraffic.SearchedByDestination;
2324
import com.amadeus.travel.analytics.airTraffic.Traveled;
25+
import com.amadeus.travel.predictions.FlightDelay;
2426
import com.google.gson.JsonArray;
2527
import com.google.gson.JsonObject;
2628
import junit.framework.TestCase;
@@ -50,6 +52,7 @@ public void testAllNamespacesExist() {
5052
TestCase.assertNotNull(client.travel.analytics.airTraffic.booked);
5153
TestCase.assertNotNull(client.travel.analytics.airTraffic.searched);
5254
TestCase.assertNotNull(client.travel.analytics.airTraffic.searchedByDestination);
55+
TestCase.assertNotNull(client.travel.predictions.flightDelay);
5356
TestCase.assertNotNull(client.shopping.flightDates);
5457
TestCase.assertNotNull(client.shopping.flightDestinations);
5558
TestCase.assertNotNull(client.shopping.flightOffers);
@@ -277,6 +280,15 @@ public void testGetMethods() throws ResponseException {
277280
.thenReturn(multiResponse);
278281
HotelSentiments hotelSentiments = new HotelSentiments(client);
279282
TestCase.assertNotNull(hotelSentiments.get(params));
283+
284+
// Test flight delay predictions
285+
Mockito.when(client.get("/v1/travel/predictions/flight-delay", null))
286+
.thenReturn(multiResponse);
287+
Mockito.when(client.get("/v1/travel/predictions/flight-delay", params))
288+
.thenReturn(multiResponse);
289+
FlightDelay flightDelay = new FlightDelay(client);
290+
TestCase.assertNotNull(flightDelay.get());
291+
TestCase.assertNotNull(flightDelay.get(params));
280292
}
281293

282294
@Test

0 commit comments

Comments
 (0)