Skip to content

Commit 948d6f1

Browse files
authored
Merge pull request #91 from amadeus4dev/tours-activities-support
Tours and activities support
2 parents 8ef6679 + 8c694ce commit 948d6f1

File tree

7 files changed

+325
-0
lines changed

7 files changed

+325
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,22 @@ SafePlace[] safetyScore = amadeus.safety.safetyRatedLocations.bySquare.get(Param
307307
// What is the safety information of a location based on it's Id?
308308
SafePlace safetyScore = amadeus.safety.safetyRatedLocation("Q930400801").get();
309309

310+
// Tours and Activities
311+
// What are the popular activities in Barcelona (based a geo location and a radius)
312+
Activity[] activities = amadeus.shopping.activities.get(Params
313+
.with("latitude", "41.39715")
314+
.and("longitude", "2.160873"));
315+
316+
// What are the popular activities in Barcelona? (based on a square)
317+
Activity[] activities = amadeus.shopping.activities.bySquare.get(Params
318+
.with("north", "41.397158")
319+
.and("west", "2.160873")
320+
.and("south", "41.394582")
321+
.and("east", "2.177181"));
322+
323+
// Returns a single activity from a given id
324+
Activity activity = amadeus.shopping.activity("4615").get();
325+
310326
// What's the likelihood flights from this airport will leave on time?
311327
Prediction AirportOnTime = amadeus.airport.predictions.onTime.get(Params
312328
.with("airportCode", "NCE")

src/main/java/com/amadeus/Shopping.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.amadeus;
22

3+
import com.amadeus.shopping.Activities;
4+
import com.amadeus.shopping.Activity;
35
import com.amadeus.shopping.FlightDates;
46
import com.amadeus.shopping.FlightDestinations;
57
import com.amadeus.shopping.FlightOffers;
@@ -84,6 +86,22 @@ public class Shopping {
8486
*/
8587
public SeatMaps seatMaps;
8688

89+
/**
90+
* <p>
91+
* A namespaced client for the
92+
* <code>/v1/shopping/activities</code> endpoints.
93+
* </p>
94+
*/
95+
96+
public Activity activity;
97+
/**
98+
* <p>
99+
* A namespaced client for the
100+
* <code>/v1/shopping/activities</code> endpoints.
101+
* </p>
102+
*/
103+
public Activities activities;
104+
87105
/**
88106
* Constructor.
89107
* @hide
@@ -97,6 +115,7 @@ public Shopping(Amadeus client) {
97115
this.hotelOffersByHotel = new HotelOffersByHotel(client);
98116
this.flightOffersSearch = new FlightOffersSearch(client);
99117
this.seatMaps = new SeatMaps(client);
118+
this.activities = new Activities(client);
100119
}
101120

102121
/**
@@ -108,4 +127,14 @@ public Shopping(Amadeus client) {
108127
public HotelOffer hotelOffer(String hotelId) {
109128
return new HotelOffer(client, hotelId);
110129
}
130+
131+
/**
132+
* <p>
133+
* A namespaced client for the
134+
* <code>/v1/shopping/activities/:activity_id</code> endpoints.
135+
* </p>
136+
*/
137+
public Activity activity(String activityId) {
138+
return new Activity(client, activityId);
139+
}
111140
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* An Activity object as returned by the Tours and Activities API.
8+
* @see com.amadeus.shopping.Activity#get()
9+
*/
10+
@ToString
11+
public class Activity extends Resource {
12+
protected Activity() {}
13+
14+
private @Getter String type;
15+
private @Getter String id;
16+
private @Getter String name;
17+
private @Getter String shortDescription;
18+
private @Getter String description;
19+
private @Getter GeoCode geoCode;
20+
private @Getter String rating;
21+
private @Getter String bookingLink;
22+
private @Getter String minimumDuration;
23+
private @Getter ElementaryPrice price;
24+
private @Getter String[] pictures;
25+
26+
27+
/**
28+
* An Activity-related object as returned by the Tours and Activities API.
29+
* @see com.amadeus.shopping.Activity#get()
30+
*/
31+
@ToString
32+
public class GeoCode {
33+
protected GeoCode() {}
34+
35+
private @Getter double latitude;
36+
private @Getter double longitude;
37+
}
38+
39+
@ToString
40+
public class ElementaryPrice {
41+
protected ElementaryPrice() {}
42+
43+
private @Getter String amount;
44+
private @Getter String currencyCode;
45+
}
46+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.amadeus.shopping;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Activity;
8+
import com.amadeus.resources.Resource;
9+
import com.amadeus.shopping.activities.BySquare;
10+
11+
/**
12+
* <p>
13+
* A namespaced client for the
14+
* <code>/v1/shopping/activities</code> endpoints.
15+
* </p>
16+
*
17+
* <p>
18+
* Access via the Amadeus client object.
19+
* </p>
20+
*
21+
* <pre>
22+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
23+
* amadeus.shopping.activities;</pre>
24+
*/
25+
public class Activities {
26+
private Amadeus client;
27+
28+
29+
/**
30+
* <p>
31+
* A namespaced client for the
32+
* <code>/v1/shopping/activities/by-square</code> endpoints.
33+
* </p>
34+
*/
35+
public BySquare bySquare;
36+
37+
/**
38+
* Constructor.
39+
* @hide
40+
*/
41+
public Activities(Amadeus client) {
42+
this.client = client;
43+
this.bySquare = new BySquare(client);
44+
}
45+
46+
47+
/**
48+
* <p>
49+
* Returns a list of activities near to a given point.
50+
* </p>
51+
*
52+
* <pre>
53+
* amadeus.amadeus.shopping.activities.get(Params
54+
* .with("longitude", 2.160873)
55+
* .and("latitude", 41.397158));</pre>
56+
*
57+
* @param params the parameters to send to the API
58+
* @return an API response object
59+
* @throws ResponseException when an exception occurs
60+
*/
61+
public Activity[] get(Params params) throws ResponseException {
62+
Response response = client.get("/v1/shopping/activities", params);
63+
return (Activity[]) Resource.fromArray(response, Activity[].class);
64+
}
65+
66+
/**
67+
* Convenience method for calling <code>get</code> without any parameters.
68+
* @see Activities#get()
69+
*/
70+
public Activity[] get() throws ResponseException {
71+
return get(null);
72+
}
73+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.amadeus.shopping;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Resource;
8+
9+
/**
10+
* <p>
11+
* A namespaced client for the
12+
* <code>/v1/shopping/activities</code> endpoints.
13+
* </p>
14+
*
15+
* <p>
16+
* Access via the Amadeus client object.
17+
* </p>
18+
*
19+
* <pre>
20+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
21+
* amadeus.shopping.activity;</pre>
22+
*/
23+
public class Activity {
24+
private Amadeus client;
25+
private String id;
26+
27+
28+
/**
29+
* Constructor.
30+
* @hide
31+
*/
32+
public Activity(Amadeus client, String id) {
33+
this.client = client;
34+
this.id = id;
35+
}
36+
37+
/**
38+
* <p>
39+
* Returns a single activity from a given id.
40+
* </p>
41+
*
42+
* <pre>
43+
* amadeus.shopping.activity.("4615").get();</pre>
44+
*
45+
* @param params the parameters to send to the API
46+
* @return an API response object
47+
* @throws ResponseException when an exception occurs
48+
*/
49+
public com.amadeus.resources.Activity get(Params params) throws ResponseException {
50+
String path = String.format("/v1/shopping/activities/%s", id);
51+
Response response = client.get(path, params);
52+
return (com.amadeus.resources.Activity) Resource.fromObject(
53+
response, com.amadeus.resources.Activity.class);
54+
}
55+
56+
/**
57+
* Convenience method for calling <code>get</code> without any parameters.
58+
* @see Activity#get()
59+
*/
60+
public com.amadeus.resources.Activity get() throws ResponseException {
61+
return get(null);
62+
}
63+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.amadeus.shopping.activities;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Activity;
8+
import com.amadeus.resources.Resource;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v1/shopping/activities/by-square</code> endpoints.
14+
* </p>
15+
*
16+
* <p>
17+
* Access via the Amadeus client object.
18+
* </p>
19+
*
20+
* <pre>
21+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
22+
* amadeus.shopping.activities.bySquare;</pre>
23+
*/
24+
public class BySquare {
25+
private Amadeus client;
26+
27+
/**
28+
* Constructor.
29+
* @hide
30+
*/
31+
public BySquare(Amadeus client) {
32+
this.client = client;
33+
}
34+
35+
/**
36+
* <p>
37+
* Returns a list of activities within a square defined by
38+
* cardinal points.
39+
* </p>
40+
*
41+
* <pre>
42+
* amadeus.shopping.activities.bySquare.get(Params
43+
* .with("north", 41.397158)
44+
* .and("west", 2.160873)
45+
* .and("south", 41.394582)
46+
* .and("east", 2.177181));</pre>
47+
*
48+
* @param params the parameters to send to the API
49+
* @return an API response object
50+
* @throws ResponseException when an exception occurs
51+
*/
52+
public Activity[] get(Params params) throws ResponseException {
53+
Response response = client.get("/v1/shopping/activities/by-square", params);
54+
return (Activity[]) Resource.fromArray(response, Activity[].class);
55+
}
56+
57+
/**
58+
* Convenience method for calling <code>get</code> without any parameters.
59+
* @see Activities#get()
60+
*/
61+
public Activity[] get() throws ResponseException {
62+
return get(null);
63+
}
64+
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.amadeus.referenceData.urls.CheckinLinks;
1717
import com.amadeus.safety.SafetyRatedLocations;
1818
import com.amadeus.schedule.Flights;
19+
import com.amadeus.shopping.Activities;
1920
import com.amadeus.shopping.FlightDates;
2021
import com.amadeus.shopping.FlightDestinations;
2122
import com.amadeus.shopping.FlightOffers;
@@ -62,6 +63,9 @@ public void testAllNamespacesExist() {
6263
TestCase.assertNotNull(client.travel.analytics.airTraffic.booked);
6364
TestCase.assertNotNull(client.travel.predictions.tripPurpose);
6465
TestCase.assertNotNull(client.travel.predictions.flightDelay);
66+
TestCase.assertNotNull(client.shopping.activities);
67+
TestCase.assertNotNull(client.shopping.activities.bySquare);
68+
TestCase.assertNotNull(client.shopping.activity("XXX"));
6569
TestCase.assertNotNull(client.shopping.flightDates);
6670
TestCase.assertNotNull(client.shopping.flightDestinations);
6771
TestCase.assertNotNull(client.shopping.flightOffers);
@@ -208,6 +212,36 @@ public void testGetMethods() throws ResponseException {
208212
TestCase.assertNotNull(safetyById.get(params));
209213
TestCase.assertEquals(safetyById.get().length, 2);
210214

215+
// Testing tours and activities by coordinates
216+
Mockito.when(client.get("/v1/shopping/activities", null))
217+
.thenReturn(multiResponse);
218+
Mockito.when(client.get("/v1/shopping/activities", params))
219+
.thenReturn(multiResponse);
220+
Activities activities = new Activities(client);
221+
TestCase.assertNotNull(activities.get());
222+
TestCase.assertNotNull(activities.get(params));
223+
TestCase.assertEquals(activities.get().length, 2);
224+
225+
// Testing tours and activities by square
226+
Mockito.when(client.get("/v1/shopping/activities/by-square", null))
227+
.thenReturn(multiResponse);
228+
Mockito.when(client.get("/v1/shopping/activities/by-square", params))
229+
.thenReturn(multiResponse);
230+
Activities activitiesBySquare = new Activities(client);
231+
TestCase.assertNotNull(activitiesBySquare.get());
232+
TestCase.assertNotNull(activitiesBySquare.get(params));
233+
TestCase.assertEquals(activitiesBySquare.get().length, 2);
234+
235+
// Testing retrieving tours and activities
236+
Mockito.when(client.get("/v1/shopping/activities/XXX", null))
237+
.thenReturn(multiResponse);
238+
Mockito.when(client.get("/v1/shopping/activities/XXX", params))
239+
.thenReturn(multiResponse);
240+
Activities activityById = new Activities(client);
241+
TestCase.assertNotNull(activityById.get());
242+
TestCase.assertNotNull(activityById.get(params));
243+
TestCase.assertEquals(activityById.get().length, 2);
244+
211245
// Testing fetching a single location
212246
Mockito.when(client.get("/v1/reference-data/locations/ALHR", null))
213247
.thenReturn(singleResponse);

0 commit comments

Comments
 (0)