Skip to content

Commit bbcc6a4

Browse files
committed
Add hotel APIs
1 parent 96d3d82 commit bbcc6a4

File tree

6 files changed

+285
-0
lines changed

6 files changed

+285
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.amadeus.shopping.FlightDates;
44
import com.amadeus.shopping.FlightDestinations;
55
import com.amadeus.shopping.FlightOffers;
6+
import com.amadeus.shopping.Hotel;
7+
import com.amadeus.shopping.HotelOffers;
68

79
/**
810
* <p>
@@ -21,6 +23,8 @@
2123
* @hide
2224
*/
2325
public class Shopping {
26+
private Amadeus client;
27+
2428
/**
2529
* <p>
2630
* A namespaced client for the
@@ -45,13 +49,33 @@ public class Shopping {
4549
*/
4650
public FlightOffers flightOffers;
4751

52+
/**
53+
* <p>
54+
* A namespaced client for the
55+
* <code>/v1/shopping/hotel-offers</code> endpoints.
56+
* </p>
57+
*/
58+
public HotelOffers hotelOffers;
59+
4860
/**
4961
* Constructor.
5062
* @hide
5163
*/
5264
public Shopping(Amadeus client) {
65+
this.client = client;
5366
this.flightDates = new FlightDates(client);
5467
this.flightDestinations = new FlightDestinations(client);
5568
this.flightOffers = new FlightOffers(client);
69+
this.hotelOffers = new HotelOffers(client);
70+
}
71+
72+
/**
73+
* <p>
74+
* A namespaced client for the
75+
* <code>/v1/shopping/hotel/:hotel_id</code> endpoints.
76+
* </p>
77+
*/
78+
public Hotel hotel(String hotelId) {
79+
return new Hotel(client, hotelId);
5680
}
5781
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.amadeus.shopping;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.shopping.hotel.HotelOffers;
5+
import com.amadeus.shopping.hotel.Offer;
6+
7+
/**
8+
* <p>
9+
* A namespaced client for the
10+
* <code>/v1/shopping/hotels</code> endpoints.
11+
* </p>
12+
*
13+
* <p>
14+
* Access via the Amadeus client object.
15+
* </p>
16+
*
17+
* <pre>
18+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
19+
* amadeus.shopping.hotel("SMPARCOL");</pre>
20+
*/
21+
public class Hotel {
22+
private Amadeus client;
23+
private String hotelId;
24+
25+
/**
26+
* <p>
27+
* A namespaced client for the
28+
* <code>/v1/shopping/hotel/hotel-offers</code> endpoints.
29+
* </p>
30+
*/
31+
public HotelOffers hotelOffers;
32+
33+
/**
34+
* Constructor.
35+
* @hide
36+
*/
37+
public Hotel(Amadeus client, String hotelId) {
38+
this.client = client;
39+
this.hotelId = hotelId;
40+
this.hotelOffers = new HotelOffers(client, hotelId);
41+
}
42+
43+
/**
44+
* <p>
45+
* A namespaced client for the
46+
* <code>/v1/shopping/hotel/:hotel_id/offer</code> endpoints.
47+
* </p>
48+
*/
49+
public Offer offer(String offerId) {
50+
return new Offer(client, hotelId, offerId);
51+
}
52+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
8+
/**
9+
* <p>
10+
* A namespaced client for the
11+
* <code>/v1/shopping/hotel-offers</code> endpoints.
12+
* </p>
13+
*
14+
* <p>
15+
* Access via the Amadeus client object.
16+
* </p>
17+
*
18+
* <pre>
19+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
20+
* amadeus.shopping.hotelOffers;</pre>
21+
*/
22+
public class HotelOffers {
23+
private Amadeus client;
24+
25+
/**
26+
* Constructor.
27+
* @hide
28+
*/
29+
public HotelOffers(Amadeus client) {
30+
this.client = client;
31+
}
32+
33+
/**
34+
* <p>
35+
* Search for hotels and retrieve availability and rates information.
36+
* </p>
37+
*
38+
* <pre>
39+
* amadeus.shopping.hotelOffers.get(Params
40+
* .with("cityCode", "PAR"));</pre>
41+
*
42+
* @param params the parameters to send to the API
43+
* @return an API response object
44+
* @throws ResponseException when an exception occurs
45+
*/
46+
public Response get(Params params) throws ResponseException {
47+
return client.get("/v1/shopping/hotel-offers", params);
48+
}
49+
50+
/**
51+
* Convenience method for calling <code>get</code> without any parameters.
52+
* @see HotelOffers#get()
53+
*/
54+
public Response get() throws ResponseException {
55+
return get(null);
56+
}
57+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.amadeus.shopping.hotel;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
8+
/**
9+
* <p>
10+
* A namespaced client for the
11+
* <code>/v1/shopping/hotels/:hotel_id/hotel-offers</code> endpoints.
12+
* </p>
13+
*
14+
* <p>
15+
* Access via the Amadeus client object.
16+
* </p>
17+
*
18+
* <pre>
19+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
20+
* amadeus.shopping.hotel(hotelId).hotelOffers;</pre>
21+
*/
22+
public class HotelOffers {
23+
private Amadeus client;
24+
private String hotelId;
25+
26+
/**
27+
* Constructor.
28+
* @hide
29+
*/
30+
public HotelOffers(Amadeus client, String hotelId) {
31+
this.client = client;
32+
this.hotelId = hotelId;
33+
}
34+
35+
/**
36+
* <p>
37+
* Get one hotel and its available offers.
38+
* </p>
39+
*
40+
* <pre>
41+
* amadeus.shopping.hotel("SMPARCOL").hotelOffers.get();</pre>
42+
*
43+
* @param params the parameters to send to the API
44+
* @return an API response object
45+
* @throws ResponseException when an exception occurs
46+
*/
47+
public Response get(Params params) throws ResponseException {
48+
String path = String.format("/v1/shopping/hotels/%s/hotel-offers", hotelId);
49+
return client.get(path, params);
50+
}
51+
52+
/**
53+
* Convenience method for calling <code>get</code> without any parameters.
54+
* @see HotelOffers#get()
55+
*/
56+
public Response get() throws ResponseException {
57+
return get(null);
58+
}
59+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.amadeus.shopping.hotel;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
8+
/**
9+
* <p>
10+
* A namespaced client for the
11+
* <code>/v1/shopping/hotel/:hotel_id/offers</code> endpoints.
12+
* </p>
13+
*
14+
* <p>
15+
* Access via the Amadeus client object.
16+
* </p>
17+
*
18+
* <pre>
19+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
20+
* amadeus.shopping.hotel(hotelId).offers;</pre>
21+
*/
22+
public class Offer {
23+
private Amadeus client;
24+
private String hotelId;
25+
private String offerId;
26+
27+
/**
28+
* Constructor.
29+
* @hide
30+
*/
31+
public Offer(Amadeus client, String hotelId, String offerId) {
32+
this.client = client;
33+
this.hotelId = hotelId;
34+
this.offerId = offerId;
35+
}
36+
37+
/**
38+
* <p>
39+
* Get room and rate details.
40+
* </p>
41+
*
42+
* <pre>
43+
* amadeus.shopping.hotel("SMPARCOL")
44+
* .offer("AC7D4DA2C322A73AF0824318A4965DA2805A3FC2")
45+
* .get();</pre>
46+
*
47+
* @param params the parameters to send to the API
48+
* @return an API response object
49+
* @throws ResponseException when an exception occurs
50+
*/
51+
public Response get(Params params) throws ResponseException {
52+
String path = String.format("/v1/shopping/hotels/%s/offers/%s", hotelId, offerId);
53+
return client.get(path, params);
54+
}
55+
56+
/**
57+
* Convenience method for calling <code>get</code> without any parameters.
58+
* @see Offer#get()
59+
*/
60+
public Response get() throws ResponseException {
61+
return get(null);
62+
}
63+
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.amadeus.shopping.FlightDates;
1111
import com.amadeus.shopping.FlightDestinations;
1212
import com.amadeus.shopping.FlightOffers;
13+
import com.amadeus.shopping.HotelOffers;
14+
import com.amadeus.shopping.hotel.Offer;
1315
import com.amadeus.travel.analytics.FareSearches;
1416
import com.amadeus.travel.analytics.airTraffic.Traveled;
1517
import org.junit.Test;
@@ -23,6 +25,9 @@ public class NamespaceTest {
2325
assertNotNull(client.shopping.flightDates);
2426
assertNotNull(client.shopping.flightDestinations);
2527
assertNotNull(client.shopping.flightOffers);
28+
assertNotNull(client.shopping.hotelOffers);
29+
assertNotNull(client.shopping.hotel("123").hotelOffers);
30+
assertNotNull(client.shopping.hotel("123").offer("234"));
2631
}
2732

2833
@Test public void testGetMethods() throws ResponseException {
@@ -76,5 +81,30 @@ public class NamespaceTest {
7681
FlightOffers flightOffers = new FlightOffers(client);
7782
assertTrue(flightOffers.get() instanceof Response);
7883
assertTrue(flightOffers.get(params) instanceof Response);
84+
85+
when(client.get("/v1/shopping/hotel-offers", null))
86+
.thenReturn(mock(Response.class));
87+
when(client.get("/v1/shopping/hotel-offers", params))
88+
.thenReturn(mock(Response.class));
89+
HotelOffers hotelOffers = new HotelOffers(client);
90+
assertTrue(hotelOffers.get() instanceof Response);
91+
assertTrue(hotelOffers.get(params) instanceof Response);
92+
93+
when(client.get("/v1/shopping/hotels/123/hotel-offers", null))
94+
.thenReturn(mock(Response.class));
95+
when(client.get("/v1/shopping/hotels/123/hotel-offers", params))
96+
.thenReturn(mock(Response.class));
97+
com.amadeus.shopping.hotel.HotelOffers hotelOffers2
98+
= new com.amadeus.shopping.hotel.HotelOffers(client, "123");
99+
assertTrue(hotelOffers2.get() instanceof Response);
100+
assertTrue(hotelOffers2.get(params) instanceof Response);
101+
102+
when(client.get("/v1/shopping/hotels/123/offers/234", null))
103+
.thenReturn(mock(Response.class));
104+
when(client.get("/v1/shopping/hotels/123/offers/234", params))
105+
.thenReturn(mock(Response.class));
106+
Offer offer = new Offer(client, "123", "234");
107+
assertTrue(offer.get() instanceof Response);
108+
assertTrue(offer.get(params) instanceof Response);
79109
}
80110
}

0 commit comments

Comments
 (0)