Skip to content

Commit cad0689

Browse files
authored
DRAFT: Adding support for Trip Purpose Prediction API (#36)
* Adding support for Trip Purpose Prediction API * Fix comments on PR + solve merge conflicts * Fix comments on PR + solve merge conflicts * Refactor Flight Delay Prediction and Airport-On Time performance
1 parent e241504 commit cad0689

File tree

10 files changed

+125
-49
lines changed

10 files changed

+125
-49
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ build
88
out
99
.DS_Store
1010
amadeus-java.iml
11-
Bin/
11+
Bin/
12+
.vscode/

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,14 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt
315315
.and("west", "2.160873")
316316
.and("south", "41.394582")
317317
.and("east", "2.177181"));
318-
318+
319319
// What's the likelihood flights from this airport will leave on time?
320-
OnTime AirportOnTime = amadeus.airport.predictions.onTime.get(Params
320+
Prediction AirportOnTime = amadeus.airport.predictions.onTime.get(Params
321321
.with("airportCode", "NCE")
322-
.and("date", "2020-09-01"));
322+
.and("date", "2020-09-01"));
323323

324324
// What's the likelihood of a given flight to be delayed?
325-
Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
325+
Prediction[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
326326
.with("originLocationCode", "NCE")
327327
.and("destinationLocationCode", "IST")
328328
.and("departureDate", "2020-08-01")
@@ -353,6 +353,13 @@ SeatMap[] seatmap = amadeus.shopping.seatMaps.post(body);
353353
// AI-Generated Photos
354354
GeneratedPhoto photo = amadeus.media.files.generatedPhotos.get(Params
355355
.with("category", "BEACH"));
356+
357+
// Trip Purpose Prediction
358+
Prediction tripPurpose = amadeus.travel.predictions.tripPurpose.get(Params
359+
.with("originLocationCode", "NYC")
360+
.and("destinationLocationCode", "MAD")
361+
.and("departureDate", "2020-08-01")
362+
.and("returnDate", "2020-08-12"));
356363
```
357364

358365
## Development & Contributing

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.amadeus;
22

3+
import com.amadeus.travel.Predictions;
34
import com.amadeus.travel.analytics.Analytics;
4-
import com.amadeus.travel.predictions.Predictions;
55

66
/**
77
* <p>

src/main/java/com/amadeus/airport/predictions/AirportOnTime.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.amadeus.Params;
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
7-
import com.amadeus.resources.OnTime;
7+
import com.amadeus.resources.Prediction;
88
import com.amadeus.resources.Resource;
99

1010
/**
@@ -46,16 +46,16 @@ public AirportOnTime(Amadeus client) {
4646
* @return an API response object
4747
* @throws ResponseException when an exception occurs
4848
*/
49-
public OnTime get(Params params) throws ResponseException {
49+
public Prediction get(Params params) throws ResponseException {
5050
Response response = client.get("/v1/airport/predictions/on-time", params);
51-
return (OnTime) Resource.fromObject(response, OnTime.class);
51+
return (Prediction) Resource.fromObject(response, Prediction.class);
5252
}
5353

5454
/**
5555
* Convenience method for calling <code>get</code> without any parameters.
5656
* @see AirportOnTime#get()
5757
*/
58-
public OnTime get() throws ResponseException {
58+
public Prediction get() throws ResponseException {
5959
return get(null);
6060
}
6161
}

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/java/com/amadeus/resources/Delay.java renamed to src/main/java/com/amadeus/resources/Prediction.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
import lombok.ToString;
55

66
/**
7-
* A Delay object as returned by the FlightDelay API.
8-
* @see com.amadeus.travel.predictions.FlightDelay#get()
7+
* An Period object as returned by the Prediction APIs.
8+
*
9+
* @see com.amadeus.travel.predictions.TripPurpose#get()
910
*/
1011
@ToString
11-
public class Delay extends Resource {
12-
protected Delay() {}
12+
public class Prediction extends Resource {
13+
protected Prediction() {
14+
}
1315

16+
private @Getter String type;
17+
private @Getter String subType;
1418
private @Getter String id;
15-
private @Getter String probability;
1619
private @Getter String result;
17-
private @Getter String subType;
18-
private @Getter String type;
20+
private @Getter String probability;
1921
}

src/main/java/com/amadeus/travel/Predictions.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
package com.amadeus.travel.predictions;
1+
package com.amadeus.travel;
22

33
import com.amadeus.Amadeus;
4+
import com.amadeus.travel.predictions.FlightDelay;
5+
import com.amadeus.travel.predictions.TripPurpose;
46

57
/**
68
* <p>
@@ -21,18 +23,25 @@
2123
public class Predictions {
2224
/**
2325
* <p>
24-
* A namespaced client for the
26+
* A namespaced client for the
27+
* <code>/v1/travel/predictions/trip-purpose</code> endpoints.
28+
* </p>
29+
*/
30+
public TripPurpose tripPurpose;
31+
32+
/** A namespaced client for the
2533
* <code>/v1/travel/predictions/flight-delay</code> endpoints.
2634
* </p>
2735
*/
2836
public FlightDelay flightDelay;
2937

30-
3138
/**
3239
* Constructor.
40+
*
3341
* @hide
3442
*/
3543
public Predictions(Amadeus client) {
44+
this.tripPurpose = new TripPurpose(client);
3645
this.flightDelay = new FlightDelay(client);
3746
}
3847
}

src/main/java/com/amadeus/travel/predictions/FlightDelay.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.amadeus.Params;
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
7-
import com.amadeus.resources.Delay;
7+
import com.amadeus.resources.Prediction;
88
import com.amadeus.resources.Resource;
99

1010
/**
@@ -54,16 +54,16 @@ public FlightDelay(Amadeus client) {
5454
* @return an API response object
5555
* @throws ResponseException when an exception occurs
5656
*/
57-
public Delay[] get(Params params) throws ResponseException {
57+
public Prediction[] get(Params params) throws ResponseException {
5858
Response response = client.get("/v1/travel/predictions/flight-delay", params);
59-
return (Delay[]) Resource.fromArray(response, Delay[].class);
59+
return (Prediction[]) Resource.fromArray(response, Prediction[].class);
6060
}
6161

6262
/**
6363
* Convenience method for calling <code>get</code> without any parameters.
6464
* @see FlightDelay#get()
6565
*/
66-
public Delay[] get() throws ResponseException {
66+
public Prediction[] get() throws ResponseException {
6767
return get(null);
6868
}
6969
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.Prediction;
8+
import com.amadeus.resources.Resource;
9+
10+
11+
/**
12+
* <p>
13+
* A namespaced client for the
14+
* <code>/v1/travel/predictions/trip-purpose</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.travel.predictions.tripPurpose;</pre>
24+
*/
25+
public class TripPurpose {
26+
private Amadeus client;
27+
28+
/**
29+
* Constructor.
30+
*
31+
* @hide
32+
*/
33+
public TripPurpose(Amadeus client) {
34+
this.client = client;
35+
}
36+
37+
/**
38+
* <p>
39+
* Returns a trip purpose prediction.
40+
* </p>
41+
*
42+
* <pre>
43+
* amadeus.travel.predictions.tripPurpose.get(Params
44+
* .with("originLocationCode", "NYC")
45+
* .and("destinationLocationCode", "MAD")
46+
* .and("departureDate", "2020-08-01")
47+
* .and("returnDate", "2020-08-12"));
48+
* </pre>
49+
*
50+
* @param params the parameters to send to the API
51+
* @return an API response object
52+
* @throws ResponseException when an exception occurs
53+
*/
54+
public Prediction get(Params params) throws ResponseException {
55+
Response response = client.get("/v1/travel/predictions/trip-purpose", params);
56+
return (Prediction) Resource.fromObject(response, Prediction.class);
57+
}
58+
59+
/**
60+
* Convenience method for calling <code>get</code> without any parameters.
61+
*
62+
* @see TripPurpose#get()
63+
*/
64+
public Prediction get() throws ResponseException {
65+
return get(null);
66+
}
67+
}

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.amadeus.travel.analytics.airTraffic.BusiestPeriod;
2626
import com.amadeus.travel.analytics.airTraffic.Traveled;
2727
import com.amadeus.travel.predictions.FlightDelay;
28+
import com.amadeus.travel.predictions.TripPurpose;
2829
import com.google.gson.JsonArray;
2930
import com.google.gson.JsonObject;
3031
import junit.framework.TestCase;
@@ -52,6 +53,7 @@ public void testAllNamespacesExist() {
5253
TestCase.assertNotNull(client.referenceData.airlines);
5354
TestCase.assertNotNull(client.travel.analytics.airTraffic.traveled);
5455
TestCase.assertNotNull(client.travel.analytics.airTraffic.booked);
56+
TestCase.assertNotNull(client.travel.predictions.tripPurpose);
5557
TestCase.assertNotNull(client.travel.predictions.flightDelay);
5658
TestCase.assertNotNull(client.shopping.flightDates);
5759
TestCase.assertNotNull(client.shopping.flightDestinations);
@@ -266,15 +268,22 @@ public void testGetMethods() throws ResponseException {
266268
HotelSentiments hotelSentiments = new HotelSentiments(client);
267269
TestCase.assertNotNull(hotelSentiments.get(params));
268270

269-
// Test airport-on-time
271+
// Test trip purpose prediction
272+
Mockito.when(client.get("/v1/travel/predictions/trip-purpose", null))
273+
.thenReturn(singleResponse);
274+
Mockito.when(client.get("/v1/travel/predictions/trip-purpose", params))
275+
.thenReturn(singleResponse);
276+
TripPurpose tripPurpose = new TripPurpose(client);
277+
TestCase.assertNotNull(tripPurpose.get(params));
278+
// Test airport-on-time
270279
Mockito.when(client.get("/v1/airport/predictions/on-time", null))
271280
.thenReturn(singleResponse);
272281
Mockito.when(client.get("/v1/airport/predictions/on-time", params))
273282
.thenReturn(singleResponse);
274283
AirportOnTime airportOnTime = new AirportOnTime(client);
275284
TestCase.assertNotNull(airportOnTime.get());
276285
TestCase.assertNotNull(airportOnTime.get(params));
277-
286+
278287
// Test flight delay predictions
279288
Mockito.when(client.get("/v1/travel/predictions/flight-delay", null))
280289
.thenReturn(multiResponse);
@@ -290,8 +299,8 @@ public void testGetMethods() throws ResponseException {
290299
Mockito.when(client.get("/v1/shopping/seatmaps", params))
291300
.thenReturn(multiResponse);
292301
SeatMaps seatmap = new SeatMaps(client);
293-
TestCase.assertNotNull(seatmap.get(params));
294-
302+
TestCase.assertNotNull(seatmap.get(params));
303+
295304
// Test fetching a specific offer
296305
Mockito.when(client.get("/v1/booking/flight-orders/XXX", null))
297306
.thenReturn(singleResponse);
@@ -339,11 +348,11 @@ public void testPostMethods() throws ResponseException {
339348
Mockito.when(client.post("/v1/booking/flight-orders", (String) null))
340349
.thenReturn(singleResponse);
341350
Mockito.when(client.post("/v1/booking/flight-orders", body))
342-
.thenReturn(singleResponse);
351+
.thenReturn(singleResponse);
343352
FlightOrders order = new FlightOrders(client);
344353
TestCase.assertNotNull(order.post());
345354
TestCase.assertNotNull(order.post(body));
346-
355+
347356
// Test SeatMaps post
348357
Mockito.when(client.post("/v1/shopping/seatmaps", (String) null))
349358
.thenReturn(multiResponse);

0 commit comments

Comments
 (0)