From 8174e37b21526a50686e1cab99362574657667ab Mon Sep 17 00:00:00 2001 From: Sealsoft Date: Wed, 23 Oct 2019 16:42:40 +0300 Subject: [PATCH 01/22] introduce flight pricing api --- src/main/java/com/amadeus/HTTPClient.java | 48 +++++++++++ .../com/amadeus/resources/FlightPrice.java | 13 +++ .../amadeus/shopping/FlightOffersSearch.java | 3 + .../shopping/flightOffers/Pricing.java | 80 +++++++++++++++++++ src/test/java/com/amadeus/NamespaceTest.java | 14 ++++ 5 files changed, 158 insertions(+) create mode 100644 src/main/java/com/amadeus/resources/FlightPrice.java create mode 100644 src/main/java/com/amadeus/shopping/flightOffers/Pricing.java diff --git a/src/main/java/com/amadeus/HTTPClient.java b/src/main/java/com/amadeus/HTTPClient.java index 1faf2645..622076f7 100644 --- a/src/main/java/com/amadeus/HTTPClient.java +++ b/src/main/java/com/amadeus/HTTPClient.java @@ -154,6 +154,54 @@ public Response post(String path, JsonObject body) throws ResponseException { return request(Constants.POST, path, null, body.toString()); } + /** + *

+ * A helper module for making generic POST requests calls. It is used by + * every namespaced API POST method. + *

+ * + *

+ * It can be used to make any generic API call that is automatically + * authenticated using your API credentials: + *

+ * + *
+   *    amadeus.post("/v1/foo/bar", Params.with("airline", "1X"), { "foo" : "bar" })
+   * 
+ * + * @param path The full path for the API call + * @param params The optional POST params to pass to the API + * @param body The POST JsonObject body to pass to the API + * @return a Response object containing the status code, body, and parsed data. + */ + public Response post(String path, Params params, JsonObject body) throws ResponseException { + return request(Constants.POST, path, params, body.toString()); + } + + /** + *

+ * A helper module for making generic POST requests calls. It is used by + * every namespaced API POST method. + *

+ * + *

+ * It can be used to make any generic API call that is automatically + * authenticated using your API credentials: + *

+ * + *
+   *    amadeus.post("/v1/foo/bar", Params.with("airline", "1X"), { "foo" : "bar" })
+   * 
+ * + * @param path The full path for the API call + * @param params The optional POST params to pass to the API + * @param body The POST String object body to pass to the API + * @return a Response object containing the status code, body, and parsed data. + */ + public Response post(String path, Params params, String body) throws ResponseException { + return request(Constants.POST, path, params, body.toString()); + } + /** * A generic method for making any authenticated or unauthenticated request, * passing in the bearer token explicitly. Used primarily by the diff --git a/src/main/java/com/amadeus/resources/FlightPrice.java b/src/main/java/com/amadeus/resources/FlightPrice.java new file mode 100644 index 00000000..a232342c --- /dev/null +++ b/src/main/java/com/amadeus/resources/FlightPrice.java @@ -0,0 +1,13 @@ +package com.amadeus.resources; + +import lombok.Getter; +import lombok.ToString; + +@ToString +public class FlightPrice extends Resource { + + private @Getter String type; + private @Getter FlightOfferSearch[] flightOffers; + private @Getter Object flightRequirements; + +} diff --git a/src/main/java/com/amadeus/shopping/FlightOffersSearch.java b/src/main/java/com/amadeus/shopping/FlightOffersSearch.java index c0448d58..a95e911e 100644 --- a/src/main/java/com/amadeus/shopping/FlightOffersSearch.java +++ b/src/main/java/com/amadeus/shopping/FlightOffersSearch.java @@ -6,6 +6,7 @@ import com.amadeus.exceptions.ResponseException; import com.amadeus.resources.FlightOfferSearch; import com.amadeus.resources.Resource; +import com.amadeus.shopping.flightOffers.Pricing; import com.google.gson.JsonObject; /** @@ -24,6 +25,7 @@ */ public class FlightOffersSearch { private Amadeus client; + public Pricing pricing; /** * Constructor. @@ -32,6 +34,7 @@ public class FlightOffersSearch { */ public FlightOffersSearch(Amadeus client) { this.client = client; + this.pricing = new Pricing(client); } /** diff --git a/src/main/java/com/amadeus/shopping/flightOffers/Pricing.java b/src/main/java/com/amadeus/shopping/flightOffers/Pricing.java new file mode 100644 index 00000000..c552db0f --- /dev/null +++ b/src/main/java/com/amadeus/shopping/flightOffers/Pricing.java @@ -0,0 +1,80 @@ +package com.amadeus.shopping.flightOffers; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.Response; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.FlightPrice; +import com.amadeus.resources.Resource; +import com.google.gson.JsonObject; + +/** + *

+ * A namespaced client for the + * /v1/shopping/flight-offers/pricing endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder(API_KEY, API_SECRET).build();
+ * amadeus.shopping.flightOffers.pricing;
+ */ +public class Pricing { + + private Amadeus client; + + /** + * Constructor. + * + * @hide + */ + public Pricing(Amadeus client) { + this.client = client; + } + + /** + *

+ * The Flight Offers Price REST/JSON API is an open price API that enables + * you to get or confirm the price of a flight and obtain information + * about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. It also retrieves + * ancillary information (e.g. additional bag or extra legroom seats pricing) + * and the payment information details requested at booking time. + *

+ * + *
+   * amadeus.shopping.flightOffers.pricing.post(body, params);
+ * + * @param body the parameters to send to the API as a String + * @param params the parameters to send to the API + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightPrice[] post(JsonObject body, Params params) throws ResponseException { + Response response = client.post("/v1/shopping/flight-offers/pricing", params, body); + return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + } + + public FlightPrice[] post(String body, Params params) throws ResponseException { + Response response = client.post("/v1/shopping/flight-offers/pricing", params, body); + return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + } + + + public FlightPrice[] post(JsonObject body) throws ResponseException { + Response response = client.post("/v1/shopping/flight-offers/pricing", body); + return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + } + + public FlightPrice[] post(String body) throws ResponseException { + Response response = client.post("/v1/shopping/flight-offers/pricing", body); + return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + } + + public FlightPrice[] post() throws ResponseException { + return post((String) null); + } +} diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index 51e805fd..a6c887fb 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -16,6 +16,7 @@ import com.amadeus.shopping.HotelOffers; import com.amadeus.shopping.HotelOffersByHotel; import com.amadeus.shopping.flightOffers.Prediction; +import com.amadeus.shopping.flightOffers.Pricing; import com.amadeus.travel.analytics.airTraffic.Booked; import com.amadeus.travel.analytics.airTraffic.BusiestPeriod; import com.amadeus.travel.analytics.airTraffic.Searched; @@ -54,6 +55,7 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.shopping.flightDestinations); TestCase.assertNotNull(client.shopping.flightOffers); TestCase.assertNotNull(client.shopping.flightOffersSearch); + TestCase.assertNotNull(client.shopping.flightOffersSearch.pricing); TestCase.assertNotNull(client.shopping.flightOffers.prediction); TestCase.assertNotNull(client.shopping.hotelOffers); TestCase.assertNotNull(client.shopping.hotelOffersByHotel); @@ -302,5 +304,17 @@ public void testPostMethods() throws ResponseException { TestCase.assertNotNull(flightOfferSearch.post()); TestCase.assertNotNull(flightOfferSearch.post(body)); TestCase.assertEquals(flightOfferSearch.post().length, 2); + + // Test flight price + Mockito.when(client.post("/v1/shopping/flight-offers/pricing", (String) null)) + .thenReturn(multiResponse); + Mockito.when(client.post("/v1/shopping/flight-offers/pricing", body)) + .thenReturn(multiResponse); + Mockito.when(client.post("/v1/shopping/flight-offers/pricing", params, jsonObject)) + .thenReturn(multiResponse); + Pricing pricing = new Pricing(client); + TestCase.assertNotNull(pricing.post()); + TestCase.assertNotNull(pricing.post(body)); + TestCase.assertEquals(pricing.post().length, 2); } } From eaac4cb174c8bf093dc34c70fb1fd99aefe8c5af Mon Sep 17 00:00:00 2001 From: Sealsoft Date: Wed, 23 Oct 2019 17:30:08 +0300 Subject: [PATCH 02/22] populate README for pricing request --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 97c901c9..57835af4 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,12 @@ FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.g // body can be a String version of your JSON or a JsonObject FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.post(body); +// Flight Offer price +FlightPrice[] flightPricing = amadeus.shopping.flightOffersSearch.pricing.post( + body, + Params.with("include", "other-services") + .and("forceClass", "false")) + // Flight Choice Prediction // Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction FlightOffer[] flightOffers = amadeus.shopping.flightOffers From c6bbf7dd3f81a264ac604aeeca486204866288af Mon Sep 17 00:00:00 2001 From: Anthony Roux Date: Tue, 5 Nov 2019 13:00:52 +0100 Subject: [PATCH 03/22] Adding other methods for Price API. Fixing the POST version with query params on going --- src/main/java/com/amadeus/HTTPClient.java | 19 +- src/main/java/com/amadeus/Request.java | 2 +- .../com/amadeus/resources/FlightPayment.java | 17 ++ .../com/amadeus/resources/FlightPrice.java | 32 +++- .../shopping/flightOffers/Pricing.java | 174 ++++++++++++++++-- src/test/java/com/amadeus/HTTPClientTest.java | 36 ++-- src/test/java/com/amadeus/NamespaceTest.java | 7 +- src/test/java/com/amadeus/RequestTest.java | 2 +- 8 files changed, 245 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/amadeus/resources/FlightPayment.java diff --git a/src/main/java/com/amadeus/HTTPClient.java b/src/main/java/com/amadeus/HTTPClient.java index 622076f7..a1bbe5bc 100644 --- a/src/main/java/com/amadeus/HTTPClient.java +++ b/src/main/java/com/amadeus/HTTPClient.java @@ -340,8 +340,23 @@ private Request fetch(Request request) throws NetworkException { // Writes the parameters to the request. private void write(Request request) throws IOException { + // POST with access token + body + URL parameters + if (request.getVerb() == Constants.POST && request.getParams() != null + && request.getBearerToken() != null) { + OutputStream os = request.getConnection().getOutputStream(); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); + // writer.write(request.getParams().toQueryString()); + if (request.getBody() != null) { + writer.write(request.getBody()); + } + writer.flush(); + writer.close(); + os.close(); + } - if (request.getVerb() == Constants.POST && request.getParams() != null) { + // POST with access without token (authentication call) + if (request.getVerb() == Constants.POST && request.getParams() != null + && request.getBearerToken() == null) { OutputStream os = request.getConnection().getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(request.getParams().toQueryString()); @@ -349,6 +364,8 @@ private void write(Request request) throws IOException { writer.close(); os.close(); } + + // POST with access token + body if (request.getVerb() == Constants.POST && request.getParams() == null) { OutputStream os = request.getConnection().getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); diff --git a/src/main/java/com/amadeus/Request.java b/src/main/java/com/amadeus/Request.java index 6d1dca65..776df60f 100644 --- a/src/main/java/com/amadeus/Request.java +++ b/src/main/java/com/amadeus/Request.java @@ -157,7 +157,7 @@ private String buildUserAgent() { // Gets the serialized params, only if this is a Get call private String getQueryParams() { - if (verb == Constants.GET && params != null) { + if (params != null) { return params.toQueryString(); } else { return ""; diff --git a/src/main/java/com/amadeus/resources/FlightPayment.java b/src/main/java/com/amadeus/resources/FlightPayment.java new file mode 100644 index 00000000..237bcc57 --- /dev/null +++ b/src/main/java/com/amadeus/resources/FlightPayment.java @@ -0,0 +1,17 @@ +package com.amadeus.resources; + +import lombok.Getter; +import lombok.ToString; + +/** + * An Airline object as returned by the Airline Code LookUp API. + * @see amadeus.shopping.flightOffersSearch.pricing#post() + */ +@ToString +public class FlightPayment extends Resource { + protected FlightPayment() {} + + private @Getter String brand; + private @Getter Integer binNumber; + private @Getter String[] flightOfferIds; +} diff --git a/src/main/java/com/amadeus/resources/FlightPrice.java b/src/main/java/com/amadeus/resources/FlightPrice.java index a232342c..52eac76b 100644 --- a/src/main/java/com/amadeus/resources/FlightPrice.java +++ b/src/main/java/com/amadeus/resources/FlightPrice.java @@ -5,9 +5,39 @@ @ToString public class FlightPrice extends Resource { + protected FlightPrice() {} private @Getter String type; private @Getter FlightOfferSearch[] flightOffers; - private @Getter Object flightRequirements; + private @Getter BookingRequirements bookingRequirements; + + @ToString + public class BookingRequirements { + protected BookingRequirements() {} + + private @Getter Boolean invoiceAddressRequired; + private @Getter Boolean mailingAddressRequired; + private @Getter Boolean emailAddressRequired; + private @Getter Boolean phoneCountryCodeRequired; + private @Getter Boolean mobilePhoneNumberRequired; + private @Getter Boolean phoneNumberRequired; + private @Getter Boolean postalCodeRequired; + private @Getter PassengerConditions[] travelerRequirements; + } + + @ToString + public class PassengerConditions { + protected PassengerConditions(){} + + private @Getter String travelerId; + private @Getter Boolean genderRequired; + private @Getter Boolean documentRequired; + private @Getter Boolean documentIssuanceCityRequired; + private @Getter Boolean dateOfBirthRequired; + private @Getter Boolean redressRequiredIfAny; + private @Getter Boolean airFranceDiscountRequired; + private @Getter Boolean spanishResidentDiscountRequired; + private @Getter Boolean residenceRequired; + } } diff --git a/src/main/java/com/amadeus/shopping/flightOffers/Pricing.java b/src/main/java/com/amadeus/shopping/flightOffers/Pricing.java index c552db0f..43642c0b 100644 --- a/src/main/java/com/amadeus/shopping/flightOffers/Pricing.java +++ b/src/main/java/com/amadeus/shopping/flightOffers/Pricing.java @@ -4,6 +4,8 @@ import com.amadeus.Params; import com.amadeus.Response; import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.FlightOfferSearch; +import com.amadeus.resources.FlightPayment; import com.amadeus.resources.FlightPrice; import com.amadeus.resources.Resource; import com.google.gson.JsonObject; @@ -37,44 +39,180 @@ public Pricing(Amadeus client) { /** *

- * The Flight Offers Price REST/JSON API is an open price API that enables - * you to get or confirm the price of a flight and obtain information - * about taxes and fees to be applied to the entire journey. - * It is usually used after the Flight Offers Search API. It also retrieves - * ancillary information (e.g. additional bag or extra legroom seats pricing) - * and the payment information details requested at booking time. + * The Flight Offers Price API allows the user to get or confirm the price of a flight + * and obtain information about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. + * It also retrieves ancillary information and the payment information details. *

* *
    * amadeus.shopping.flightOffers.pricing.post(body, params);
* - * @param body the parameters to send to the API as a String - * @param params the parameters to send to the API + * @param body JSON body of flight-offers as JsonObject to price + * @param params URL parameters such as include or forceClass * @return an API resource * @throws ResponseException when an exception occurs */ - public FlightPrice[] post(JsonObject body, Params params) throws ResponseException { + public FlightPrice post(JsonObject body, Params params) throws ResponseException { Response response = client.post("/v1/shopping/flight-offers/pricing", params, body); - return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + return (FlightPrice) Resource.fromObject(response, FlightPrice.class); } - public FlightPrice[] post(String body, Params params) throws ResponseException { + /** + *

+ * The Flight Offers Price API allows the user to get or confirm the price of a flight + * and obtain information about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. + * It also retrieves ancillary information and the payment information details. + *

+ * + *
+   * amadeus.shopping.flightOffersSearch.pricing.post(body, params);
+ * + * @param body JSON body of flight-offers as String to price + * @param params URL parameters such as include or forceClass + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightPrice post(String body, Params params) throws ResponseException { Response response = client.post("/v1/shopping/flight-offers/pricing", params, body); - return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + return (FlightPrice) Resource.fromObject(response, FlightPrice.class); } - - public FlightPrice[] post(JsonObject body) throws ResponseException { + /** + *

+ * The Flight Offers Price API allows the user to get or confirm the price of a flight + * and obtain information about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. + * It also retrieves ancillary information and the payment information details. + *

+ * + *
+   * amadeus.shopping.flightOffersSearch.pricing.post(body);
+ * + * @param body JSON body of flight-offers as JsonObject to price + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightPrice post(JsonObject body) throws ResponseException { Response response = client.post("/v1/shopping/flight-offers/pricing", body); - return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + return (FlightPrice) Resource.fromObject(response, FlightPrice.class); } - public FlightPrice[] post(String body) throws ResponseException { + /** + *

+ * The Flight Offers Price API allows the user to get or confirm the price of a flight + * and obtain information about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. + * It also retrieves ancillary information and the payment information details. + *

+ * + *
+   * amadeus.shopping.flightOffersSearch.pricing.post(body);
+ * + * @param body JSON body of flight-offers as String to price + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightPrice post(String body) throws ResponseException { Response response = client.post("/v1/shopping/flight-offers/pricing", body); - return (FlightPrice[]) Resource.fromArray(response, FlightPrice[].class); + return (FlightPrice) Resource.fromObject(response, FlightPrice.class); + } + + /** + *

+ * The Flight Offers Price API allows the user to get or confirm the price of a flight + * and obtain information about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. + * It also retrieves ancillary information and the payment information details. + *

+ * + *
+   * amadeus.shopping.flightOffersSearch.pricing.post(flightOffersSearches);
+ * + * @param flightOffersSearches List of flight-offers as FlightOfferSearch[] object to price + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightPrice post(FlightOfferSearch[] flightOffersSearches) throws ResponseException { + JsonObject typeObject = new JsonObject(); + typeObject.addProperty("type", "flight-offers-pricing"); + typeObject.add("flightOffers", flightOffersSearches[0].getResponse().getData()); + + JsonObject jsonObject = new JsonObject(); + jsonObject.add("data", typeObject); + + Response response = client.post("/v1/shopping/flight-offers/pricing", jsonObject); + return (FlightPrice) Resource.fromObject(response, FlightPrice.class); + } + + /** + *

+ * The Flight Offers Price API allows the user to get or confirm the price of a flight + * and obtain information about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. + * It also retrieves ancillary information and the payment information details. + *

+ * + *
+   * amadeus.shopping.flightOffersSearch.pricing.post(flightOffersSearches);
+ * + * @param flightOffersSearches List of flight-offers as FlightOfferSearch[] object to price + * @param params URL parameters such as include or forceClass + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightPrice post(FlightOfferSearch[] flightOffersSearches, + Params params) throws ResponseException { + JsonObject typeObject = new JsonObject(); + typeObject.addProperty("type", "flight-offers-pricing"); + typeObject.add("flightOffers", flightOffersSearches[0].getResponse().getData()); + + JsonObject jsonObject = new JsonObject(); + jsonObject.add("data", typeObject); + + Response response = client.post( + "/v1/shopping/flight-offers/pricing", params, jsonObject); + return (FlightPrice) Resource.fromObject(response, FlightPrice.class); + } + + /** + *

+ * The Flight Offers Price API allows the user to get or confirm the price of a flight + * and obtain information about taxes and fees to be applied to the entire journey. + * It is usually used after the Flight Offers Search API. + * It also retrieves ancillary information and the payment information details. + *

+ * + *
+   * amadeus.shopping.flightOffersSearch.pricing.post(flightOffersSearches);
+ * + * @param flightOffersSearches List of flight-offers as FlightOfferSearch[] object to price + * @param flightPayment List of flight-offers as FlightOfferSearch[] object to price + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightPrice post(FlightOfferSearch[] flightOffersSearches, + FlightPayment flightPayment) throws ResponseException { + JsonObject typeObject = new JsonObject(); + typeObject.addProperty("type", "flight-offers-pricing"); + typeObject.add("flightOffers", flightOffersSearches[0].getResponse().getData()); + + JsonObject paymentObject = new JsonObject(); + paymentObject.addProperty("brand", flightPayment.getBrand().toString()); + paymentObject.addProperty("binNumber", flightPayment.getBinNumber().toString()); + paymentObject.addProperty("flightOffersIds", flightPayment.getFlightOfferIds().toString()); + + typeObject.add("payment", flightOffersSearches[0].getResponse().getData()); + + JsonObject jsonObject = new JsonObject(); + jsonObject.add("data", typeObject); + + Response response = client.post("/v1/shopping/flight-offers/pricing", jsonObject); + return (FlightPrice) Resource.fromObject(response, FlightPrice.class); } - public FlightPrice[] post() throws ResponseException { + public FlightPrice post() throws ResponseException { return post((String) null); } } diff --git a/src/test/java/com/amadeus/HTTPClientTest.java b/src/test/java/com/amadeus/HTTPClientTest.java index 46400b07..fce3529a 100644 --- a/src/test/java/com/amadeus/HTTPClientTest.java +++ b/src/test/java/com/amadeus/HTTPClientTest.java @@ -156,24 +156,24 @@ public class HTTPClientTest { } - @Test (expected = NetworkException.class) - public void tesFailedUnauthenticatedPostRequest() throws ResponseException, IOException { - when(request.getVerb()).thenReturn("POST"); - when(request.getParams()).thenReturn(params); - when(request.getConnection()).thenReturn(connection); - - when(connection.getOutputStream()).thenReturn(new PipedOutputStream()); - when(connection.getResponseCode()).thenReturn(200); - when(connection.getHeaderField("Content-Type")).thenReturn( - "application/json"); - when(connection.getInputStream()).thenReturn( - new ByteArrayInputStream("{ \"data\": [{}]}".getBytes())); - - when(client.buildRequest("POST", "/foo", params, null,null)).thenReturn(request); - when(client.unauthenticatedRequest("POST", "/foo", params, null,null)).thenCallRealMethod(); - - client.unauthenticatedRequest("POST", "/foo", params, null,null); - } + // @Test (expected = NetworkException.class) + // public void testFailedUnauthenticatedPostRequest() throws ResponseException, IOException { + // when(request.getVerb()).thenReturn("POST"); + // when(request.getParams()).thenReturn(params); + // when(request.getConnection()).thenReturn(connection); + // + // when(connection.getOutputStream()).thenReturn(new PipedOutputStream()); + // when(connection.getResponseCode()).thenReturn(200); + // when(connection.getHeaderField("Content-Type")).thenReturn( + // "application/json"); + // when(connection.getInputStream()).thenReturn( + // new ByteArrayInputStream("{ \"data\": [{}]}".getBytes())); + // + // when(client.buildRequest("POST", "/foo", params, null,null)).thenReturn(request); + // when(client.unauthenticatedRequest("POST", "/foo", params, null,null)).thenCallRealMethod(); + // + // client.unauthenticatedRequest("POST", "/foo", params, null,null); + // } @Test public void testLogIfDebug() throws ResponseException, IOException { when(client.getConfiguration().getLogLevel()).thenReturn("debug"); diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index a6c887fb..9b0d2554 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -307,14 +307,13 @@ public void testPostMethods() throws ResponseException { // Test flight price Mockito.when(client.post("/v1/shopping/flight-offers/pricing", (String) null)) - .thenReturn(multiResponse); + .thenReturn(singleResponse); Mockito.when(client.post("/v1/shopping/flight-offers/pricing", body)) - .thenReturn(multiResponse); + .thenReturn(singleResponse); Mockito.when(client.post("/v1/shopping/flight-offers/pricing", params, jsonObject)) - .thenReturn(multiResponse); + .thenReturn(singleResponse); Pricing pricing = new Pricing(client); TestCase.assertNotNull(pricing.post()); TestCase.assertNotNull(pricing.post(body)); - TestCase.assertEquals(pricing.post().length, 2); } } diff --git a/src/test/java/com/amadeus/RequestTest.java b/src/test/java/com/amadeus/RequestTest.java index 64bede2d..6a531232 100644 --- a/src/test/java/com/amadeus/RequestTest.java +++ b/src/test/java/com/amadeus/RequestTest.java @@ -83,7 +83,7 @@ public class RequestTest { Params params = Params.with("foo", "bar"); Request request = new Request("POST", "/foo/bar", params, null,null, amadeus); - assertEquals(request.getUri(), "https://test.api.amadeus.com:443/foo/bar?"); + assertEquals(request.getUri(), "https://test.api.amadeus.com:443/foo/bar?foo=bar"); } @Test public void testToString() { From 99ff6c753dffb92568d4a845a154965349f3c3ac Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Wed, 8 Jan 2020 15:46:26 +0100 Subject: [PATCH 04/22] update dates on readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 97c901c9..6a2db593 100644 --- a/README.md +++ b/README.md @@ -229,8 +229,8 @@ FlightOffer[] flightOffers = amadeus.shopping.flightOffers.get(Params FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.get( Params.with("originLocationCode", "SYD") .and("destinationLocationCode", "BKK") - .and("departureDate", "2020-04-01") - .and("returnDate", "2020-04-05") + .and("departureDate", "2020-11-01") + .and("returnDate", "2020-11-08") .and("adults", 2) .and("max", 3)); @@ -241,7 +241,7 @@ FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.p // Flight Choice Prediction // Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction FlightOffer[] flightOffers = amadeus.shopping.flightOffers - .get(Params.with("origin", "MAD").and("destination", "NYC").and("departureDate", "2020-04-01").and("max", "2")); + .get(Params.with("origin", "MAD").and("destination", "NYC").and("departureDate", "2020-08-01").and("max", "2")); // Using a JSonObject JsonObject result = flightOffers[0].getResponse().getResult(); From 44e9eee8a032533b3c32595dfeda980a3dc09c95 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Tue, 14 Jan 2020 14:20:51 +0100 Subject: [PATCH 05/22] update low-fare example date --- src/main/java/com/amadeus/shopping/FlightOffers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/amadeus/shopping/FlightOffers.java b/src/main/java/com/amadeus/shopping/FlightOffers.java index c1f53aa7..3453e16a 100644 --- a/src/main/java/com/amadeus/shopping/FlightOffers.java +++ b/src/main/java/com/amadeus/shopping/FlightOffers.java @@ -45,7 +45,7 @@ public FlightOffers(Amadeus client) { * amadeus.shopping.flightOffers.get(Params * .with("origin", "LHR") * .and("destination", "LAX") - * .and("departureDate", "2017-12-24")); + * .and("departureDate", "2020-08-01")); * * @param params the parameters to send to the API * @return an API response object From b5a74c3b123ed3ca3804654b63eb804d375d86de Mon Sep 17 00:00:00 2001 From: Anthony Roux Date: Wed, 5 Feb 2020 13:04:14 +0100 Subject: [PATCH 06/22] Fixing wrong links on README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a2db593..1a3adde8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Amadeus Java SDK [![Build Status](https://travis-ci.org/amadeus4dev/amadeus-java.svg?branch=master)][travis] -[![Contact Support](https://github.com/amadeus4dev/amadeus-ruby/raw/master/.github/images/support.svg?sanitize=true)][support] +[![Contact Support](https://github.com/amadeus4dev/amadeus-java/raw/master/.github/images/support.svg?sanitize=true)][support] Amadeus provides a set of APIs for the travel industry. Flights, Hotels, Locations and more. @@ -116,8 +116,8 @@ in-depth information about every SDK method, its arguments and return types. * [Get Started](https://amadeus4dev.github.io/amadeus-java/) documentation * [Initialize the SDK](https://amadeus4dev.github.io/amadeus-java/) * [Find an Airport](https://amadeus4dev.github.io/amadeus-java/) - * [Find a Flight](https://amadeus4dev.github.io/amadeus-ruby/) - * [Get Flight Inspiration](https://amadeus4dev.github.io/amadeus-ruby/) + * [Find a Flight](https://amadeus4dev.github.io/amadeus-java/) + * [Get Flight Inspiration](https://amadeus4dev.github.io/amadeus-java/) ## Making API calls From a075523576fb92d1fc180f23a0b95b4e282056be Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Thu, 20 Feb 2020 09:38:03 +0100 Subject: [PATCH 07/22] 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 --- README.md | 12 ++++ src/main/java/com/amadeus/Travel.java | 9 +++ .../java/com/amadeus/resources/Delay.java | 19 +++++ .../java/com/amadeus/travel/Predictions.java | 38 ++++++++++ .../travel/predictions/FlightDelay.java | 69 +++++++++++++++++++ src/test/java/com/amadeus/NamespaceTest.java | 12 ++++ 6 files changed, 159 insertions(+) create mode 100644 src/main/java/com/amadeus/resources/Delay.java create mode 100644 src/main/java/com/amadeus/travel/Predictions.java create mode 100644 src/main/java/com/amadeus/travel/predictions/FlightDelay.java diff --git a/README.md b/README.md index 1a3adde8..682006d4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/main/java/com/amadeus/Travel.java b/src/main/java/com/amadeus/Travel.java index 97c1a94d..a44bd414 100644 --- a/src/main/java/com/amadeus/Travel.java +++ b/src/main/java/com/amadeus/Travel.java @@ -1,6 +1,7 @@ package com.amadeus; import com.amadeus.travel.analytics.Analytics; +import com.amadeus.travel.predictions.Predictions; /** *

@@ -26,6 +27,13 @@ public class Travel { *

*/ public Analytics analytics; + /** + *

+ * A namespaced client for the + * /v1/travel/predictions endpoints. + *

+ */ + public Predictions predictions; /** * Constructor. @@ -33,5 +41,6 @@ public class Travel { */ public Travel(Amadeus client) { this.analytics = new Analytics(client); + this.predictions = new Predictions(client); } } diff --git a/src/main/java/com/amadeus/resources/Delay.java b/src/main/java/com/amadeus/resources/Delay.java new file mode 100644 index 00000000..92ef4372 --- /dev/null +++ b/src/main/java/com/amadeus/resources/Delay.java @@ -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; +} diff --git a/src/main/java/com/amadeus/travel/Predictions.java b/src/main/java/com/amadeus/travel/Predictions.java new file mode 100644 index 00000000..986867ee --- /dev/null +++ b/src/main/java/com/amadeus/travel/Predictions.java @@ -0,0 +1,38 @@ +package com.amadeus.travel.predictions; + +import com.amadeus.Amadeus; + +/** + *

+ * A namespaced client for the + * /v1/travel/predictions endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.travel.predictions;
+ * + * @hide + */ +public class Predictions { + /** + *

+ * A namespaced client for the + * /v1/travel/predictions/flight-delay endpoints. + *

+ */ + public FlightDelay flightDelay; + + + /** + * Constructor. + * @hide + */ + public Predictions(Amadeus client) { + this.flightDelay = new FlightDelay(client); + } +} diff --git a/src/main/java/com/amadeus/travel/predictions/FlightDelay.java b/src/main/java/com/amadeus/travel/predictions/FlightDelay.java new file mode 100644 index 00000000..b86a9fda --- /dev/null +++ b/src/main/java/com/amadeus/travel/predictions/FlightDelay.java @@ -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; + +/** + *

+ * A namespaced client for the + * /v1/travel/predictions/flight-delay endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.travel.predictions.flightDelay;
+ */ +public class FlightDelay { + private Amadeus client; + + /** + * Constructor. + * @hide + */ + public FlightDelay(Amadeus client) { + this.client = client; + } + + /** + *

+ * Predicts delay of a given flight. + *

+ * + *
+   * 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"));
+   * 
+ * @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 get without any parameters. + * @see FlightDelay#get() + */ + public Delay[] get() throws ResponseException { + return get(null); + } +} diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index 51e805fd..52595e11 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -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; @@ -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; @@ -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); @@ -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)); } @Test From 3d3ae83ab2afd26841c2d3be14ceb1aa9b9dd04b Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Thu, 20 Feb 2020 09:46:49 +0100 Subject: [PATCH 08/22] 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 --- README.md | 5 ++ src/main/java/com/amadeus/Airport.java | 37 +++++++++++ src/main/java/com/amadeus/Amadeus.java | 8 +++ .../java/com/amadeus/airport/Predictions.java | 38 ++++++++++++ .../airport/predictions/AirportOnTime.java | 61 +++++++++++++++++++ .../java/com/amadeus/resources/OnTime.java | 19 ++++++ src/test/java/com/amadeus/NamespaceTest.java | 11 ++++ 7 files changed, 179 insertions(+) create mode 100644 src/main/java/com/amadeus/Airport.java create mode 100644 src/main/java/com/amadeus/airport/Predictions.java create mode 100644 src/main/java/com/amadeus/airport/predictions/AirportOnTime.java create mode 100644 src/main/java/com/amadeus/resources/OnTime.java diff --git a/README.md b/README.md index 682006d4..7f0e5c0a 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,11 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt .and("west", "2.160873") .and("south", "41.394582") .and("east", "2.177181")); + +// What's the likelihood flights from this airport will leave on time? +OnTime AirportOnTime = amadeus.airport.predictions.onTime.get(Params + .with("airportCode", "NCE") + .and("date", "2020-09-01")); Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params .with("originLocationCode", "NCE") diff --git a/src/main/java/com/amadeus/Airport.java b/src/main/java/com/amadeus/Airport.java new file mode 100644 index 00000000..9057fcd5 --- /dev/null +++ b/src/main/java/com/amadeus/Airport.java @@ -0,0 +1,37 @@ +package com.amadeus; + +import com.amadeus.airport.predictions.Predictions; + +/** + *

+ * A namespaced client for the + * /v1/airport endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.airport
+ * + * @hide + */ +public class Airport { + /** + *

+ * A namespaced client for the + * /v1/airport/predictions endpoints. + *

+ */ + public Predictions predictions; + + /** + * Constructor. + * @hide + */ + public Airport(Amadeus client) { + this.predictions = new Predictions(client); + } +} diff --git a/src/main/java/com/amadeus/Amadeus.java b/src/main/java/com/amadeus/Amadeus.java index c9da2613..41bedc09 100644 --- a/src/main/java/com/amadeus/Amadeus.java +++ b/src/main/java/com/amadeus/Amadeus.java @@ -55,12 +55,20 @@ public class Amadeus extends HTTPClient { */ public EReputation ereputation; + /** + *

+ * A namespaced client for the /v1/airport endpoints. + *

+ */ + public Airport airport; + protected Amadeus(Configuration configuration) { super(configuration); this.referenceData = new ReferenceData(this); this.travel = new Travel(this); this.shopping = new Shopping(this); this.ereputation = new EReputation(this); + this.airport = new Airport(this); } /** diff --git a/src/main/java/com/amadeus/airport/Predictions.java b/src/main/java/com/amadeus/airport/Predictions.java new file mode 100644 index 00000000..07cbdbcd --- /dev/null +++ b/src/main/java/com/amadeus/airport/Predictions.java @@ -0,0 +1,38 @@ +package com.amadeus.airport.predictions; + +import com.amadeus.Amadeus; + +/** + *

+ * A namespaced client for the + * /v1/airport/predictions endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.airport.predictions;
+ * + * @hide + */ +public class Predictions { + /** + *

+ * A namespaced client for the + * /v1/airport/predictions/on-time endpoints. + *

+ */ + public AirportOnTime onTime; + + + /** + * Constructor. + * @hide + */ + public Predictions(Amadeus client) { + this.onTime = new AirportOnTime(client); + } +} \ No newline at end of file diff --git a/src/main/java/com/amadeus/airport/predictions/AirportOnTime.java b/src/main/java/com/amadeus/airport/predictions/AirportOnTime.java new file mode 100644 index 00000000..43ad6412 --- /dev/null +++ b/src/main/java/com/amadeus/airport/predictions/AirportOnTime.java @@ -0,0 +1,61 @@ +package com.amadeus.airport.predictions; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.Response; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.OnTime; +import com.amadeus.resources.Resource; + +/** + *

+ * A namespaced client for the + * /v1/airport/predictions/on-time endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.airport.predictions.onTime;
+ */ +public class AirportOnTime { + private Amadeus client; + + /** + * Constructor. + * @hide + */ + public AirportOnTime(Amadeus client) { + this.client = client; + } + + /** + *

+ * Returns a percentage of on-time flight from a given airport. + *

+ * + *
+   * OnTime airportOnTime = amadeus.airport.predictions.onTime.get(Params
+   *     .with("airportCode", "NCE")
+   *     .and("date", "2020-09-01"));
+   * 
+ * @param params the parameters to send to the API + * @return an API response object + * @throws ResponseException when an exception occurs + */ + public OnTime get(Params params) throws ResponseException { + Response response = client.get("/v1/airport/predictions/on-time", params); + return (OnTime) Resource.fromObject(response, OnTime.class); + } + + /** + * Convenience method for calling get without any parameters. + * @see AirportOnTime#get() + */ + public OnTime get() throws ResponseException { + return get(null); + } +} \ No newline at end of file diff --git a/src/main/java/com/amadeus/resources/OnTime.java b/src/main/java/com/amadeus/resources/OnTime.java new file mode 100644 index 00000000..ae184682 --- /dev/null +++ b/src/main/java/com/amadeus/resources/OnTime.java @@ -0,0 +1,19 @@ +package com.amadeus.resources; + +import lombok.Getter; +import lombok.ToString; + +/** + * An OnTime object as returned by the AirportOnTime API. + * @see com.amadeus.airport.predictions.AirportOnTime#get() + */ +@ToString +public class OnTime extends Resource { + protected OnTime() {} + + private @Getter String id; + private @Getter String probability; + private @Getter String result; + private @Getter String subType; + private @Getter String type; +} diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index 52595e11..13d33c13 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -1,5 +1,6 @@ package com.amadeus; +import com.amadeus.airport.predictions.AirportOnTime; import com.amadeus.ereputation.HotelSentiments; import com.amadeus.exceptions.ResponseException; import com.amadeus.referenceData.Airlines; @@ -62,6 +63,7 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.shopping.hotelOffersByHotel); TestCase.assertNotNull(client.ereputation.hotelSentiments); TestCase.assertNotNull(client.shopping.hotelOffer("XXX")); + TestCase.assertNotNull(client.airport.predictions.onTime); } @Before @@ -281,6 +283,15 @@ public void testGetMethods() throws ResponseException { HotelSentiments hotelSentiments = new HotelSentiments(client); TestCase.assertNotNull(hotelSentiments.get(params)); + // Test airport-on-time + Mockito.when(client.get("/v1/airport/predictions/on-time", null)) + .thenReturn(singleResponse); + Mockito.when(client.get("/v1/airport/predictions/on-time", params)) + .thenReturn(singleResponse); + AirportOnTime airportOnTime = new AirportOnTime(client); + TestCase.assertNotNull(airportOnTime.get()); + TestCase.assertNotNull(airportOnTime.get(params)); + // Test flight delay predictions Mockito.when(client.get("/v1/travel/predictions/flight-delay", null)) .thenReturn(multiResponse); From 6e80a1f11b008137a69640278e667ff9cd1d803a Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Fri, 21 Feb 2020 09:23:22 +0100 Subject: [PATCH 09/22] initial commit --- src/main/java/com/amadeus/Amadeus.java | 8 ++ src/main/java/com/amadeus/Booking.java | 20 +++++ .../java/com/amadeus/booking/FlightOrder.java | 61 +++++++++++++ .../com/amadeus/resources/FlightOrder.java | 85 +++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 src/main/java/com/amadeus/Booking.java create mode 100644 src/main/java/com/amadeus/booking/FlightOrder.java create mode 100644 src/main/java/com/amadeus/resources/FlightOrder.java diff --git a/src/main/java/com/amadeus/Amadeus.java b/src/main/java/com/amadeus/Amadeus.java index 41bedc09..26a80e24 100644 --- a/src/main/java/com/amadeus/Amadeus.java +++ b/src/main/java/com/amadeus/Amadeus.java @@ -62,6 +62,13 @@ public class Amadeus extends HTTPClient { */ public Airport airport; + /** + *

+ * A namespaced client for the /v1/booking endpoints. + *

+ */ + public Booking booking; + protected Amadeus(Configuration configuration) { super(configuration); this.referenceData = new ReferenceData(this); @@ -69,6 +76,7 @@ protected Amadeus(Configuration configuration) { this.shopping = new Shopping(this); this.ereputation = new EReputation(this); this.airport = new Airport(this); + this.booking = new Booking(this); } /** diff --git a/src/main/java/com/amadeus/Booking.java b/src/main/java/com/amadeus/Booking.java new file mode 100644 index 00000000..3f6629b2 --- /dev/null +++ b/src/main/java/com/amadeus/Booking.java @@ -0,0 +1,20 @@ +package com.amadeus; + +import com.amadeus.booking.FlightOrder; + +public class Booking { + private Amadeus client; + + /** + *

+ * A namespaced client for the + * /v1/booking/flightOrder endpoints. + *

+ */ + public FlightOrder flightOrder; + + public Booking(Amadeus client) { + this.client = client; + this.flightOrder = new FlightOrder(client); + } +} diff --git a/src/main/java/com/amadeus/booking/FlightOrder.java b/src/main/java/com/amadeus/booking/FlightOrder.java new file mode 100644 index 00000000..5c939425 --- /dev/null +++ b/src/main/java/com/amadeus/booking/FlightOrder.java @@ -0,0 +1,61 @@ +package com.amadeus.booking; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.Response; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.Resource; + +/** + *

+ * A namespaced client for the + * /v1/booking/flight-orders endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.booking.flightOrder;
+ */ +public class FlightOrder { + private Amadeus client; + + /** + * Constructor. + * @hide + */ + public FlightOrder(Amadeus client) { + this.client = client; + } + + /** + *

+ * Allows you to manipulate a flight order. + *

+ * + *
+   *  com.amadeus.resources.FlightOrder order = amadeus.booking.flightOrder.(
+   * "4BA070CE929E135B3268A9F2D0C51E9D4A6CF318BA10485322FA2C7E78C7852E").get();
+   * 
+ * @param params the parameters to send to the API + * @return an API response object + * @throws ResponseException when an exception occurs + */ + public com.amadeus.resources.FlightOrder[] get(Params params) throws ResponseException { + Response response = client.get( + "/v1/booking/flight-orders/", params); + return (com.amadeus.resources.FlightOrder[]) Resource.fromArray( + response, com.amadeus.resources.FlightOrder[].class); + } + + /** + * Convenience method for calling get without any parameters. + * @see FlightDelay#get() + */ + public com.amadeus.resources.FlightOrder[] get() throws ResponseException { + return get(null); + } +} diff --git a/src/main/java/com/amadeus/resources/FlightOrder.java b/src/main/java/com/amadeus/resources/FlightOrder.java new file mode 100644 index 00000000..b9ff566c --- /dev/null +++ b/src/main/java/com/amadeus/resources/FlightOrder.java @@ -0,0 +1,85 @@ +package com.amadeus.resources; + +import java.util.Date; +import lombok.Getter; +import lombok.ToString; + +/** + * An Airline object as returned by the Airline Code LookUp API. + * @see com.amadeus.booking.flightOrder#get() + */ +@ToString +public class FlightOrder extends Resource { + protected FlightOrder() {} + + private @Getter String type; + private @Getter String id; + private @Getter String queuingOfficeId; + private @Getter AssociatedRecord[] associatedRecords; + private @Getter Traveler[] travelers; + private @Getter FlightOfferSearch[] flightOffers; + + @ToString + public class AssociatedRecord { + protected AssociatedRecord() { + } + + private @Getter String reference; + private @Getter String creationDateTime; + private @Getter String originSystemCode; + private @Getter String flightOfferId; + } + + @ToString + public class Traveler { + protected Traveler() { + } + + private @Getter String id; + private @Getter Date dateOfBirth; + private @Getter Name name; + private @Getter Contact contact; + private @Getter Document documents; + } + + @ToString + public class Name { + protected Name() { + } + + private @Getter String firstName; + private @Getter String lastName; + } + + @ToString + public class Contact { + protected Contact() { + } + + private @Getter Phone phones; + } + + @ToString + public class Document { + protected Document() { + } + + private @Getter String documentType; + private @Getter String number; + private @Getter Date expiryDate; + private @Getter String issuanceCountry; + private @Getter String nationality; + private @Getter boolean holder; + } + + @ToString + public class Phone { + + protected Phone() { + } + + private @Getter String countryCallingCode; + private @Getter String number; + } + +} From f59b1fa5124060634d1b7117be0db99f7e8c27be Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Fri, 21 Feb 2020 11:12:31 +0100 Subject: [PATCH 10/22] add FlightOrder method and fix model --- src/main/java/com/amadeus/Booking.java | 5 +++- .../java/com/amadeus/booking/FlightOrder.java | 23 +++++++++++-------- .../com/amadeus/resources/FlightOrder.java | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/amadeus/Booking.java b/src/main/java/com/amadeus/Booking.java index 3f6629b2..93f3ec6a 100644 --- a/src/main/java/com/amadeus/Booking.java +++ b/src/main/java/com/amadeus/Booking.java @@ -15,6 +15,9 @@ public class Booking { public Booking(Amadeus client) { this.client = client; - this.flightOrder = new FlightOrder(client); + } + + public FlightOrder flightOrder(String flightOrderId) { + return new FlightOrder(client, flightOrderId); } } diff --git a/src/main/java/com/amadeus/booking/FlightOrder.java b/src/main/java/com/amadeus/booking/FlightOrder.java index 5c939425..d5510fec 100644 --- a/src/main/java/com/amadeus/booking/FlightOrder.java +++ b/src/main/java/com/amadeus/booking/FlightOrder.java @@ -9,7 +9,7 @@ /** *

* A namespaced client for the - * /v1/booking/flight-orders endpoints. + * /v1/booking/flight-orders:flightOrderId endpoints. *

* *

@@ -22,13 +22,15 @@ */ public class FlightOrder { private Amadeus client; + private String flightOfferId; /** * Constructor. * @hide */ - public FlightOrder(Amadeus client) { + public FlightOrder(Amadeus client, String flightOfferId) { this.client = client; + this.flightOfferId = flightOfferId; } /** @@ -44,18 +46,19 @@ public FlightOrder(Amadeus client) { * @return an API response object * @throws ResponseException when an exception occurs */ - public com.amadeus.resources.FlightOrder[] get(Params params) throws ResponseException { - Response response = client.get( - "/v1/booking/flight-orders/", params); - return (com.amadeus.resources.FlightOrder[]) Resource.fromArray( - response, com.amadeus.resources.FlightOrder[].class); - } + public com.amadeus.resources.FlightOrder get(Params params) throws ResponseException { + String path = String.format("/v1/booking/flight-orders/%s", flightOfferId); + Response response = client.get(path, params); + return (com.amadeus.resources.FlightOrder) Resource.fromObject( + response, com.amadeus.resources.FlightOrder.class); + } + /** * Convenience method for calling get without any parameters. - * @see FlightDelay#get() + * @see com.amadeus.booking.FlightOrder#get() */ - public com.amadeus.resources.FlightOrder[] get() throws ResponseException { + public com.amadeus.resources.FlightOrder get() throws ResponseException { return get(null); } } diff --git a/src/main/java/com/amadeus/resources/FlightOrder.java b/src/main/java/com/amadeus/resources/FlightOrder.java index b9ff566c..241e4e2c 100644 --- a/src/main/java/com/amadeus/resources/FlightOrder.java +++ b/src/main/java/com/amadeus/resources/FlightOrder.java @@ -39,7 +39,7 @@ protected Traveler() { private @Getter Date dateOfBirth; private @Getter Name name; private @Getter Contact contact; - private @Getter Document documents; + private @Getter Document[] documents; } @ToString @@ -56,7 +56,7 @@ public class Contact { protected Contact() { } - private @Getter Phone phones; + private @Getter Phone[] phones; } @ToString From a2fb023a6b71555e46313efb91404d0226691e25 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Fri, 21 Feb 2020 11:40:23 +0100 Subject: [PATCH 11/22] add tests --- src/test/java/com/amadeus/NamespaceTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index 13d33c13..bea3cc53 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -1,6 +1,7 @@ package com.amadeus; import com.amadeus.airport.predictions.AirportOnTime; +import com.amadeus.booking.FlightOrder; import com.amadeus.ereputation.HotelSentiments; import com.amadeus.exceptions.ResponseException; import com.amadeus.referenceData.Airlines; @@ -64,6 +65,7 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.ereputation.hotelSentiments); TestCase.assertNotNull(client.shopping.hotelOffer("XXX")); TestCase.assertNotNull(client.airport.predictions.onTime); + TestCase.assertNotNull(client.booking.flightOrder("XXX")); } @Before @@ -300,6 +302,15 @@ public void testGetMethods() throws ResponseException { FlightDelay flightDelay = new FlightDelay(client); TestCase.assertNotNull(flightDelay.get()); TestCase.assertNotNull(flightDelay.get(params)); + + // Test fetching a specific offer + Mockito.when(client.get("/v1/booking/flight-orders/XXX", null)) + .thenReturn(singleResponse); + Mockito.when(client.get("/v1/booking/flight-orders/XXX", params)) + .thenReturn(singleResponse); + FlightOrder flightOrder = new FlightOrder(client, "XXX"); + TestCase.assertNotNull(flightOrder.get()); + TestCase.assertNotNull(flightOrder.get(params)); } @Test From 58fa2d009134c92ff5703d0baebb6308626ab1ce Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Fri, 21 Feb 2020 11:46:43 +0100 Subject: [PATCH 12/22] update docs --- README.md | 4 ++++ src/main/java/com/amadeus/booking/FlightOrder.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f0e5c0a..ebad91ee 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,10 @@ FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.g // body can be a String version of your JSON or a JsonObject FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.post(body); +// Flight Order Management +// The flightOrderID comes from the Flight Create Orders (in test environment it's temporary) +com.amadeus.resources.FlightOrder order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").get(); + // Flight Choice Prediction // Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction FlightOffer[] flightOffers = amadeus.shopping.flightOffers diff --git a/src/main/java/com/amadeus/booking/FlightOrder.java b/src/main/java/com/amadeus/booking/FlightOrder.java index d5510fec..7e468a88 100644 --- a/src/main/java/com/amadeus/booking/FlightOrder.java +++ b/src/main/java/com/amadeus/booking/FlightOrder.java @@ -40,7 +40,7 @@ public FlightOrder(Amadeus client, String flightOfferId) { * *

    *  com.amadeus.resources.FlightOrder order = amadeus.booking.flightOrder.(
-   * "4BA070CE929E135B3268A9F2D0C51E9D4A6CF318BA10485322FA2C7E78C7852E").get();
+   * "eJzTd9f3NjIJdzUGAAp%2fAiY=").get();
    * 
* @param params the parameters to send to the API * @return an API response object From b4ec0576d4b68f462e1dff35e7c14c6a054b64d2 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Mon, 24 Feb 2020 11:59:51 +0100 Subject: [PATCH 13/22] remove most search destinations support --- README.md | 13 ---- .../java/com/amadeus/resources/Search.java | 37 ---------- .../resources/SearchedDestination.java | 53 --------------- .../amadeus/travel/analytics/AirTraffic.java | 20 ------ .../travel/analytics/airTraffic/Searched.java | 66 ------------------ .../airTraffic/SearchedByDestination.java | 67 ------------------- src/test/java/com/amadeus/NamespaceTest.java | 23 ------- 7 files changed, 279 deletions(-) delete mode 100644 src/main/java/com/amadeus/resources/Search.java delete mode 100644 src/main/java/com/amadeus/resources/SearchedDestination.java delete mode 100644 src/main/java/com/amadeus/travel/analytics/airTraffic/Searched.java delete mode 100644 src/main/java/com/amadeus/travel/analytics/airTraffic/SearchedByDestination.java diff --git a/README.md b/README.md index 7f0e5c0a..e12c8501 100644 --- a/README.md +++ b/README.md @@ -273,19 +273,6 @@ Location[] locations = amadeus.referenceData.locations.airports.get(Params .with("latitude", 0.1278) .and("longitude", 51.5074)); -// Flight Most Searched Destinations -// Which were the most searched flight destinations from Madrid in August 2017? -SearchedDestination searchedDestination = amadeus.travel.analytics.airTraffic.searchedByDestination.get(Params - .with("originCityCode", "MAD") - .and("destinationCityCode", "NYC") - .and("searchPeriod", "2017-08") - .and("marketCountryCode", "ES")); -// How many people in Spain searched for a trip from Madrid to New-York in September 2017? -Search[] search = amadeus.travel.analytics.airTraffic.searched.get(Params - .with("originCityCode", "MAD") - .and("searchPeriod", "2017-08") - .and("marketCountryCode", "ES")); - // Flight Most Booked Destinations AirTraffic[] airTraffics = amadeus.travel.analytics.airTraffic.booked.get(Params .with("originCityCode", "MAD") diff --git a/src/main/java/com/amadeus/resources/Search.java b/src/main/java/com/amadeus/resources/Search.java deleted file mode 100644 index c4b961ef..00000000 --- a/src/main/java/com/amadeus/resources/Search.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.amadeus.resources; - -import lombok.Getter; -import lombok.ToString; - -@ToString -public class Search extends Resource { - protected Search() { } - - private @Getter String subType; - private @Getter String destination; - private @Getter Analytics analytics; - - /** - * An Search-related object as returned by the AirTraffic API. - * - * @see Searched#get() - */ - @ToString - public class Analytics { - protected Analytics() {} - - private @Getter Searches searches; - } - - /** - * An Search-related object as returned by the AirTraffic API. - * - * @see Searched#get() - */ - @ToString - public class Searches { - protected Searches() {} - - private @Getter Double score; - } -} diff --git a/src/main/java/com/amadeus/resources/SearchedDestination.java b/src/main/java/com/amadeus/resources/SearchedDestination.java deleted file mode 100644 index 8ac9ee2f..00000000 --- a/src/main/java/com/amadeus/resources/SearchedDestination.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.amadeus.resources; - -import java.util.HashMap; -import lombok.Getter; -import lombok.ToString; - -/** - * An SearchedDestination object as returned by the SearchedByDestination API. - * @see SearchedByDestination#get() - */ -@ToString -public class SearchedDestination extends Resource { - protected SearchedDestination() {} - - private @Getter String destination; - private @Getter String subType; - private @Getter Analytics analytics; - - /** - * An AirTraffic-related object as returned by the AirTraffic API. - * @see SearchedByDestination#get() - */ - @ToString - public class Analytics { - protected Analytics() { - } - - private @Getter Searches searches; - } - - /** - * An AirTraffic-related object as returned by the AirTraffic API. - * @see SearchedByDestination#get() - */ - @ToString - public class Searches { - protected Searches() {} - - private @Getter NumberOfSearches numberOfSearches; - } - - /** - * An SearchedDestination-related object as returned by the SearchedByDestination API. - * @see SearchedByDestination#get() - */ - @ToString - public class NumberOfSearches { - protected NumberOfSearches() {} - - private @Getter HashMap perTripDuration; - private @Getter HashMap perDaysInAdvance; - } -} diff --git a/src/main/java/com/amadeus/travel/analytics/AirTraffic.java b/src/main/java/com/amadeus/travel/analytics/AirTraffic.java index a3b9ca05..2b94e12e 100644 --- a/src/main/java/com/amadeus/travel/analytics/AirTraffic.java +++ b/src/main/java/com/amadeus/travel/analytics/AirTraffic.java @@ -3,8 +3,6 @@ import com.amadeus.Amadeus; import com.amadeus.travel.analytics.airTraffic.Booked; import com.amadeus.travel.analytics.airTraffic.BusiestPeriod; -import com.amadeus.travel.analytics.airTraffic.Searched; -import com.amadeus.travel.analytics.airTraffic.SearchedByDestination; import com.amadeus.travel.analytics.airTraffic.Traveled; /** @@ -24,22 +22,6 @@ * @hide */ public class AirTraffic { - /** - *

- * A namespaced client for the - * /v1/travel/analytics/air-traffic/searched endpoints. - *

- */ - public Searched searched; - - /** - *

- * A namespaced client for the - * /v1/travel/analytics/air-traffic/searched/by-destination endpoints. - *

- */ - public SearchedByDestination searchedByDestination; - /** *

* A namespaced client for the @@ -69,8 +51,6 @@ public class AirTraffic { * @hide */ public AirTraffic(Amadeus client) { - this.searched = new Searched(client); - this.searchedByDestination = new SearchedByDestination(client); this.traveled = new Traveled(client); this.booked = new Booked(client); this.busiestPeriod = new BusiestPeriod(client); diff --git a/src/main/java/com/amadeus/travel/analytics/airTraffic/Searched.java b/src/main/java/com/amadeus/travel/analytics/airTraffic/Searched.java deleted file mode 100644 index 6ab9509c..00000000 --- a/src/main/java/com/amadeus/travel/analytics/airTraffic/Searched.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.amadeus.travel.analytics.airTraffic; - -import com.amadeus.Amadeus; -import com.amadeus.Params; -import com.amadeus.Response; -import com.amadeus.exceptions.ResponseException; -import com.amadeus.resources.Resource; -import com.amadeus.resources.Search; - - -/** - *

- * A namespaced client for the - * /v1/travel/analytics/air-traffic/searched endpoints. - *

- * - *

- * Access via the Amadeus client object. - *

- * - *
- * Amadeus amadeus = Amadeus.builder("API_KEY", "API_SECRET").build();
- * amadeus.travel.analytics.airTraffis.Searched;
- */ -public class Searched { - - private Amadeus client; - - /** - * Constructor. - * - * @hide - */ - public Searched(Amadeus client) { - this.client = client; - } - - /** - *

- * Returns a list of air traffic reports based on the number of searches. - *

- * - *
-   * amadeus.travel.analytics.airTraffic.searched.get(Params
-   *   .with("originCityCode", "MAD")
-   *   .and("searchPeriod", "2017-08")
-   *   .and("marketCountryCode", "ES"));
- * - * @param params the parameters to send to the API - * @return an API response object - * @throws ResponseException when an exception occurs - */ - public Search[] get(Params params) throws ResponseException { - Response response = client.get("/v1/travel/analytics/air-traffic/searched", params); - return (Search[]) Resource.fromArray(response, Search[].class); - } - - /** - * Convenience method for calling get without any parameters. - * - * @see Searched#get() - */ - public Search[] get() throws ResponseException { - return get(null); - } -} diff --git a/src/main/java/com/amadeus/travel/analytics/airTraffic/SearchedByDestination.java b/src/main/java/com/amadeus/travel/analytics/airTraffic/SearchedByDestination.java deleted file mode 100644 index 5c967284..00000000 --- a/src/main/java/com/amadeus/travel/analytics/airTraffic/SearchedByDestination.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.amadeus.travel.analytics.airTraffic; - -import com.amadeus.Amadeus; -import com.amadeus.Params; -import com.amadeus.Response; -import com.amadeus.exceptions.ResponseException; -import com.amadeus.resources.Resource; -import com.amadeus.resources.SearchedDestination; - -/** - *

- * A namespaced client for the - * /v1/travel/analytics/air-traffic/searched/by-destination endpoints. - *

- * - *

- * Access via the Amadeus client object. - *

- * - *
- * Amadeus amadeus = Amadeus.builder("API_KEY", "API_SECRET").build();
- * amadeus.travel.analytics.airTraffis.SearchedByDestination;
- */ -public class SearchedByDestination { - - private Amadeus client; - - /** - * Constructor. - * - * @hide - */ - public SearchedByDestination(Amadeus client) { - this.client = client; - } - - /** - *

- * Returns a air traffic report based on the number of searches. - *

- * - *
-   * amadeus.travel.analytics.airTraffic.searchedByDestination.get(Params
-   *   .with("originCityCode", "MAD")
-   *   .and("destinationCityCode", "NYC")
-   *   .and("searchPeriod", "2017-08")
-   *   .and("marketCountryCode", "ES"));
- * - * @param params the parameters to send to the API - * @return an API response object - * @throws ResponseException when an exception occurs - */ - public SearchedDestination get(Params params) throws ResponseException { - Response response = client - .get("/v1/travel/analytics/air-traffic/searched/by-destination", params); - return (SearchedDestination) Resource.fromObject(response, SearchedDestination.class); - } - - /** - * Convenience method for calling get without any parameters. - * - * @see SearchedByDestination#get() - */ - public SearchedDestination get() throws ResponseException { - return get(null); - } -} diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index 13d33c13..fbc8e767 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -20,8 +20,6 @@ import com.amadeus.shopping.flightOffers.Prediction; import com.amadeus.travel.analytics.airTraffic.Booked; import com.amadeus.travel.analytics.airTraffic.BusiestPeriod; -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; @@ -51,8 +49,6 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.referenceData.airlines); TestCase.assertNotNull(client.travel.analytics.airTraffic.traveled); 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); @@ -190,25 +186,6 @@ public void testGetMethods() throws ResponseException { TestCase.assertNotNull(busiestPeriod.get(params)); TestCase.assertEquals(busiestPeriod.get().length, 2); - // Testing most searched destinations - Mockito.when(client.get("/v1/travel/analytics/air-traffic/searched", null)) - .thenReturn(multiResponse); - Mockito.when(client.get("/v1/travel/analytics/air-traffic/searched", params)) - .thenReturn(multiResponse); - Searched searches = new Searched(client); - TestCase.assertNotNull(searches.get()); - TestCase.assertNotNull(searches.get(params)); - TestCase.assertEquals(searches.get().length, 2); - - // Testing searched stats - Mockito.when(client.get("/v1/travel/analytics/air-traffic/searched/by-destination", null)) - .thenReturn(singleResponse); - Mockito.when(client.get("/v1/travel/analytics/air-traffic/searched/by-destination", params)) - .thenReturn(singleResponse); - SearchedByDestination searchesByDestination = new SearchedByDestination(client); - TestCase.assertNotNull(searchesByDestination.get()); - TestCase.assertNotNull(searchesByDestination.get(params)); - // Testing flight date search Mockito.when(client.get("/v1/shopping/flight-dates", null)) .thenReturn(multiResponse); From 3620493ffa18a769d3a65fffd13b0dcafd8aa493 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Tue, 25 Feb 2020 16:37:37 +0100 Subject: [PATCH 14/22] support docs and tests --- README.md | 9 ++ src/main/java/com/amadeus/Shopping.java | 10 ++ .../java/com/amadeus/resources/SeatMap.java | 74 ++++++++++++ .../java/com/amadeus/shopping/SeatMaps.java | 109 ++++++++++++++++++ src/test/java/com/amadeus/NamespaceTest.java | 22 +++- 5 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/amadeus/resources/SeatMap.java create mode 100644 src/main/java/com/amadeus/shopping/SeatMaps.java diff --git a/README.md b/README.md index e12c8501..2fec5383 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,7 @@ OnTime AirportOnTime = amadeus.airport.predictions.onTime.get(Params .with("airportCode", "NCE") .and("date", "2020-09-01")); +// What's the likelihood of a given flight to be delayed? Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params .with("originLocationCode", "NCE") .and("destinationLocationCode", "IST") @@ -329,6 +330,14 @@ Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params .and("carrierCode", "TK") .and("flightNumber", "1816") .and("duration", "PT31H10M")); + +// What is the the seat map of a given flight? +SeatMap[] seatmap = amadeus.shopping.seatMaps.get(Params + .with("flight-orderId", "eJzTd9f3NjIJdzUGAAp%2fAiY=")); + +// What is the the seat map of a given flight? +// The body can be a String version of your JSON or a JsonObject +SeatMap[] seatmap = amadeus.shopping.seatMaps..post(body); ``` ## Development & Contributing diff --git a/src/main/java/com/amadeus/Shopping.java b/src/main/java/com/amadeus/Shopping.java index ecbff776..71e67858 100644 --- a/src/main/java/com/amadeus/Shopping.java +++ b/src/main/java/com/amadeus/Shopping.java @@ -7,6 +7,7 @@ import com.amadeus.shopping.HotelOffer; import com.amadeus.shopping.HotelOffers; import com.amadeus.shopping.HotelOffersByHotel; +import com.amadeus.shopping.SeatMaps; /** *

@@ -75,6 +76,14 @@ public class Shopping { */ public HotelOffersByHotel hotelOffersByHotel; + /** + *

+ * A namespaced client for the + * /v1/shopping/seatmaps endpoints. + *

+ */ + public SeatMaps seatMaps; + /** * Constructor. * @hide @@ -87,6 +96,7 @@ public Shopping(Amadeus client) { this.hotelOffers = new HotelOffers(client); this.hotelOffersByHotel = new HotelOffersByHotel(client); this.flightOffersSearch = new FlightOffersSearch(client); + this.seatMaps = new SeatMaps(client); } /** diff --git a/src/main/java/com/amadeus/resources/SeatMap.java b/src/main/java/com/amadeus/resources/SeatMap.java new file mode 100644 index 00000000..7258e416 --- /dev/null +++ b/src/main/java/com/amadeus/resources/SeatMap.java @@ -0,0 +1,74 @@ +package com.amadeus.resources; + +import lombok.Getter; +import lombok.ToString; + +/** + * An SeatMap object as returned by the SeatMap API. + * @see com.amadeus.booking.SeatMaps#get() + * @see com.amadeus.booking.SeatMaps#post() */ +@ToString +public class SeatMap extends Resource { + protected SeatMap() {} + + private @Getter String type; + private @Getter String flightOfferid; + private @Getter String segmentid; + private @Getter String carrierCode; + private @Getter String number; + private @Getter Aircraft aircraft; + private @Getter Departure departure; + private @Getter Deck[] decks; + + @ToString + public class Aircraft { + protected Aircraft() { + } + + private @Getter String code; + } + + @ToString + public class Departure { + protected Departure() { + } + + private @Getter String iataCode; + private @Getter String at; + } + + @ToString + public class Arrival { + protected Arrival() { + } + + private @Getter String iataCode; + } + + @ToString + public class Deck { + protected Deck() { + } + + private @Getter String deckType; + private @Getter DeckConfiguration deckConfiguration; + + } + + @ToString + public class DeckConfiguration { + protected DeckConfiguration() { + } + + private @Getter int width; + private @Getter int length; + private @Getter int startseatRow; + private @Getter int endSeatRow; + private @Getter int startWingsRow; + private @Getter int endWingsRow; + private @Getter int startWingsX; + private @Getter int endWingsX; + + } + +} diff --git a/src/main/java/com/amadeus/shopping/SeatMaps.java b/src/main/java/com/amadeus/shopping/SeatMaps.java new file mode 100644 index 00000000..35950620 --- /dev/null +++ b/src/main/java/com/amadeus/shopping/SeatMaps.java @@ -0,0 +1,109 @@ +package com.amadeus.shopping; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.Response; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.Resource; +import com.amadeus.resources.SeatMap; +import com.google.gson.JsonObject; + +/** + *

+ * A namespaced client for the + * /v1/shopping/seatmaps endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder(API_KEY, API_SECRET).build();
+ * amadeus.shopping.seatMaps;
+ */ +public class SeatMaps { + private Amadeus client; + + /** + * Constructor. + * + * @hide + */ + public SeatMaps(Amadeus client) { + this.client = client; + } + + /** + *

+ * The SeatMap API allows you to retrieve the seat map of one or several + * flights based on the flight-orderId returned by the Flight Create Orders API. + *

+ * + *
+   * amadeus.shopping.seatMaps.get(params);
+ * + * @param params the parameters to send to the API + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public SeatMap[] get(Params params) throws ResponseException { + Response response = client.get("/v1/shopping/seatmaps", params); + return (SeatMap[]) Resource.fromArray(response, SeatMap[].class); + } + + /** + * Convenience method for calling get without any parameters. + * @see SeatMaps#get() + */ + public SeatMap[] get() throws ResponseException { + return get(null); + } + + /** + *

+ * The SeatMap API allows you to retrieve the seat map of one or several + * Take the body of a flight offer search or flight offer price and pass + * it in to this method to get a seatmap. + *

+ * + *
+   * amadeus.shopping.seatMaps.post(body);
+ * + * @param body the parameters to send to the API as a JSonObject + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public SeatMap[] post(JsonObject body) throws ResponseException { + Response response = client.post("/v1/shopping/seatmaps", body); + return (SeatMap[]) Resource.fromArray(response, SeatMap[].class); + } + + /** + *

+ * The SeatMap API allows you to retrieve the seat map of one or several + * Take the body of a flight offer search or flight offer price and pass + * it in to this method to get a seatmap. + *

+ * + *
+   * amadeus.shopping.seatMaps.post(body);
+ * + * @param body the parameters to send to the API as a String + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public SeatMap[] post(String body) throws ResponseException { + Response response = client.post("/v1/shopping/seatmaps", body); + return (SeatMap[]) Resource.fromArray(response, SeatMap[].class); + } + + /** + * Convenience method for calling post without any parameters. + * + * @see SeatMaps#post() + */ + public SeatMap[] post() throws ResponseException { + return post((String) null); + } +} diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index fbc8e767..8e5d37aa 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -9,7 +9,6 @@ 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; @@ -18,6 +17,7 @@ import com.amadeus.shopping.HotelOffers; import com.amadeus.shopping.HotelOffersByHotel; import com.amadeus.shopping.flightOffers.Prediction; +import com.amadeus.shopping.SeatMaps; import com.amadeus.travel.analytics.airTraffic.Booked; import com.amadeus.travel.analytics.airTraffic.BusiestPeriod; import com.amadeus.travel.analytics.airTraffic.Traveled; @@ -57,6 +57,7 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.shopping.flightOffers.prediction); TestCase.assertNotNull(client.shopping.hotelOffers); TestCase.assertNotNull(client.shopping.hotelOffersByHotel); + TestCase.assertNotNull(client.shopping.seatMaps); TestCase.assertNotNull(client.ereputation.hotelSentiments); TestCase.assertNotNull(client.shopping.hotelOffer("XXX")); TestCase.assertNotNull(client.airport.predictions.onTime); @@ -277,6 +278,14 @@ public void testGetMethods() throws ResponseException { FlightDelay flightDelay = new FlightDelay(client); TestCase.assertNotNull(flightDelay.get()); TestCase.assertNotNull(flightDelay.get(params)); + + // Test SeatMaps get + Mockito.when(client.get("/v1/shopping/seatmaps", null)) + .thenReturn(multiResponse); + Mockito.when(client.get("/v1/shopping/seatmaps", params)) + .thenReturn(multiResponse); + SeatMaps seatmap = new SeatMaps(client); + TestCase.assertNotNull(seatmap.get(params)); } @Test @@ -302,5 +311,16 @@ public void testPostMethods() throws ResponseException { TestCase.assertNotNull(flightOfferSearch.post()); TestCase.assertNotNull(flightOfferSearch.post(body)); TestCase.assertEquals(flightOfferSearch.post().length, 2); + + // Test SeatMaps post + Mockito.when(client.post("/v1/shopping/seatmaps", (String) null)) + .thenReturn(multiResponse); + Mockito.when(client.post("/v1/shopping/seatmaps", body)) + .thenReturn(multiResponse); + Mockito.when(client.post("/v1/shopping/seatmaps", jsonObject)) + .thenReturn(multiResponse); + SeatMaps seatmap = new SeatMaps(client); + TestCase.assertNotNull(seatmap.post()); + TestCase.assertNotNull(seatmap.post(body)); } } From 9fa4c25481e91bbb1f519f1358cfec9e9bb3e8cb Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Tue, 25 Feb 2020 16:41:00 +0100 Subject: [PATCH 15/22] fix import order --- src/test/java/com/amadeus/NamespaceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index 8e5d37aa..81a30f2d 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -16,8 +16,8 @@ import com.amadeus.shopping.HotelOffer; import com.amadeus.shopping.HotelOffers; import com.amadeus.shopping.HotelOffersByHotel; -import com.amadeus.shopping.flightOffers.Prediction; import com.amadeus.shopping.SeatMaps; +import com.amadeus.shopping.flightOffers.Prediction; import com.amadeus.travel.analytics.airTraffic.Booked; import com.amadeus.travel.analytics.airTraffic.BusiestPeriod; import com.amadeus.travel.analytics.airTraffic.Traveled; From 7fd04d2386dfb3554eb19754f52b3c8b8c615240 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Tue, 25 Feb 2020 16:44:58 +0100 Subject: [PATCH 16/22] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fec5383..ea5c767f 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ SeatMap[] seatmap = amadeus.shopping.seatMaps.get(Params // What is the the seat map of a given flight? // The body can be a String version of your JSON or a JsonObject -SeatMap[] seatmap = amadeus.shopping.seatMaps..post(body); +SeatMap[] seatmap = amadeus.shopping.seatMaps.post(body); ``` ## Development & Contributing From 1419491551a05ad1d3c63252133c45c445025e10 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Fri, 28 Feb 2020 12:52:50 +0100 Subject: [PATCH 17/22] update class names in docs --- README.md | 2 +- src/main/java/com/amadeus/booking/FlightOrder.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ebad91ee..57ebf948 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.p // Flight Order Management // The flightOrderID comes from the Flight Create Orders (in test environment it's temporary) -com.amadeus.resources.FlightOrder order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").get(); +FlightOrder order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").get(); // Flight Choice Prediction // Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction diff --git a/src/main/java/com/amadeus/booking/FlightOrder.java b/src/main/java/com/amadeus/booking/FlightOrder.java index 7e468a88..3c2db246 100644 --- a/src/main/java/com/amadeus/booking/FlightOrder.java +++ b/src/main/java/com/amadeus/booking/FlightOrder.java @@ -9,7 +9,7 @@ /** *

* A namespaced client for the - * /v1/booking/flight-orders:flightOrderId endpoints. + * /v1/booking/flight-orders/:flightOrderId endpoints. *

* *

@@ -35,11 +35,13 @@ public FlightOrder(Amadeus client, String flightOfferId) { /** *

- * Allows you to manipulate a flight order. + * Allows you to manipulate a flight order. The flightOfferId + * used is an example for educational purposes. In test enviromnent + * it's temporary. *

* *
-   *  com.amadeus.resources.FlightOrder order = amadeus.booking.flightOrder.(
+   * FlightOrder order = amadeus.booking.flightOrder.(
    * "eJzTd9f3NjIJdzUGAAp%2fAiY=").get();
    * 
* @param params the parameters to send to the API From 8ed52c6dfa0b7c129386aa192bc5bb55ded19e9a Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Thu, 12 Mar 2020 16:16:39 +0100 Subject: [PATCH 18/22] Flight Create Orders (#54) * initial commit * fix booking * support traveler and flighs object for create orders * update docs and add tests * fix readme * add create orders example * update docs * update readme --- README.md | 8 + src/main/java/com/amadeus/Booking.java | 10 ++ .../com/amadeus/booking/FlightOrders.java | 147 ++++++++++++++++++ .../java/com/amadeus/resources/Traveler.java | 83 ++++++++++ .../createorders/FlightCreateOrders.java | 74 +++++++++ src/test/java/com/amadeus/NamespaceTest.java | 10 ++ 6 files changed, 332 insertions(+) create mode 100644 src/main/java/com/amadeus/booking/FlightOrders.java create mode 100644 src/main/java/com/amadeus/resources/Traveler.java create mode 100644 src/main/java/examples/flight/createorders/FlightCreateOrders.java diff --git a/README.md b/README.md index 6529e3b4..c41f6e98 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,14 @@ Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params .and("flightNumber", "1816") .and("duration", "PT31H10M")); +// Flight Create Orders to book a flight +// Using a JSonObject or String +FlightOrder createdOrder = amadeus.booking.flightOrders.pricing.post(body); + +// Using a JsonObject for flight offer and Traveler[] as traveler information +// see example at src/main/java/examples/flight/createorders/FlightCreateOrders.java +FlightOrder createdOrder = amadeus.booking.flightOrders.post(flightOffersSearches, travelerArray); + // What is the the seat map of a given flight? SeatMap[] seatmap = amadeus.shopping.seatMaps.get(Params .with("flight-orderId", "eJzTd9f3NjIJdzUGAAp%2fAiY=")); diff --git a/src/main/java/com/amadeus/Booking.java b/src/main/java/com/amadeus/Booking.java index 93f3ec6a..4e5a7a73 100644 --- a/src/main/java/com/amadeus/Booking.java +++ b/src/main/java/com/amadeus/Booking.java @@ -1,6 +1,7 @@ package com.amadeus; import com.amadeus.booking.FlightOrder; +import com.amadeus.booking.FlightOrders; public class Booking { private Amadeus client; @@ -13,8 +14,17 @@ public class Booking { */ public FlightOrder flightOrder; + /** + *

+ * A namespaced client for the + * /v1/booking/flightOrders endpoints. + *

+ */ + public FlightOrders flightOrders; + public Booking(Amadeus client) { this.client = client; + this.flightOrders = new FlightOrders(client); } public FlightOrder flightOrder(String flightOrderId) { diff --git a/src/main/java/com/amadeus/booking/FlightOrders.java b/src/main/java/com/amadeus/booking/FlightOrders.java new file mode 100644 index 00000000..e6ae4477 --- /dev/null +++ b/src/main/java/com/amadeus/booking/FlightOrders.java @@ -0,0 +1,147 @@ +package com.amadeus.booking; + +import com.amadeus.Amadeus; +import com.amadeus.Response; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.FlightOfferSearch; +import com.amadeus.resources.FlightOrder; +import com.amadeus.resources.Resource; +import com.amadeus.resources.Traveler; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +/** + *

+ * A namespaced client for the + * /v1/booking/flight-orders endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder(API_KEY, API_SECRET).build();
+ * amadeus.booking.flightOrders;
+ */ +public class FlightOrders { + private Amadeus client; + + /** + * Constructor. + * + * @hide + */ + public FlightOrders(Amadeus client) { + this.client = client; + } + + /** + *

+ * The Flight Create Orders API allows you to perform flight booking. + *

+ * + *
+   * amadeus.booking.flightOrders.post(body);
+ * + * @param body the parameters to send to the API as a JSonObject + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightOrder post(JsonObject body) throws ResponseException { + Response response = client.post("/v1/booking/flight-orders", body); + return (FlightOrder) Resource.fromObject(response, FlightOrder.class); + } + + /** + *

+ * The Flight Create Orders API allows you to perform flight booking. + *

+ * + *
+   * amadeus.booking.flightOrders.post(body);
+ * + * @param body the parameters to send to the API as a String + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightOrder post(String body) throws ResponseException { + Response response = client.post("/v1/booking/flight-orders", body); + return (FlightOrder) Resource.fromObject(response, FlightOrder.class); + } + + /** + *

+ * The Flight Create Orders API allows you to perform flight booking. + *

+ * + *
+   * amadeus.booking.flightOrders.post(object);
+ * + * @param flightOffersSearches List of flight-offers as FlightOfferSearch[] + * @param travelers List of travelers as Traveler[] + * @return an API resource + * @throws ResponseException when an exception occurs + */ + public FlightOrder post(FlightOfferSearch[] flightOffersSearches, + Traveler[] travelers) throws ResponseException { + + JsonObject nameObject = new JsonObject(); + nameObject.addProperty("firstName", travelers[0].getName().getFirstName()); + nameObject.addProperty("lastName", travelers[0].getName().getLastName()); + + JsonObject phoneObject = new JsonObject(); + phoneObject.addProperty("countryCallingCode", + travelers[0].getContact().getPhones()[0].getCountryCallingCode()); + phoneObject.addProperty("number", travelers[0].getContact().getPhones()[0].getNumber()); + phoneObject.addProperty("deviceType", travelers[0].getContact().getPhones()[0].getDeviceType()); + + + JsonArray phonesArray = new JsonArray(); + phonesArray.add(phoneObject); + + JsonObject contactObject = new JsonObject(); + contactObject.add("phones", phonesArray); + + JsonObject documentsOject = new JsonObject(); + documentsOject.addProperty("documentType", travelers[0].getDocuments()[0].getDocumentType()); + documentsOject.addProperty("number", travelers[0].getDocuments()[0].getNumber()); + documentsOject.addProperty("expiryDate", travelers[0].getDocuments()[0].getExpiryDate()); + documentsOject.addProperty("nationality", travelers[0].getDocuments()[0].getNationality()); + documentsOject.addProperty("issuanceCountry", + travelers[0].getDocuments()[0].getIssuanceCountry()); + documentsOject.addProperty("holder", travelers[0].getDocuments()[0].isHolder()); + JsonArray documentsArray = new JsonArray(); + documentsArray.add(documentsOject); + + JsonObject travelerObject = new JsonObject(); + travelerObject.addProperty("id", travelers[0].getId()); + travelerObject.addProperty("dateOfBirth", travelers[0].getDateOfBirth()); + travelerObject.add("name", nameObject); + travelerObject.add("contact", contactObject); + travelerObject.add("documents", documentsArray); + JsonArray travelerArray = new JsonArray(); + travelerArray.add(travelerObject); + + JsonObject typeObject = new JsonObject(); + typeObject.addProperty("type", "flight-order"); + typeObject.add("flightOffers", flightOffersSearches[0].getResponse().getData()); + typeObject.add("travelers", travelerArray); + + JsonObject jsonObject = new JsonObject(); + jsonObject.add("data", typeObject); + System.out.println(jsonObject); + + Response response = client.post("/v1/booking/flight-orders", jsonObject); + return (FlightOrder) Resource.fromObject(response, FlightOrder.class); + } + + /** + * Convenience method for calling post without any parameters. + * + * @see FlightOrders#post() + */ + public FlightOrder post() throws ResponseException { + return post((String) null); + } +} diff --git a/src/main/java/com/amadeus/resources/Traveler.java b/src/main/java/com/amadeus/resources/Traveler.java new file mode 100644 index 00000000..98f6e999 --- /dev/null +++ b/src/main/java/com/amadeus/resources/Traveler.java @@ -0,0 +1,83 @@ +package com.amadeus.resources; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * An Traveler object used in the body of Flight Create Orders. + * @see com.amadeus.booking.flightOrder#get() + */ +@ToString +public class Traveler extends Resource { + public Traveler(String id, String dateOfBirth, Name name, Contact contact, Document[] documents) { + this.name = name; + this.contact = contact; + } + + public Traveler() { + + } + + private @Getter @Setter String id; + private @Getter @Setter String dateOfBirth; + private @Getter @Setter Name name; + private @Getter @Setter Contact contact; + private @Getter @Setter Document[] documents; + + @ToString + public class Name { + public Name(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + private @Getter @Setter String firstName; + private @Getter @Setter String lastName; + + } + + @ToString + public class Contact { + public Contact() { + } + + public Contact(Phone phones) { + } + + private @Getter @Setter Phone[] phones; + } + + @ToString + public class Document { + public Document() { + } + + public Document(String documentType, String number, String expiryDate, + String issuanceCountry, String nationality, boolean holder) { + + } + + private @Getter @Setter String documentType; + private @Getter @Setter String number; + private @Getter @Setter String expiryDate; + private @Getter @Setter String issuanceCountry; + private @Getter @Setter String nationality; + private @Getter @Setter boolean holder; + } + + @ToString + public class Phone { + + public Phone() { + } + + public Phone(String countryCallingCode, String number) { + } + + private @Getter @Setter String countryCallingCode; + private @Getter @Setter String number; + private @Getter @Setter String deviceType; + } + +} diff --git a/src/main/java/examples/flight/createorders/FlightCreateOrders.java b/src/main/java/examples/flight/createorders/FlightCreateOrders.java new file mode 100644 index 00000000..c672a480 --- /dev/null +++ b/src/main/java/examples/flight/createorders/FlightCreateOrders.java @@ -0,0 +1,74 @@ +package examples.flight.createorders; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.FlightOfferSearch; +import com.amadeus.resources.FlightOrder; +import com.amadeus.resources.Traveler; +import com.amadeus.resources.Traveler.Document; +import com.amadeus.resources.Traveler.Phone; + +public class FlightCreateOrders { + /** + *

+ * An example to call the Flight Create Orders API + * /v1/booking/flight-orders endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+   * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+   * amadeus.booking.flightOrders;
+ */ + public static void main(String[] args) throws ResponseException { + + Traveler traveler = new Traveler(); + + traveler.setId("1"); + traveler.setDateOfBirth("2000-04-14"); + traveler.setName(traveler.new Name("JORGE", "GONZALES")); + + Traveler.Phone[] phone = new Phone[1]; + phone[0] = traveler.new Phone(); + phone[0].setCountryCallingCode("33"); + phone[0].setNumber("675426222"); + phone[0].setDeviceType("MOBILE"); + + Traveler.Contact contact = traveler.new Contact(); + contact.setPhones(phone); + traveler.setContact(contact); + + Traveler.Document[] document = new Document[1]; + document[0] = traveler.new Document(); + document[0].setDocumentType("PASSPORT"); + document[0].setNumber("480080076"); + document[0].setExpiryDate("2022-10-11"); + document[0].setIssuanceCountry("ES"); + document[0].setNationality("ES"); + document[0].setHolder(true); + traveler.setDocuments(document); + + Traveler[] travelerArray = new Traveler[1]; + travelerArray[0] = traveler; + System.out.println(travelerArray[0]); + + Amadeus amadeus = Amadeus + .builder("YOUR_CLIENT_ID","YOUR_CLIENT_SECRET") + .build(); + + FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.get( + Params.with("originLocationCode", "SYD") + .and("destinationLocationCode", "BKK") + .and("departureDate", "2020-11-01") + .and("returnDate", "2020-11-08") + .and("adults", 1) + .and("max", 1)); + + FlightOrder order = amadeus.booking.flightOrders.post(flightOffersSearches, travelerArray); + System.out.println(order); + } +} \ No newline at end of file diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index 62cbc1c2..eb532e70 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -2,6 +2,7 @@ import com.amadeus.airport.predictions.AirportOnTime; import com.amadeus.booking.FlightOrder; +import com.amadeus.booking.FlightOrders; import com.amadeus.ereputation.HotelSentiments; import com.amadeus.exceptions.ResponseException; import com.amadeus.referenceData.Airlines; @@ -323,6 +324,15 @@ public void testPostMethods() throws ResponseException { TestCase.assertNotNull(flightOfferSearch.post(body)); TestCase.assertEquals(flightOfferSearch.post().length, 2); + // Test flight create orders + Mockito.when(client.post("/v1/booking/flight-orders", (String) null)) + .thenReturn(singleResponse); + Mockito.when(client.post("/v1/booking/flight-orders", body)) + .thenReturn(singleResponse); + FlightOrders order = new FlightOrders(client); + TestCase.assertNotNull(order.post()); + TestCase.assertNotNull(order.post(body)); + // Test SeatMaps post Mockito.when(client.post("/v1/shopping/seatmaps", (String) null)) .thenReturn(multiResponse); From 9e6cf0efa4b6921369066929a2aee942e943405f Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Fri, 13 Mar 2020 09:36:38 +0100 Subject: [PATCH 19/22] Add support for ai-generated photos (#55) * add support for ai-generated photos * add tests and example * fix intendation * fix intendation --- README.md | 4 ++ src/main/java/com/amadeus/Amadeus.java | 9 +++ src/main/java/com/amadeus/Media.java | 37 ++++++++++++ src/main/java/com/amadeus/media/Files.java | 39 ++++++++++++ .../amadeus/media/files/GeneratedPhotos.java | 60 +++++++++++++++++++ .../com/amadeus/resources/GeneratedPhoto.java | 45 ++++++++++++++ .../amadeus/resources/PointOfInterest.java | 2 +- .../examples/media/AIGeneratedPhotos.java | 34 +++++++++++ src/test/java/com/amadeus/NamespaceTest.java | 11 ++++ 9 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/amadeus/Media.java create mode 100644 src/main/java/com/amadeus/media/Files.java create mode 100644 src/main/java/com/amadeus/media/files/GeneratedPhotos.java create mode 100644 src/main/java/com/amadeus/resources/GeneratedPhoto.java create mode 100644 src/main/java/examples/media/AIGeneratedPhotos.java diff --git a/README.md b/README.md index c41f6e98..234b3e31 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,10 @@ SeatMap[] seatmap = amadeus.shopping.seatMaps.get(Params // What is the the seat map of a given flight? // The body can be a String version of your JSON or a JsonObject SeatMap[] seatmap = amadeus.shopping.seatMaps.post(body); + +// AI-Generated Photos +GeneratedPhoto photo = amadeus.media.files.generatedPhotos.get(Params + .with("category", "BEACH")); ``` ## Development & Contributing diff --git a/src/main/java/com/amadeus/Amadeus.java b/src/main/java/com/amadeus/Amadeus.java index 26a80e24..132083df 100644 --- a/src/main/java/com/amadeus/Amadeus.java +++ b/src/main/java/com/amadeus/Amadeus.java @@ -69,6 +69,13 @@ public class Amadeus extends HTTPClient { */ public Booking booking; + /** + *

+ * A namespaced client for the /v2/media endpoints. + *

+ */ + public Media media; + protected Amadeus(Configuration configuration) { super(configuration); this.referenceData = new ReferenceData(this); @@ -77,6 +84,8 @@ protected Amadeus(Configuration configuration) { this.ereputation = new EReputation(this); this.airport = new Airport(this); this.booking = new Booking(this); + this.media = new Media(this); + } /** diff --git a/src/main/java/com/amadeus/Media.java b/src/main/java/com/amadeus/Media.java new file mode 100644 index 00000000..deccffab --- /dev/null +++ b/src/main/java/com/amadeus/Media.java @@ -0,0 +1,37 @@ +package com.amadeus; + +import com.amadeus.media.Files; + +/** + *

+ * A namespaced client for the + * /v2/media endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.media;
+ * + * @hide + */ +public class Media { + /** + *

+ * A namespaced client for the + * /v2/media/files endpoints. + *

+ */ + public Files files; + + /** + * Constructor. + * @hide + */ + public Media(Amadeus client) { + this.files = new Files(client); + } +} \ No newline at end of file diff --git a/src/main/java/com/amadeus/media/Files.java b/src/main/java/com/amadeus/media/Files.java new file mode 100644 index 00000000..5adb4a67 --- /dev/null +++ b/src/main/java/com/amadeus/media/Files.java @@ -0,0 +1,39 @@ +package com.amadeus.media; + +import com.amadeus.Amadeus; +import com.amadeus.media.files.GeneratedPhotos; + +/** + *

+ * A namespaced client for the + * /v2/media/files endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.media.files;
+ * + * @hide + */ +public class Files { + /** + *

+ * A namespaced client for the + * /v2/media/files/generated-photos endpoints. + *

+ */ + public GeneratedPhotos generatedPhotos; + + /** + * Constructor. + * + * @hide + */ + public Files(Amadeus client) { + this.generatedPhotos = new GeneratedPhotos(client); + } +} diff --git a/src/main/java/com/amadeus/media/files/GeneratedPhotos.java b/src/main/java/com/amadeus/media/files/GeneratedPhotos.java new file mode 100644 index 00000000..d6d13cde --- /dev/null +++ b/src/main/java/com/amadeus/media/files/GeneratedPhotos.java @@ -0,0 +1,60 @@ +package com.amadeus.media.files; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.Response; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.GeneratedPhoto; +import com.amadeus.resources.Resource; + +/** + *

+ * A namespaced client for the + * /v2/media/files/generated-photos endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.media.files.generatedPhotos;
+ */ +public class GeneratedPhotos { + private Amadeus client; + + /** + * Constructor. + * @hide + */ + public GeneratedPhotos(Amadeus client) { + this.client = client; + } + + /** + *

+ * Returns a link to download a rendered image of a landscape. + *

+ * + *
+   * amadeus.media.files.generatedPhotos.get(Params
+   *   .with("category", "BEACH"));
+ * + * @param params the parameters to send to the API + * @return an API response object + * @throws ResponseException when an exception occurs + */ + public GeneratedPhoto get(Params params) throws ResponseException { + Response response = client.get("/v2/media/files/generated-photos", params); + return (GeneratedPhoto) Resource.fromObject(response, GeneratedPhoto.class); + } + + /** + * Convenience method for calling get without any parameters. + * @see GeneratedPhotos#get() + */ + public GeneratedPhoto get() throws ResponseException { + return get(null); + } +} diff --git a/src/main/java/com/amadeus/resources/GeneratedPhoto.java b/src/main/java/com/amadeus/resources/GeneratedPhoto.java new file mode 100644 index 00000000..e9b64986 --- /dev/null +++ b/src/main/java/com/amadeus/resources/GeneratedPhoto.java @@ -0,0 +1,45 @@ +package com.amadeus.resources; + +import lombok.Getter; +import lombok.ToString; + +/** + * An GeneratedPhoto object as returned by the AI-Generated Photos API. + * @see Traveled#get() + */ +@ToString +public class GeneratedPhoto extends Resource { + protected GeneratedPhoto() {} + + private @Getter String type; + private @Getter String owner; + private @Getter String attachmentUri; + private @Getter String description; + private @Getter String fileKbSize; + private @Getter String expirationDateTime; + private @Getter MediaMetadata mediaMetadata; + + /** + * A MediaMetadata-related object as returned by the AI-Generated Photos API. + * @see GeneratedPhotos#get() + */ + @ToString + public class MediaMetadata { + protected MediaMetadata() {} + + private @Getter Dimension dimensions; + + /** + * A MediaMetadata-related object as returned by the AI-Generated Photos API. + * @see GeneratedPhotos#get() + */ + @ToString + public class Dimension { + protected Dimension() {} + + private @Getter String height; + private @Getter String width; + + } + } +} diff --git a/src/main/java/com/amadeus/resources/PointOfInterest.java b/src/main/java/com/amadeus/resources/PointOfInterest.java index 3becbdb5..81350f53 100644 --- a/src/main/java/com/amadeus/resources/PointOfInterest.java +++ b/src/main/java/com/amadeus/resources/PointOfInterest.java @@ -4,7 +4,7 @@ import lombok.ToString; /** - * An PointOfInterest object as returned by the Locaion API. + * An PointOfInterest object as returned by the Location API. * @see com.amadeus.referenceData.locations.PointOfInterest#get() */ @ToString diff --git a/src/main/java/examples/media/AIGeneratedPhotos.java b/src/main/java/examples/media/AIGeneratedPhotos.java new file mode 100644 index 00000000..dc3d5f37 --- /dev/null +++ b/src/main/java/examples/media/AIGeneratedPhotos.java @@ -0,0 +1,34 @@ +package examples.media.files; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.GeneratedPhoto; + +public class AIGeneratedPhotos { + /** + *

+ * An example to call the AI-Generated Photos API + * /v2/media/files/generated-photos endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+   * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+   * amadeus.media.files.generatedPhotos;
+ */ + public static void main(String[] args) throws ResponseException { + + + Amadeus amadeus = Amadeus + .builder("YOUR_API_ID","YOUR_API_SECRET") + .build(); + + GeneratedPhoto photo = amadeus.media.files.generatedPhotos.get(Params + .with("category", "BEACH")); + System.out.println(photo); + } +} diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index eb532e70..c72c0f47 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -5,6 +5,7 @@ import com.amadeus.booking.FlightOrders; import com.amadeus.ereputation.HotelSentiments; import com.amadeus.exceptions.ResponseException; +import com.amadeus.media.files.GeneratedPhotos; import com.amadeus.referenceData.Airlines; import com.amadeus.referenceData.Location; import com.amadeus.referenceData.Locations; @@ -64,6 +65,7 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.shopping.hotelOffer("XXX")); TestCase.assertNotNull(client.airport.predictions.onTime); TestCase.assertNotNull(client.booking.flightOrder("XXX")); + TestCase.assertNotNull(client.media.files.generatedPhotos); } @Before @@ -298,6 +300,15 @@ public void testGetMethods() throws ResponseException { FlightOrder flightOrder = new FlightOrder(client, "XXX"); TestCase.assertNotNull(flightOrder.get()); TestCase.assertNotNull(flightOrder.get(params)); + + // Testing AI-generated photos + Mockito.when(client.get("/v2/media/files/generated-photos", null)) + .thenReturn(singleResponse); + Mockito.when(client.get("/v2/media/files/generated-photos", params)) + .thenReturn(singleResponse); + GeneratedPhotos photo = new GeneratedPhotos(client); + TestCase.assertNotNull(photo.get()); + TestCase.assertNotNull(photo.get(params)); } @Test From e241504f87a001283a7257e5b8e05271308e5a13 Mon Sep 17 00:00:00 2001 From: Anthony Roux Date: Fri, 13 Mar 2020 12:39:17 +0100 Subject: [PATCH 20/22] Fix typo --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 234b3e31..64ded17c 100644 --- a/README.md +++ b/README.md @@ -141,10 +141,9 @@ You can make any arbitrary API call as well directly with the `.get` method. Keep in mind, this returns a raw `Resource` ```java -Resource resource = amadeus.get('/v2/reference-data/urls/checkin-links', - Params.with("airlineCode", "BA")); +Response response = amadeus.get("/v2/reference-data/urls/checkin-links", Params.with("airlineCode", "BA")); -resource.getResult(); +response.getResult(); ``` ## Response From cad0689ac2e39ff2cb594bc780d82b2777ccec96 Mon Sep 17 00:00:00 2001 From: Anthony Roux Date: Wed, 18 Mar 2020 12:11:46 +0100 Subject: [PATCH 21/22] 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 --- .gitignore | 3 +- README.md | 15 +++-- src/main/java/com/amadeus/Travel.java | 2 +- .../airport/predictions/AirportOnTime.java | 8 +-- .../java/com/amadeus/resources/OnTime.java | 19 ------ .../resources/{Delay.java => Prediction.java} | 16 +++-- .../java/com/amadeus/travel/Predictions.java | 15 ++++- .../travel/predictions/FlightDelay.java | 8 +-- .../travel/predictions/TripPurpose.java | 67 +++++++++++++++++++ src/test/java/com/amadeus/NamespaceTest.java | 21 ++++-- 10 files changed, 125 insertions(+), 49 deletions(-) delete mode 100644 src/main/java/com/amadeus/resources/OnTime.java rename src/main/java/com/amadeus/resources/{Delay.java => Prediction.java} (58%) create mode 100644 src/main/java/com/amadeus/travel/predictions/TripPurpose.java diff --git a/.gitignore b/.gitignore index 301ab319..d4df65ca 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ build out .DS_Store amadeus-java.iml -Bin/ \ No newline at end of file +Bin/ +.vscode/ diff --git a/README.md b/README.md index 64ded17c..7a1787cb 100644 --- a/README.md +++ b/README.md @@ -315,14 +315,14 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt .and("west", "2.160873") .and("south", "41.394582") .and("east", "2.177181")); - + // What's the likelihood flights from this airport will leave on time? -OnTime AirportOnTime = amadeus.airport.predictions.onTime.get(Params +Prediction AirportOnTime = amadeus.airport.predictions.onTime.get(Params .with("airportCode", "NCE") - .and("date", "2020-09-01")); + .and("date", "2020-09-01")); // What's the likelihood of a given flight to be delayed? -Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params +Prediction[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params .with("originLocationCode", "NCE") .and("destinationLocationCode", "IST") .and("departureDate", "2020-08-01") @@ -353,6 +353,13 @@ SeatMap[] seatmap = amadeus.shopping.seatMaps.post(body); // AI-Generated Photos GeneratedPhoto photo = amadeus.media.files.generatedPhotos.get(Params .with("category", "BEACH")); + +// Trip Purpose Prediction +Prediction tripPurpose = amadeus.travel.predictions.tripPurpose.get(Params + .with("originLocationCode", "NYC") + .and("destinationLocationCode", "MAD") + .and("departureDate", "2020-08-01") + .and("returnDate", "2020-08-12")); ``` ## Development & Contributing diff --git a/src/main/java/com/amadeus/Travel.java b/src/main/java/com/amadeus/Travel.java index a44bd414..038d04cf 100644 --- a/src/main/java/com/amadeus/Travel.java +++ b/src/main/java/com/amadeus/Travel.java @@ -1,7 +1,7 @@ package com.amadeus; +import com.amadeus.travel.Predictions; import com.amadeus.travel.analytics.Analytics; -import com.amadeus.travel.predictions.Predictions; /** *

diff --git a/src/main/java/com/amadeus/airport/predictions/AirportOnTime.java b/src/main/java/com/amadeus/airport/predictions/AirportOnTime.java index 43ad6412..f92b27db 100644 --- a/src/main/java/com/amadeus/airport/predictions/AirportOnTime.java +++ b/src/main/java/com/amadeus/airport/predictions/AirportOnTime.java @@ -4,7 +4,7 @@ import com.amadeus.Params; import com.amadeus.Response; import com.amadeus.exceptions.ResponseException; -import com.amadeus.resources.OnTime; +import com.amadeus.resources.Prediction; import com.amadeus.resources.Resource; /** @@ -46,16 +46,16 @@ public AirportOnTime(Amadeus client) { * @return an API response object * @throws ResponseException when an exception occurs */ - public OnTime get(Params params) throws ResponseException { + public Prediction get(Params params) throws ResponseException { Response response = client.get("/v1/airport/predictions/on-time", params); - return (OnTime) Resource.fromObject(response, OnTime.class); + return (Prediction) Resource.fromObject(response, Prediction.class); } /** * Convenience method for calling get without any parameters. * @see AirportOnTime#get() */ - public OnTime get() throws ResponseException { + public Prediction get() throws ResponseException { return get(null); } } \ No newline at end of file diff --git a/src/main/java/com/amadeus/resources/OnTime.java b/src/main/java/com/amadeus/resources/OnTime.java deleted file mode 100644 index ae184682..00000000 --- a/src/main/java/com/amadeus/resources/OnTime.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.amadeus.resources; - -import lombok.Getter; -import lombok.ToString; - -/** - * An OnTime object as returned by the AirportOnTime API. - * @see com.amadeus.airport.predictions.AirportOnTime#get() - */ -@ToString -public class OnTime extends Resource { - protected OnTime() {} - - private @Getter String id; - private @Getter String probability; - private @Getter String result; - private @Getter String subType; - private @Getter String type; -} diff --git a/src/main/java/com/amadeus/resources/Delay.java b/src/main/java/com/amadeus/resources/Prediction.java similarity index 58% rename from src/main/java/com/amadeus/resources/Delay.java rename to src/main/java/com/amadeus/resources/Prediction.java index 92ef4372..211e9f38 100644 --- a/src/main/java/com/amadeus/resources/Delay.java +++ b/src/main/java/com/amadeus/resources/Prediction.java @@ -4,16 +4,18 @@ import lombok.ToString; /** - * A Delay object as returned by the FlightDelay API. - * @see com.amadeus.travel.predictions.FlightDelay#get() + * An Period object as returned by the Prediction APIs. + * + * @see com.amadeus.travel.predictions.TripPurpose#get() */ @ToString -public class Delay extends Resource { - protected Delay() {} +public class Prediction extends Resource { + protected Prediction() { + } + private @Getter String type; + private @Getter String subType; private @Getter String id; - private @Getter String probability; private @Getter String result; - private @Getter String subType; - private @Getter String type; + private @Getter String probability; } diff --git a/src/main/java/com/amadeus/travel/Predictions.java b/src/main/java/com/amadeus/travel/Predictions.java index 986867ee..82a72476 100644 --- a/src/main/java/com/amadeus/travel/Predictions.java +++ b/src/main/java/com/amadeus/travel/Predictions.java @@ -1,6 +1,8 @@ -package com.amadeus.travel.predictions; +package com.amadeus.travel; import com.amadeus.Amadeus; +import com.amadeus.travel.predictions.FlightDelay; +import com.amadeus.travel.predictions.TripPurpose; /** *

@@ -21,18 +23,25 @@ public class Predictions { /** *

- * A namespaced client for the + * A namespaced client for the + * /v1/travel/predictions/trip-purpose endpoints. + *

+ */ + public TripPurpose tripPurpose; + + /** A namespaced client for the * /v1/travel/predictions/flight-delay endpoints. *

*/ public FlightDelay flightDelay; - /** * Constructor. + * * @hide */ public Predictions(Amadeus client) { + this.tripPurpose = new TripPurpose(client); this.flightDelay = new FlightDelay(client); } } diff --git a/src/main/java/com/amadeus/travel/predictions/FlightDelay.java b/src/main/java/com/amadeus/travel/predictions/FlightDelay.java index b86a9fda..fc24d0f9 100644 --- a/src/main/java/com/amadeus/travel/predictions/FlightDelay.java +++ b/src/main/java/com/amadeus/travel/predictions/FlightDelay.java @@ -4,7 +4,7 @@ import com.amadeus.Params; import com.amadeus.Response; import com.amadeus.exceptions.ResponseException; -import com.amadeus.resources.Delay; +import com.amadeus.resources.Prediction; import com.amadeus.resources.Resource; /** @@ -54,16 +54,16 @@ public FlightDelay(Amadeus client) { * @return an API response object * @throws ResponseException when an exception occurs */ - public Delay[] get(Params params) throws ResponseException { + public Prediction[] get(Params params) throws ResponseException { Response response = client.get("/v1/travel/predictions/flight-delay", params); - return (Delay[]) Resource.fromArray(response, Delay[].class); + return (Prediction[]) Resource.fromArray(response, Prediction[].class); } /** * Convenience method for calling get without any parameters. * @see FlightDelay#get() */ - public Delay[] get() throws ResponseException { + public Prediction[] get() throws ResponseException { return get(null); } } diff --git a/src/main/java/com/amadeus/travel/predictions/TripPurpose.java b/src/main/java/com/amadeus/travel/predictions/TripPurpose.java new file mode 100644 index 00000000..f533824d --- /dev/null +++ b/src/main/java/com/amadeus/travel/predictions/TripPurpose.java @@ -0,0 +1,67 @@ +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.Prediction; +import com.amadeus.resources.Resource; + + +/** + *

+ * A namespaced client for the + * /v1/travel/predictions/trip-purpose endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.travel.predictions.tripPurpose;
+ */ +public class TripPurpose { + private Amadeus client; + + /** + * Constructor. + * + * @hide + */ + public TripPurpose(Amadeus client) { + this.client = client; + } + + /** + *

+ * Returns a trip purpose prediction. + *

+ * + *
+   * amadeus.travel.predictions.tripPurpose.get(Params
+   *   .with("originLocationCode", "NYC")
+   *   .and("destinationLocationCode", "MAD")
+   *   .and("departureDate", "2020-08-01")
+   *   .and("returnDate", "2020-08-12"));
+   *   
+ * + * @param params the parameters to send to the API + * @return an API response object + * @throws ResponseException when an exception occurs + */ + public Prediction get(Params params) throws ResponseException { + Response response = client.get("/v1/travel/predictions/trip-purpose", params); + return (Prediction) Resource.fromObject(response, Prediction.class); + } + + /** + * Convenience method for calling get without any parameters. + * + * @see TripPurpose#get() + */ + public Prediction get() throws ResponseException { + return get(null); + } +} diff --git a/src/test/java/com/amadeus/NamespaceTest.java b/src/test/java/com/amadeus/NamespaceTest.java index c72c0f47..50c7a517 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -25,6 +25,7 @@ import com.amadeus.travel.analytics.airTraffic.BusiestPeriod; import com.amadeus.travel.analytics.airTraffic.Traveled; import com.amadeus.travel.predictions.FlightDelay; +import com.amadeus.travel.predictions.TripPurpose; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import junit.framework.TestCase; @@ -52,6 +53,7 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.referenceData.airlines); TestCase.assertNotNull(client.travel.analytics.airTraffic.traveled); TestCase.assertNotNull(client.travel.analytics.airTraffic.booked); + TestCase.assertNotNull(client.travel.predictions.tripPurpose); TestCase.assertNotNull(client.travel.predictions.flightDelay); TestCase.assertNotNull(client.shopping.flightDates); TestCase.assertNotNull(client.shopping.flightDestinations); @@ -266,7 +268,14 @@ public void testGetMethods() throws ResponseException { HotelSentiments hotelSentiments = new HotelSentiments(client); TestCase.assertNotNull(hotelSentiments.get(params)); - // Test airport-on-time + // Test trip purpose prediction + Mockito.when(client.get("/v1/travel/predictions/trip-purpose", null)) + .thenReturn(singleResponse); + Mockito.when(client.get("/v1/travel/predictions/trip-purpose", params)) + .thenReturn(singleResponse); + TripPurpose tripPurpose = new TripPurpose(client); + TestCase.assertNotNull(tripPurpose.get(params)); + // Test airport-on-time Mockito.when(client.get("/v1/airport/predictions/on-time", null)) .thenReturn(singleResponse); Mockito.when(client.get("/v1/airport/predictions/on-time", params)) @@ -274,7 +283,7 @@ public void testGetMethods() throws ResponseException { AirportOnTime airportOnTime = new AirportOnTime(client); TestCase.assertNotNull(airportOnTime.get()); TestCase.assertNotNull(airportOnTime.get(params)); - + // Test flight delay predictions Mockito.when(client.get("/v1/travel/predictions/flight-delay", null)) .thenReturn(multiResponse); @@ -290,8 +299,8 @@ public void testGetMethods() throws ResponseException { Mockito.when(client.get("/v1/shopping/seatmaps", params)) .thenReturn(multiResponse); SeatMaps seatmap = new SeatMaps(client); - TestCase.assertNotNull(seatmap.get(params)); - + TestCase.assertNotNull(seatmap.get(params)); + // Test fetching a specific offer Mockito.when(client.get("/v1/booking/flight-orders/XXX", null)) .thenReturn(singleResponse); @@ -339,11 +348,11 @@ public void testPostMethods() throws ResponseException { Mockito.when(client.post("/v1/booking/flight-orders", (String) null)) .thenReturn(singleResponse); Mockito.when(client.post("/v1/booking/flight-orders", body)) - .thenReturn(singleResponse); + .thenReturn(singleResponse); FlightOrders order = new FlightOrders(client); TestCase.assertNotNull(order.post()); TestCase.assertNotNull(order.post(body)); - + // Test SeatMaps post Mockito.when(client.post("/v1/shopping/seatmaps", (String) null)) .thenReturn(multiResponse); From 215f345ae8a82abbf65c676fa76a0c7563a4f75b Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Thu, 19 Mar 2020 11:15:17 +0100 Subject: [PATCH 22/22] fix typo and add example --- .../com/amadeus/resources/FlightPayment.java | 2 +- .../flight/offers/FlightOffersPrice.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/examples/flight/offers/FlightOffersPrice.java diff --git a/src/main/java/com/amadeus/resources/FlightPayment.java b/src/main/java/com/amadeus/resources/FlightPayment.java index 237bcc57..1caefa9a 100644 --- a/src/main/java/com/amadeus/resources/FlightPayment.java +++ b/src/main/java/com/amadeus/resources/FlightPayment.java @@ -4,7 +4,7 @@ import lombok.ToString; /** - * An Airline object as returned by the Airline Code LookUp API. + * An FlightPayment object as returned by the Flight Offers Price API. * @see amadeus.shopping.flightOffersSearch.pricing#post() */ @ToString diff --git a/src/main/java/examples/flight/offers/FlightOffersPrice.java b/src/main/java/examples/flight/offers/FlightOffersPrice.java new file mode 100644 index 00000000..56c21298 --- /dev/null +++ b/src/main/java/examples/flight/offers/FlightOffersPrice.java @@ -0,0 +1,45 @@ +package examples.flight.offers; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.FlightOfferSearch; +import com.amadeus.resources.FlightPrice; + +public class FlightOffersPrice { + /** + *

+ * An example to call hotel Booking API + * /v1/shopping/flight-offers/pricing endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+   * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+   * amadeus.shopping.flightOffersSearch.pricing;
+ */ + public static void main(String[] args) throws ResponseException { + + Amadeus amadeus = Amadeus + .builder("REPLACE_BY_YOUR_API_KEY","REPLACE_BY_YOUR_API_SECRET") + .build(); + + FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.get( + Params.with("originLocationCode", "SYD") + .and("destinationLocationCode", "BKK") + .and("departureDate", "2020-11-01") + .and("returnDate", "2020-11-08") + .and("adults", 1) + .and("max", 1)); + + FlightPrice flightPricing = amadeus.shopping.flightOffersSearch.pricing.post( + flightOffersSearches, + Params.with("include", "detailed-fare-rules") + .and("forceClass", "false") + ); + System.out.println(flightPricing.getResponse()); + } +} \ No newline at end of file