Skip to content

Commit

Permalink
Merge pull request #91 from amadeus4dev/tours-activities-support
Browse files Browse the repository at this point in the history
Tours and activities support
  • Loading branch information
tsolakoua authored Oct 5, 2020
2 parents 8ef6679 + 8c694ce commit 948d6f1
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ SafePlace[] safetyScore = amadeus.safety.safetyRatedLocations.bySquare.get(Param
// What is the safety information of a location based on it's Id?
SafePlace safetyScore = amadeus.safety.safetyRatedLocation("Q930400801").get();

// Tours and Activities
// What are the popular activities in Barcelona (based a geo location and a radius)
Activity[] activities = amadeus.shopping.activities.get(Params
.with("latitude", "41.39715")
.and("longitude", "2.160873"));

// What are the popular activities in Barcelona? (based on a square)
Activity[] activities = amadeus.shopping.activities.bySquare.get(Params
.with("north", "41.397158")
.and("west", "2.160873")
.and("south", "41.394582")
.and("east", "2.177181"));

// Returns a single activity from a given id
Activity activity = amadeus.shopping.activity("4615").get();

// What's the likelihood flights from this airport will leave on time?
Prediction AirportOnTime = amadeus.airport.predictions.onTime.get(Params
.with("airportCode", "NCE")
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/amadeus/Shopping.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.amadeus;

import com.amadeus.shopping.Activities;
import com.amadeus.shopping.Activity;
import com.amadeus.shopping.FlightDates;
import com.amadeus.shopping.FlightDestinations;
import com.amadeus.shopping.FlightOffers;
Expand Down Expand Up @@ -84,6 +86,22 @@ public class Shopping {
*/
public SeatMaps seatMaps;

/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/activities</code> endpoints.
* </p>
*/

public Activity activity;
/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/activities</code> endpoints.
* </p>
*/
public Activities activities;

/**
* Constructor.
* @hide
Expand All @@ -97,6 +115,7 @@ public Shopping(Amadeus client) {
this.hotelOffersByHotel = new HotelOffersByHotel(client);
this.flightOffersSearch = new FlightOffersSearch(client);
this.seatMaps = new SeatMaps(client);
this.activities = new Activities(client);
}

/**
Expand All @@ -108,4 +127,14 @@ public Shopping(Amadeus client) {
public HotelOffer hotelOffer(String hotelId) {
return new HotelOffer(client, hotelId);
}

/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/activities/:activity_id</code> endpoints.
* </p>
*/
public Activity activity(String activityId) {
return new Activity(client, activityId);
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/amadeus/resources/Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.amadeus.resources;

import lombok.Getter;
import lombok.ToString;

/**
* An Activity object as returned by the Tours and Activities API.
* @see com.amadeus.shopping.Activity#get()
*/
@ToString
public class Activity extends Resource {
protected Activity() {}

private @Getter String type;
private @Getter String id;
private @Getter String name;
private @Getter String shortDescription;
private @Getter String description;
private @Getter GeoCode geoCode;
private @Getter String rating;
private @Getter String bookingLink;
private @Getter String minimumDuration;
private @Getter ElementaryPrice price;
private @Getter String[] pictures;


/**
* An Activity-related object as returned by the Tours and Activities API.
* @see com.amadeus.shopping.Activity#get()
*/
@ToString
public class GeoCode {
protected GeoCode() {}

private @Getter double latitude;
private @Getter double longitude;
}

@ToString
public class ElementaryPrice {
protected ElementaryPrice() {}

private @Getter String amount;
private @Getter String currencyCode;
}
}
73 changes: 73 additions & 0 deletions src/main/java/com/amadeus/shopping/Activities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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.Activity;
import com.amadeus.resources.Resource;
import com.amadeus.shopping.activities.BySquare;

/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/activities</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.shopping.activities;</pre>
*/
public class Activities {
private Amadeus client;


/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/activities/by-square</code> endpoints.
* </p>
*/
public BySquare bySquare;

/**
* Constructor.
* @hide
*/
public Activities(Amadeus client) {
this.client = client;
this.bySquare = new BySquare(client);
}


/**
* <p>
* Returns a list of activities near to a given point.
* </p>
*
* <pre>
* amadeus.amadeus.shopping.activities.get(Params
* .with("longitude", 2.160873)
* .and("latitude", 41.397158));</pre>
*
* @param params the parameters to send to the API
* @return an API response object
* @throws ResponseException when an exception occurs
*/
public Activity[] get(Params params) throws ResponseException {
Response response = client.get("/v1/shopping/activities", params);
return (Activity[]) Resource.fromArray(response, Activity[].class);
}

/**
* Convenience method for calling <code>get</code> without any parameters.
* @see Activities#get()
*/
public Activity[] get() throws ResponseException {
return get(null);
}
}
63 changes: 63 additions & 0 deletions src/main/java/com/amadeus/shopping/Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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;

/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/activities</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.shopping.activity;</pre>
*/
public class Activity {
private Amadeus client;
private String id;


/**
* Constructor.
* @hide
*/
public Activity(Amadeus client, String id) {
this.client = client;
this.id = id;
}

/**
* <p>
* Returns a single activity from a given id.
* </p>
*
* <pre>
* amadeus.shopping.activity.("4615").get();</pre>
*
* @param params the parameters to send to the API
* @return an API response object
* @throws ResponseException when an exception occurs
*/
public com.amadeus.resources.Activity get(Params params) throws ResponseException {
String path = String.format("/v1/shopping/activities/%s", id);
Response response = client.get(path, params);
return (com.amadeus.resources.Activity) Resource.fromObject(
response, com.amadeus.resources.Activity.class);
}

/**
* Convenience method for calling <code>get</code> without any parameters.
* @see Activity#get()
*/
public com.amadeus.resources.Activity get() throws ResponseException {
return get(null);
}
}
64 changes: 64 additions & 0 deletions src/main/java/com/amadeus/shopping/activities/BySquare.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.amadeus.shopping.activities;

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

/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/activities/by-square</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.shopping.activities.bySquare;</pre>
*/
public class BySquare {
private Amadeus client;

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

/**
* <p>
* Returns a list of activities within a square defined by
* cardinal points.
* </p>
*
* <pre>
* amadeus.shopping.activities.bySquare.get(Params
* .with("north", 41.397158)
* .and("west", 2.160873)
* .and("south", 41.394582)
* .and("east", 2.177181));</pre>
*
* @param params the parameters to send to the API
* @return an API response object
* @throws ResponseException when an exception occurs
*/
public Activity[] get(Params params) throws ResponseException {
Response response = client.get("/v1/shopping/activities/by-square", params);
return (Activity[]) Resource.fromArray(response, Activity[].class);
}

/**
* Convenience method for calling <code>get</code> without any parameters.
* @see Activities#get()
*/
public Activity[] get() throws ResponseException {
return get(null);
}
}
34 changes: 34 additions & 0 deletions src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.amadeus.referenceData.urls.CheckinLinks;
import com.amadeus.safety.SafetyRatedLocations;
import com.amadeus.schedule.Flights;
import com.amadeus.shopping.Activities;
import com.amadeus.shopping.FlightDates;
import com.amadeus.shopping.FlightDestinations;
import com.amadeus.shopping.FlightOffers;
Expand Down Expand Up @@ -62,6 +63,9 @@ public void testAllNamespacesExist() {
TestCase.assertNotNull(client.travel.analytics.airTraffic.booked);
TestCase.assertNotNull(client.travel.predictions.tripPurpose);
TestCase.assertNotNull(client.travel.predictions.flightDelay);
TestCase.assertNotNull(client.shopping.activities);
TestCase.assertNotNull(client.shopping.activities.bySquare);
TestCase.assertNotNull(client.shopping.activity("XXX"));
TestCase.assertNotNull(client.shopping.flightDates);
TestCase.assertNotNull(client.shopping.flightDestinations);
TestCase.assertNotNull(client.shopping.flightOffers);
Expand Down Expand Up @@ -208,6 +212,36 @@ public void testGetMethods() throws ResponseException {
TestCase.assertNotNull(safetyById.get(params));
TestCase.assertEquals(safetyById.get().length, 2);

// Testing tours and activities by coordinates
Mockito.when(client.get("/v1/shopping/activities", null))
.thenReturn(multiResponse);
Mockito.when(client.get("/v1/shopping/activities", params))
.thenReturn(multiResponse);
Activities activities = new Activities(client);
TestCase.assertNotNull(activities.get());
TestCase.assertNotNull(activities.get(params));
TestCase.assertEquals(activities.get().length, 2);

// Testing tours and activities by square
Mockito.when(client.get("/v1/shopping/activities/by-square", null))
.thenReturn(multiResponse);
Mockito.when(client.get("/v1/shopping/activities/by-square", params))
.thenReturn(multiResponse);
Activities activitiesBySquare = new Activities(client);
TestCase.assertNotNull(activitiesBySquare.get());
TestCase.assertNotNull(activitiesBySquare.get(params));
TestCase.assertEquals(activitiesBySquare.get().length, 2);

// Testing retrieving tours and activities
Mockito.when(client.get("/v1/shopping/activities/XXX", null))
.thenReturn(multiResponse);
Mockito.when(client.get("/v1/shopping/activities/XXX", params))
.thenReturn(multiResponse);
Activities activityById = new Activities(client);
TestCase.assertNotNull(activityById.get());
TestCase.assertNotNull(activityById.get(params));
TestCase.assertEquals(activityById.get().length, 2);

// Testing fetching a single location
Mockito.when(client.get("/v1/reference-data/locations/ALHR", null))
.thenReturn(singleResponse);
Expand Down

0 comments on commit 948d6f1

Please sign in to comment.