Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Flight Delay Prediction #48

Merged
merged 6 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt
.and("west", "2.160873")
.and("south", "41.394582")
.and("east", "2.177181"));

Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
.with("originLocationCode", "NCE")
.and("destinationLocationCode", "IST")
.and("departureDate", "2020-08-01")
.and("departureTime", "18:20:00")
.and("arrivalDate", "2020-08-01")
.and("arrivalTime", "22:15:00")
.and("aircraftCode", "321")
.and("carrierCode", "TK")
.and("flightNumber", "1816")
.and("duration", "PT31H10M"));
```

## Development & Contributing
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/amadeus/Travel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.amadeus;

import com.amadeus.travel.analytics.Analytics;
import com.amadeus.travel.predictions.Predictions;

/**
* <p>
Expand All @@ -26,12 +27,20 @@ public class Travel {
* </p>
*/
public Analytics analytics;
/**
* <p>
* A namespaced client for the
* <code>/v1/travel/predictions</code> endpoints.
* </p>
*/
public Predictions predictions;

/**
* Constructor.
* @hide
*/
public Travel(Amadeus client) {
this.analytics = new Analytics(client);
this.predictions = new Predictions(client);
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/amadeus/resources/Delay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.amadeus.resources;

import lombok.Getter;
import lombok.ToString;

/**
* A Delay object as returned by the FlightDelay API.
* @see com.amadeus.travel.predictions.FlightDelay#get()
*/
@ToString
public class Delay extends Resource {
protected Delay() {}

private @Getter String id;
private @Getter String probability;
private @Getter String result;
private @Getter String subType;
private @Getter String type;
}
38 changes: 38 additions & 0 deletions src/main/java/com/amadeus/travel/Predictions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.amadeus.travel.predictions;

import com.amadeus.Amadeus;

/**
* <p>
* A namespaced client for the
* <code>/v1/travel/predictions</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.travel.analytics;</pre>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

travel.predictions

*
* @hide
*/
public class Predictions {
/**
* <p>
* A namespaced client for the
* <code>/v1/travel/predictions/flight-delay</code> endpoints.
* </p>
*/
public FlightDelay flightDelay;


/**
* Constructor.
* @hide
*/
public Predictions(Amadeus client) {
this.flightDelay = new FlightDelay(client);
}
}
69 changes: 69 additions & 0 deletions src/main/java/com/amadeus/travel/predictions/FlightDelay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.amadeus.travel.predictions;

import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.Response;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.Delay;
import com.amadeus.resources.Resource;

/**
* <p>
* A namespaced client for the
* <code>/v1/travel/predictions/flight-delay</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.travel.predictions.flightDelay;</pre>
*/
public class FlightDelay {
private Amadeus client;

/**
* Constructor.
* @hide
*/
public FlightDelay(Amadeus client) {
this.client = client;
}

/**
* <p>
* Predicts delay of a given flight.
* </p>
*
* <pre>
* Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
* .with("originLocationCode", "NCE")
* .and("destinationLocationCode", "IST")
* .and("departureDate", "2020-08-01")
* .and("departureTime", "18:20:00"))
* .and("arrivalDate", "2020-08-01")
* .and("arrivalTime", "22:15:00")
* .and("aircraftCode", "321"))
* .and("carrierCode", "TK")
* .and("flightNumber", "1816")
* .and("duration", "PT31H10M"));
* </pre>
* @param params the parameters to send to the API
* @return an API response object
* @throws ResponseException when an exception occurs
*/
public Delay[] get(Params params) throws ResponseException {
Response response = client.get("/v1/travel/predictions/flight-delay", params);
return (Delay[]) Resource.fromArray(response, Delay[].class);
}

/**
* Convenience method for calling <code>get</code> without any parameters.
* @see FlightDelay#get()
*/
public Delay[] get() throws ResponseException {
return get(null);
}
}
12 changes: 12 additions & 0 deletions src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.amadeus.referenceData.locations.Airports;
import com.amadeus.referenceData.locations.PointsOfInterest;
import com.amadeus.referenceData.urls.CheckinLinks;
import com.amadeus.resources.Delay;
import com.amadeus.shopping.FlightDates;
import com.amadeus.shopping.FlightDestinations;
import com.amadeus.shopping.FlightOffers;
Expand All @@ -21,6 +22,7 @@
import com.amadeus.travel.analytics.airTraffic.Searched;
import com.amadeus.travel.analytics.airTraffic.SearchedByDestination;
import com.amadeus.travel.analytics.airTraffic.Traveled;
import com.amadeus.travel.predictions.FlightDelay;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import junit.framework.TestCase;
Expand Down Expand Up @@ -50,6 +52,7 @@ public void testAllNamespacesExist() {
TestCase.assertNotNull(client.travel.analytics.airTraffic.booked);
TestCase.assertNotNull(client.travel.analytics.airTraffic.searched);
TestCase.assertNotNull(client.travel.analytics.airTraffic.searchedByDestination);
TestCase.assertNotNull(client.travel.predictions.flightDelay);
TestCase.assertNotNull(client.shopping.flightDates);
TestCase.assertNotNull(client.shopping.flightDestinations);
TestCase.assertNotNull(client.shopping.flightOffers);
Expand Down Expand Up @@ -277,6 +280,15 @@ public void testGetMethods() throws ResponseException {
.thenReturn(multiResponse);
HotelSentiments hotelSentiments = new HotelSentiments(client);
TestCase.assertNotNull(hotelSentiments.get(params));

// Test flight delay predictions
Mockito.when(client.get("/v1/travel/predictions/flight-delay", null))
.thenReturn(multiResponse);
Mockito.when(client.get("/v1/travel/predictions/flight-delay", params))
.thenReturn(multiResponse);
FlightDelay flightDelay = new FlightDelay(client);
TestCase.assertNotNull(flightDelay.get());
TestCase.assertNotNull(flightDelay.get(params));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other unit test we check that the response's length is 2... I dont really remember why and if it is very useful... TestCase.assertEquals(flightOffersPrediction.post().length, 2);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I had this check, but I removed it because I didn't know if it was relevant to this test case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be honest, I am not sure either...

}

@Test
Expand Down