Skip to content

Commit 802e2a7

Browse files
authored
Add support for Flight Offers Search POST (#35)
#35 Add support for Flight Offers Search POST
1 parent 6bb7412 commit 802e2a7

File tree

9 files changed

+132
-14
lines changed

9 files changed

+132
-14
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,18 @@ FlightOffer[] flightOffers = amadeus.shopping.flightOffers.get(Params
225225
.and("destination", "MAD")
226226
.and("departureDate", "2019-08-01"));
227227

228-
// Flight Offer Search v2
228+
// Flight Offer Search v2 GET
229229
FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.get(
230230
Params.with("originLocationCode", "SYD")
231231
.and("destinationLocationCode", "BKK")
232232
.and("departureDate", "2020-01-01")
233233
.and("returnDate", "2020-01-05")
234234
.and("adults", 2)
235-
.and("max", 3)
236-
);
235+
.and("max", 3));
236+
237+
// Flight Offer Search v2 POST
238+
// body can be a String version of your JSON or a JsonObject
239+
FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.post(body);
237240

238241
// Flight Choice Prediction
239242
// Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=com.amadeus
2-
VERSION_NAME=3.2.0
2+
VERSION_NAME=3.3.0
33

44
POM_URL=https://github.com/amadeus4dev/amadeus-java
55
POM_SCM_URL[email protected]:amadeus4dev/amadeus-java.git

src/main/java/com/amadeus/Amadeus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Amadeus extends HTTPClient {
2525
/**
2626
* The API version.
2727
*/
28-
public static final String VERSION = "3.2.0";
28+
public static final String VERSION = "3.3.0";
2929

3030
/**
3131
* <p>

src/main/java/com/amadeus/Request.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ private void prepareHeaders() {
139139

140140
if (bearerToken != null) {
141141
headers.put(Constants.AUTHORIZATION, bearerToken);
142+
headers.put(Constants.CONTENT_TYPE, "application/vnd.amadeus+json");
143+
142144
}
143145
}
144146

src/main/java/com/amadeus/resources/FlightOfferSearch.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import lombok.Getter;
66
import lombok.ToString;
77

8-
8+
/**
9+
* An Airline object as returned by the Airline Code LookUp API.
10+
* @see com.amadeus.shopping.flightOffersSearch#get()
11+
*/
912
@ToString
1013
public class FlightOfferSearch extends Resource {
1114
protected FlightOfferSearch() {}

src/main/java/com/amadeus/shopping/FlightOffersSearch.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,111 @@
66
import com.amadeus.exceptions.ResponseException;
77
import com.amadeus.resources.FlightOfferSearch;
88
import com.amadeus.resources.Resource;
9+
import com.google.gson.JsonObject;
910

11+
/**
12+
* <p>
13+
* A namespaced client for the
14+
* <code>/v2/shopping/flight-offers</code> endpoints.
15+
* </p>
16+
*
17+
* <p>
18+
* Access via the Amadeus client object.
19+
* </p>
20+
*
21+
* <pre>
22+
* Amadeus amadeus = Amadeus.builder(API_KEY, API_SECRET).build();
23+
* amadeus.shopping.flightOffersSearch;</pre>
24+
*/
1025
public class FlightOffersSearch {
1126
private Amadeus client;
1227

28+
/**
29+
* Constructor.
30+
*
31+
* @hide
32+
*/
1333
public FlightOffersSearch(Amadeus client) {
1434
this.client = client;
1535
}
1636

37+
/**
38+
* <p>
39+
* The Flight Offers Search API allows to get cheapest flight recommendations on a given journey.
40+
* It provides a list of flight recommendations and fares from a given origin,
41+
* for a given date and for a given list of passengers.
42+
* Additional information such as bag allowance,
43+
* first ancillary bag prices or fare details are also provided.
44+
* </p>
45+
*
46+
* <pre>
47+
* amadeus.shopping.flightOffersSearch.get(params);</pre>
48+
*
49+
* @param params the parameters to send to the API
50+
* @return an API resource
51+
* @throws ResponseException when an exception occurs
52+
*/
1753
public FlightOfferSearch[] get(Params params) throws ResponseException {
1854
Response response = client.get("/v2/shopping/flight-offers", params);
1955
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
2056
}
57+
58+
/**
59+
* Convenience method for calling <code>get</code> without any parameters.
60+
* @see FlightOffersSearch#get()
61+
*/
62+
public FlightOfferSearch[] get() throws ResponseException {
63+
return get(null);
64+
}
65+
66+
/**
67+
* <p>
68+
* The Flight Offers Search API allows to get cheapest flight recommendations on a given journey.
69+
* It provides a list of flight recommendations and fares from a given origin,
70+
* for a given date and for a given list of passengers.
71+
* Additional information such as bag allowance,
72+
* first ancillary bag prices or fare details are also provided.
73+
* </p>
74+
*
75+
* <pre>
76+
* amadeus.shopping.flightOffersSearch.post(body);</pre>
77+
*
78+
* @param body the parameters to send to the API as a JSonObject
79+
* @return an API resource
80+
* @throws ResponseException when an exception occurs
81+
*/
82+
public FlightOfferSearch[] post(JsonObject body) throws ResponseException {
83+
Response response = client.post("/v2/shopping/flight-offers", body);
84+
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
85+
}
86+
87+
/**
88+
* <p>
89+
* The Flight Offers Search API allows to get cheapest flight recommendations on a given journey.
90+
* It provides a list of flight recommendations and fares from a given origin,
91+
* for a given date and for a given list of passengers.
92+
* Additional information such as bag allowance,
93+
* first ancillary bag prices or fare details are also provided.
94+
* </p>
95+
*
96+
* <pre>
97+
* amadeus.shopping.flightOffers.prediction.post(body);</pre>
98+
*
99+
* @param body the parameters to send to the API as a String
100+
* @return an API resource
101+
* @throws ResponseException when an exception occurs
102+
*/
103+
public FlightOfferSearch[] post(String body) throws ResponseException {
104+
Response response = client.post("/v2/shopping/flight-offers", body);
105+
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
106+
}
107+
108+
/**
109+
* Convenience method for calling <code>post</code> without any parameters.
110+
*
111+
* @see FlightOffersSearch#post()
112+
*/
113+
public FlightOfferSearch[] post() throws ResponseException {
114+
return post((String) null);
115+
}
21116
}

src/test/java/com/amadeus/AmadeusTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testBuilderWithInvalidEnvironment() {
5252
}*/
5353

5454
@Test public void testVersion() {
55-
assertEquals("should have a version number", Amadeus.VERSION, "3.2.0");
55+
assertEquals("should have a version number", Amadeus.VERSION, "3.3.0");
5656
}
5757

5858
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class NamespaceTest {
3535
private Response singleResponse;
3636
private Response multiResponse;
3737
private String body;
38+
private JsonObject jsonObject;
3839

3940
@Test
4041
public void testAllNamespacesExist() {
@@ -75,7 +76,7 @@ public void setup() {
7576
Mockito.when(multiResponse.getData()).thenReturn(jsonArray);
7677

7778
// Prepare a single response
78-
JsonObject jsonObject = new JsonObject();
79+
jsonObject = new JsonObject();
7980
jsonObject.addProperty("foo", "bar");
8081
singleResponse = Mockito.mock(Response.class);
8182
Mockito.when(singleResponse.isParsed()).thenReturn(true);
@@ -261,7 +262,7 @@ public void testGetMethods() throws ResponseException {
261262
TestCase.assertNotNull(hotelOffer.get());
262263
TestCase.assertNotNull(hotelOffer.get(params));
263264

264-
// Test flight offer search v2
265+
// Test flight offers search get
265266
Mockito.when(client.get("/v2/shopping/flight-offers", null))
266267
.thenReturn(multiResponse);
267268
Mockito.when(client.get("/v2/shopping/flight-offers", params))
@@ -276,7 +277,6 @@ public void testGetMethods() throws ResponseException {
276277
.thenReturn(multiResponse);
277278
HotelSentiments hotelSentiments = new HotelSentiments(client);
278279
TestCase.assertNotNull(hotelSentiments.get(params));
279-
280280
}
281281

282282
@Test
@@ -290,5 +290,17 @@ public void testPostMethods() throws ResponseException {
290290
TestCase.assertNotNull(flightOffersPrediction.post());
291291
TestCase.assertNotNull(flightOffersPrediction.post(body));
292292
TestCase.assertEquals(flightOffersPrediction.post().length, 2);
293+
294+
// Test flight offers search post
295+
Mockito.when(client.post("/v2/shopping/flight-offers", (String) null))
296+
.thenReturn(multiResponse);
297+
Mockito.when(client.post("/v2/shopping/flight-offers", body))
298+
.thenReturn(multiResponse);
299+
Mockito.when(client.post("/v2/shopping/flight-offers", jsonObject))
300+
.thenReturn(multiResponse);
301+
FlightOffersSearch flightOfferSearch = new FlightOffersSearch(client);
302+
TestCase.assertNotNull(flightOfferSearch.post());
303+
TestCase.assertNotNull(flightOfferSearch.post(body));
304+
TestCase.assertEquals(flightOfferSearch.post().length, 2);
293305
}
294306
}

src/test/java/com/amadeus/RequestTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.Assert.assertTrue;
66

77
import java.io.IOException;
8+
89
import org.junit.Test;
910

1011
public class RequestTest {
@@ -25,11 +26,13 @@ public class RequestTest {
2526
assertEquals(request.getPort(), 443);
2627
assertEquals(request.isSsl(), true);
2728
assertEquals(request.getScheme(), "https");
28-
assertEquals(request.getHeaders().size(), 3);
29+
assertEquals(request.getHeaders().size(), 4);
30+
assertEquals(request.getHeaders()
31+
.get(Constants.ACCEPT), "application/json, application/vnd.amadeus+json");
2932
assertEquals(request.getHeaders()
30-
.get("Accept"), "application/json, application/vnd.amadeus+json");
31-
assertEquals(request.getHeaders().get("Authorization"), "token");
32-
assertTrue(request.getHeaders().get("User-Agent").matches("amadeus-java/.* java/.*"));
33+
.get(Constants.CONTENT_TYPE), "application/vnd.amadeus+json");
34+
assertEquals(request.getHeaders().get(Constants.AUTHORIZATION), "token");
35+
assertTrue(request.getHeaders().get(Constants.USER_AGENT).matches("amadeus-java/.* java/.*"));
3336
}
3437

3538
@Test public void testInitializerWithoutBearerToken() {

0 commit comments

Comments
 (0)