Skip to content

Commit

Permalink
Merge pull request #83 from amadeus4dev/travel-recommendations
Browse files Browse the repository at this point in the history
Add support for Travel Recommendations API
  • Loading branch information
tsolakoua authored Jul 27, 2020
2 parents 3d3ef78 + 0d29f94 commit bc0a60e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/amadeus/ReferenceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -48,6 +49,14 @@ public class ReferenceData {
*/
public Airlines airlines;

/**
* <p>
* A namespaced client for the
* <code>/v1/reference-data/recommended-locations</code> endpoints.
* </p>
*/
public RecommendedLocations recommendedLocations;


/**
* Constructor.
Expand All @@ -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);
}

/**
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/com/amadeus/referenceData/RecommendedLocations.java
Original file line number Diff line number Diff line change
@@ -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;

/**
* <p>
* A namespaced client for the
* <code>/v1/reference-data/recommended-locations</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.referenceData.recommendedLocations;</pre>
*/
public class RecommendedLocations {
private Amadeus client;

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

/**
* <p>
* Returns a list of destination recommendations.
* </p>
*
* <pre>
* amadeus.referenceData.recommendedLocations.get(Params
* .with("cityCodes", "PAR")
* .and("travelerCountryCode", "FR"));</pre>
*
* @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 <code>get</code> without any parameters.
* @see Location#get()
*/
public Location[] get() throws ResponseException {
return get(null);
}
}
12 changes: 12 additions & 0 deletions src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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.locations.Airports;
import com.amadeus.referenceData.locations.PointsOfInterest;
import com.amadeus.referenceData.urls.CheckinLinks;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bc0a60e

Please sign in to comment.