Skip to content

Commit d967030

Browse files
authored
Low-fare Search deco and update Flight Choice Prediction v2 (#73)
* update choice prediction version & deco LFS & update docs * add choiceProbability to FlightOffersSearch model * update date on readme * delete run file
1 parent 412a4fc commit d967030

File tree

6 files changed

+26
-227
lines changed

6 files changed

+26
-227
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,6 @@ FlightDate[] flightDates = amadeus.shopping.flightDates.get(Params
220220
.with("origin", "MAD")
221221
.and("destination", "MUC"));
222222

223-
// Flight Low-fare Search
224-
FlightOffer[] flightOffers = amadeus.shopping.flightOffers.get(Params
225-
.with("origin", "NYC")
226-
.and("destination", "MAD")
227-
.and("departureDate", "2020-04-01"));
228-
229223
// Flight Offers Search v2 GET
230224
FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.get(
231225
Params.with("originLocationCode", "SYD")
@@ -253,17 +247,21 @@ FlightPrice[] flightPricing = amadeus.shopping.flightOffersSearch.pricing.post(
253247
.and("forceClass", "false"));
254248

255249
// Flight Choice Prediction
256-
// Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction
257-
FlightOffer[] flightOffers = amadeus.shopping.flightOffers
258-
.get(Params.with("origin", "MAD").and("destination", "NYC").and("departureDate", "2020-08-01").and("max", "2"));
250+
// Note that the example calls 2 APIs: Flight Offers Search & Flight Choice Prediction
251+
FlightOfferSearch[] flightOffers = amadeus.shopping.flightOffersSearch.get(
252+
Params.with("originLocationCode", "NYC")
253+
.and("destinationLocationCode", "MAD")
254+
.and("departureDate", "2020-11-01")
255+
.and("returnDate", "2020-11-09")
256+
.and("adults", 1));
259257

260258
// Using a JSonObject
261259
JsonObject result = flightOffers[0].getResponse().getResult();
262-
FlightOffer[] flightOffersPrediction = amadeus.shopping.flightOffers.prediction.post(result);
260+
FlightOfferSearch[] flightOffersPrediction = amadeus.shopping.flightOffers.prediction.post(result);
263261

264262
// Using a String
265263
String body = flightOffers[0].getResponse().getBody();
266-
FlightOffer[] flightOffersPrediction = amadeus.shopping.flightOffers.prediction.post(body);
264+
FlightOfferSearch[] flightOffersPrediction = amadeus.shopping.flightOffers.prediction.post(body);
267265

268266
// Flight Check-in Links
269267
CheckinLink[] checkinLinks = amadeus.referenceData.urls.checkinLinks.get(Params

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

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ protected FlightOfferSearch() {}
2525
private @Getter PricingOptions pricingOptions;
2626
private @Getter String[] validatingAirlineCodes;
2727
private @Getter TravelerPricing[] travelerPricings;
28-
29-
28+
private @Getter String choiceProbability;
3029

3130
@ToString
3231
public class Itinerary {
Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package com.amadeus.shopping;
22

33
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.FlightOffer;
8-
import com.amadeus.resources.Resource;
94
import com.amadeus.shopping.flightOffers.Prediction;
10-
import com.google.gson.Gson;
115

126
/**
137
* <p>
@@ -36,31 +30,4 @@ public FlightOffers(Amadeus client) {
3630
this.prediction = new Prediction(client);
3731
}
3832

39-
/**
40-
* <p>
41-
* Find the cheapest bookable flights.
42-
* </p>
43-
*
44-
* <pre>
45-
* amadeus.shopping.flightOffers.get(Params
46-
* .with("origin", "LHR")
47-
* .and("destination", "LAX")
48-
* .and("departureDate", "2020-08-01"));</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 FlightOffer[] get(Params params) throws ResponseException {
55-
Response response = client.get("/v1/shopping/flight-offers", params);
56-
return (FlightOffer[]) Resource.fromArray(response, FlightOffer[].class);
57-
}
58-
59-
/**
60-
* Convenience method for calling <code>get</code> without any parameters.
61-
* @see FlightOffers#get()
62-
*/
63-
public FlightOffer[] get() throws ResponseException {
64-
return get(null);
65-
}
6633
}

src/main/java/com/amadeus/shopping/flightOffers/Prediction.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.amadeus.Amadeus;
44
import com.amadeus.Response;
55
import com.amadeus.exceptions.ResponseException;
6-
import com.amadeus.resources.FlightOffer;
6+
import com.amadeus.resources.FlightOfferSearch;
77
import com.amadeus.resources.Resource;
88

99
import com.google.gson.JsonObject;
@@ -15,7 +15,7 @@
1515
/**
1616
* <p>
1717
* A namespaced client for the
18-
* <code>/v1/shopping/flight-offers/prediction</code> endpoints.
18+
* <code>/v2/shopping/flight-offers/prediction</code> endpoints.
1919
* </p>
2020
*
2121
* <p>
@@ -41,9 +41,9 @@ public Prediction(Amadeus client) {
4141

4242
/**
4343
* <p>
44-
* This machine learning API is based on a prediction model that takes the response of a flight
45-
* search as input (Flight Low-fare Search) and predict, for each itinerary, the probably for a
46-
* travel to select it.
44+
* This Machine Learning API is based on a prediction model that takes the response of a flight
45+
* search as input (Flight Offers Search) and predicts, for each itinerary, the probability to
46+
* be selected.
4747
* </p>
4848
*
4949
* <pre>
@@ -53,16 +53,16 @@ public Prediction(Amadeus client) {
5353
* @return an API resource
5454
* @throws ResponseException when an exception occurs
5555
*/
56-
public FlightOffer[] post(JsonObject body) throws ResponseException {
57-
Response response = client.post("/v1/shopping/flight-offers/prediction", body);
58-
return (FlightOffer[]) Resource.fromArray(response, FlightOffer[].class);
56+
public FlightOfferSearch[] post(JsonObject body) throws ResponseException {
57+
Response response = client.post("/v2/shopping/flight-offers/prediction", body);
58+
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
5959
}
6060

6161
/**
6262
* <p>
6363
* This machine learning API is based on a prediction model that takes the response of a flight
64-
* search as input (Flight Low-fare Search) and predict, for each itinerary, the probably for a
65-
* travel to select it.
64+
* search as input (Flight Offers Search) and predicts, for each itinerary, the probability to
65+
* be selected.
6666
* </p>
6767
*
6868
* <pre>
@@ -72,17 +72,17 @@ public FlightOffer[] post(JsonObject body) throws ResponseException {
7272
* @return an API resource
7373
* @throws ResponseException when an exception occurs
7474
*/
75-
public FlightOffer[] post(String body) throws ResponseException {
76-
Response response = client.post("/v1/shopping/flight-offers/prediction", body);
77-
return (FlightOffer[]) Resource.fromArray(response, FlightOffer[].class);
75+
public FlightOfferSearch[] post(String body) throws ResponseException {
76+
Response response = client.post("/v2/shopping/flight-offers/prediction", body);
77+
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
7878
}
7979

8080
/**
8181
* Convenience method for calling <code>post</code> without any parameters.
8282
*
8383
* @see Prediction#post()
8484
*/
85-
public FlightOffer[] post() throws ResponseException {
85+
public FlightOfferSearch[] post() throws ResponseException {
8686
return post((String) null);
8787
}
8888
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,6 @@ public void testGetMethods() throws ResponseException {
229229
TestCase.assertNotNull(flightDestinations.get(params));
230230
TestCase.assertEquals(flightDestinations.get().length, 2);
231231

232-
// Testing flight offer search
233-
Mockito.when(client.get("/v1/shopping/flight-offers", null))
234-
.thenReturn(multiResponse);
235-
Mockito.when(client.get("/v1/shopping/flight-offers", params))
236-
.thenReturn(multiResponse);
237-
FlightOffers flightOffers = new FlightOffers(client);
238-
TestCase.assertNotNull(flightOffers.get());
239-
TestCase.assertNotNull(flightOffers.get(params));
240-
TestCase.assertEquals(flightOffers.get().length, 2);
241-
242232
// Testing hotel offer search
243233
Mockito.when(client.get("/v2/shopping/hotel-offers", null))
244234
.thenReturn(multiResponse);
@@ -338,9 +328,9 @@ public void testGetMethods() throws ResponseException {
338328
@Test
339329
public void testPostMethods() throws ResponseException {
340330
// Testing flight choice prediction
341-
Mockito.when(client.post("/v1/shopping/flight-offers/prediction", (String) null))
331+
Mockito.when(client.post("/v2/shopping/flight-offers/prediction", (String) null))
342332
.thenReturn(multiResponse);
343-
Mockito.when(client.post("/v1/shopping/flight-offers/prediction", body))
333+
Mockito.when(client.post("/v2/shopping/flight-offers/prediction", body))
344334
.thenReturn(multiResponse);
345335
Prediction flightOffersPrediction = new Prediction(client);
346336
TestCase.assertNotNull(flightOffersPrediction.post());

0 commit comments

Comments
 (0)