From 393e81b4aa4aeda31a07e2a7645ccf4954bbb6ab Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Mon, 27 Jul 2020 15:39:41 +0200 Subject: [PATCH 1/3] add travel recommendations --- README.md | 5 ++ src/main/java/com/amadeus/ReferenceData.java | 10 +++ .../referenceData/RecommendedLocations.java | 62 +++++++++++++++++++ src/test/java/com/amadeus/NamespaceTest.java | 12 ++++ 4 files changed, 89 insertions(+) create mode 100644 src/main/java/com/amadeus/referenceData/RecommendedLocations.java diff --git a/README.md b/README.md index 0b3ca689..12f9cbb7 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,11 @@ Prediction tripPurpose = amadeus.travel.predictions.tripPurpose.get(Params .and("destinationLocationCode", "MAD") .and("departureDate", "2020-08-01") .and("returnDate", "2020-08-12")); + +// Travel Recommendations +Location destinations = amadeus.referenceData.recommendedLocations.get(Params + .with("cityCodes", "PAR") + .and("travelerCountryCode", "FR")); ``` ## Development & Contributing diff --git a/src/main/java/com/amadeus/ReferenceData.java b/src/main/java/com/amadeus/ReferenceData.java index 34f2700f..3b96d843 100644 --- a/src/main/java/com/amadeus/ReferenceData.java +++ b/src/main/java/com/amadeus/ReferenceData.java @@ -3,6 +3,7 @@ import com.amadeus.referenceData.Airlines; import com.amadeus.referenceData.Location; import com.amadeus.referenceData.Locations; +import com.amadeus.referenceData.RecommendedLocations; import com.amadeus.referenceData.Urls; /** @@ -48,6 +49,14 @@ public class ReferenceData { */ public Airlines airlines; + /** + *

+ * A namespaced client for the + * /v1/reference-data/recommended-locations endpoints. + *

+ */ + public RecommendedLocations recommendedLocations; + /** * Constructor. @@ -58,6 +67,7 @@ public ReferenceData(Amadeus client) { this.urls = new Urls(client); this.locations = new Locations(client); this.airlines = new Airlines(client); + this.recommendedLocations = new RecommendedLocations(client); } /** diff --git a/src/main/java/com/amadeus/referenceData/RecommendedLocations.java b/src/main/java/com/amadeus/referenceData/RecommendedLocations.java new file mode 100644 index 00000000..c2518965 --- /dev/null +++ b/src/main/java/com/amadeus/referenceData/RecommendedLocations.java @@ -0,0 +1,62 @@ +package com.amadeus.referenceData; + +import com.amadeus.Amadeus; +import com.amadeus.Params; +import com.amadeus.Response; +import com.amadeus.exceptions.ResponseException; +import com.amadeus.resources.Location; +import com.amadeus.resources.Resource; +import com.google.gson.Gson; + +/** + *

+ * A namespaced client for the + * /v1/reference-data/recommended-locations endpoints. + *

+ * + *

+ * Access via the Amadeus client object. + *

+ * + *
+ * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
+ * amadeus.referenceData.locations.recommendedLocations;
+ */ +public class RecommendedLocations { + private Amadeus client; + + /** + * Constructor. + * @hide + */ + public RecommendedLocations(Amadeus client) { + this.client = client; + } + + /** + *

+ * Returns a list of destination recommendations. + *

+ * + *
+   * amadeus.referenceData.locations.recommendedLocations.get(Params
+   *   .with("cityCodes", "PAR")
+   *   .and("travelerCountryCode", "FR"));
+ * + * @param params the parameters to send to the API + * @return an API response object + * @throws ResponseException when an exception occurs + */ + public Location[] get(Params params) throws ResponseException { + Response response = client.get("/v1/reference-data/recommended-locations", params); + return (Location[]) Resource.fromArray(response, Location[].class); + } + + /** + * Convenience method for calling get without any parameters. + * @see Location#get() + */ + public Location[] 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 773a5433..018e31a1 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -12,6 +12,7 @@ import com.amadeus.referenceData.Locations; import com.amadeus.referenceData.locations.Airports; import com.amadeus.referenceData.locations.PointsOfInterest; +import com.amadeus.referenceData.RecommendedLocations; import com.amadeus.referenceData.urls.CheckinLinks; import com.amadeus.safety.SafetyRatedLocations; import com.amadeus.shopping.FlightDates; @@ -54,6 +55,7 @@ public void testAllNamespacesExist() { TestCase.assertNotNull(client.referenceData.locations.pointsOfInterest.bySquare); TestCase.assertNotNull(client.referenceData.locations.pointOfInterest("XXX")); TestCase.assertNotNull(client.referenceData.location("123")); + TestCase.assertNotNull(client.referenceData.recommendedLocations); TestCase.assertNotNull(client.referenceData.airlines); TestCase.assertNotNull(client.travel.analytics.airTraffic.traveled); TestCase.assertNotNull(client.travel.analytics.airTraffic.booked); @@ -164,6 +166,16 @@ public void testGetMethods() throws ResponseException { TestCase.assertNotNull(poi.get(params)); TestCase.assertEquals(poi.get().length, 2); + // Testing travel recommendations + Mockito.when(client.get("/v1/reference-data/recommended-locations", null)) + .thenReturn(multiResponse); + Mockito.when(client.get("/v1/reference-data/recommended-locations", params)) + .thenReturn(multiResponse); + RecommendedLocations destinations = new RecommendedLocations(client); + TestCase.assertNotNull(destinations.get()); + TestCase.assertNotNull(destinations.get(params)); + TestCase.assertEquals(destinations.get().length, 2); + // Testing safe place by coordinates Mockito.when(client.get("/v1/safety/safety-rated-locations", null)) .thenReturn(multiResponse); From 21f6707c748ace557157835cbc0b92967db3f0f9 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Mon, 27 Jul 2020 15:45:23 +0200 Subject: [PATCH 2/3] fix import order in test --- 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 018e31a1..10eb9aeb 100644 --- a/src/test/java/com/amadeus/NamespaceTest.java +++ b/src/test/java/com/amadeus/NamespaceTest.java @@ -10,9 +10,9 @@ import com.amadeus.referenceData.Airlines; import com.amadeus.referenceData.Location; import com.amadeus.referenceData.Locations; +import com.amadeus.referenceData.RecommendedLocations; import com.amadeus.referenceData.locations.Airports; import com.amadeus.referenceData.locations.PointsOfInterest; -import com.amadeus.referenceData.RecommendedLocations; import com.amadeus.referenceData.urls.CheckinLinks; import com.amadeus.safety.SafetyRatedLocations; import com.amadeus.shopping.FlightDates; From 0d29f94a5555f308249c19f7afba05ce8367b4a8 Mon Sep 17 00:00:00 2001 From: Anna Tsolakou Date: Mon, 27 Jul 2020 16:56:37 +0200 Subject: [PATCH 3/3] fix docs --- .../java/com/amadeus/referenceData/RecommendedLocations.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/amadeus/referenceData/RecommendedLocations.java b/src/main/java/com/amadeus/referenceData/RecommendedLocations.java index c2518965..4edb5073 100644 --- a/src/main/java/com/amadeus/referenceData/RecommendedLocations.java +++ b/src/main/java/com/amadeus/referenceData/RecommendedLocations.java @@ -20,7 +20,7 @@ * *
  * Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
- * amadeus.referenceData.locations.recommendedLocations;
+ * amadeus.referenceData.recommendedLocations; */ public class RecommendedLocations { private Amadeus client; @@ -39,7 +39,7 @@ public RecommendedLocations(Amadeus client) { *

* *
-   * amadeus.referenceData.locations.recommendedLocations.get(Params
+   * amadeus.referenceData.recommendedLocations.get(Params
    *   .with("cityCodes", "PAR")
    *   .and("travelerCountryCode", "FR"));
*