Skip to content

Commit 0eb9ead

Browse files
anthonyrouxspirosbatziotsolakoua
authored
Flight offers price update (#58)
* introduce flight pricing api * populate README for pricing request * Adding other methods for Price API. Fixing the POST version with query params on going * fix typo and add example * fix typo Co-authored-by: Sealsoft <[email protected]> Co-authored-by: Anna Tsolakou <[email protected]>
1 parent 2475bbb commit 0eb9ead

File tree

11 files changed

+431
-21
lines changed

11 files changed

+431
-21
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.p
241241
// The flightOrderID comes from the Flight Create Orders (in test environment it's temporary)
242242
FlightOrder order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").get();
243243

244+
// Flight Offer price
245+
FlightPrice[] flightPricing = amadeus.shopping.flightOffersSearch.pricing.post(
246+
body,
247+
Params.with("include", "other-services")
248+
.and("forceClass", "false"));
249+
244250
// Flight Choice Prediction
245251
// Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction
246252
FlightOffer[] flightOffers = amadeus.shopping.flightOffers

src/main/java/com/amadeus/HTTPClient.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,54 @@ public Response post(String path, JsonObject body) throws ResponseException {
154154
return request(Constants.POST, path, null, body.toString());
155155
}
156156

157+
/**
158+
* <p>
159+
* A helper module for making generic POST requests calls. It is used by
160+
* every namespaced API POST method.
161+
* </p>
162+
*
163+
* <p>
164+
* It can be used to make any generic API call that is automatically
165+
* authenticated using your API credentials:
166+
* </p>
167+
*
168+
* <pre>
169+
* amadeus.post("/v1/foo/bar", Params.with("airline", "1X"), { "foo" : "bar" })
170+
* </pre>
171+
*
172+
* @param path The full path for the API call
173+
* @param params The optional POST params to pass to the API
174+
* @param body The POST JsonObject body to pass to the API
175+
* @return a Response object containing the status code, body, and parsed data.
176+
*/
177+
public Response post(String path, Params params, JsonObject body) throws ResponseException {
178+
return request(Constants.POST, path, params, body.toString());
179+
}
180+
181+
/**
182+
* <p>
183+
* A helper module for making generic POST requests calls. It is used by
184+
* every namespaced API POST method.
185+
* </p>
186+
*
187+
* <p>
188+
* It can be used to make any generic API call that is automatically
189+
* authenticated using your API credentials:
190+
* </p>
191+
*
192+
* <pre>
193+
* amadeus.post("/v1/foo/bar", Params.with("airline", "1X"), { "foo" : "bar" })
194+
* </pre>
195+
*
196+
* @param path The full path for the API call
197+
* @param params The optional POST params to pass to the API
198+
* @param body The POST String object body to pass to the API
199+
* @return a Response object containing the status code, body, and parsed data.
200+
*/
201+
public Response post(String path, Params params, String body) throws ResponseException {
202+
return request(Constants.POST, path, params, body.toString());
203+
}
204+
157205
/**
158206
* A generic method for making any authenticated or unauthenticated request,
159207
* passing in the bearer token explicitly. Used primarily by the
@@ -292,15 +340,32 @@ private Request fetch(Request request) throws NetworkException {
292340
// Writes the parameters to the request.
293341
private void write(Request request) throws IOException {
294342

343+
// POST with access token + body + URL parameters
344+
if (request.getVerb() == Constants.POST && request.getParams() != null
345+
&& request.getBearerToken() != null) {
346+
OutputStream os = request.getConnection().getOutputStream();
347+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
348+
// writer.write(request.getParams().toQueryString());
349+
if (request.getBody() != null) {
350+
writer.write(request.getBody());
351+
}
352+
writer.flush();
353+
writer.close();
354+
os.close();
355+
}
295356

296-
if (request.getVerb() == Constants.POST && request.getParams() != null) {
357+
// POST with access without token (authentication call)
358+
if (request.getVerb() == Constants.POST && request.getParams() != null
359+
&& request.getBearerToken() == null) {
297360
OutputStream os = request.getConnection().getOutputStream();
298361
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
299362
writer.write(request.getParams().toQueryString());
300363
writer.flush();
301364
writer.close();
302365
os.close();
303366
}
367+
368+
// POST with access token + body
304369
if (request.getVerb() == Constants.POST && request.getParams() == null) {
305370
OutputStream os = request.getConnection().getOutputStream();
306371
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private String buildUserAgent() {
157157

158158
// Gets the serialized params, only if this is a Get call
159159
private String getQueryParams() {
160-
if (verb == Constants.GET && params != null) {
160+
if (params != null) {
161161
return params.toQueryString();
162162
} else {
163163
return "";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* An FlightPayment object as returned by the Flight Offers Price API.
8+
* @see amadeus.shopping.flightOffersSearch.pricing#post()
9+
*/
10+
@ToString
11+
public class FlightPayment extends Resource {
12+
protected FlightPayment() {}
13+
14+
private @Getter String brand;
15+
private @Getter Integer binNumber;
16+
private @Getter String[] flightOfferIds;
17+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
@ToString
7+
public class FlightPrice extends Resource {
8+
protected FlightPrice() {}
9+
10+
private @Getter String type;
11+
private @Getter FlightOfferSearch[] flightOffers;
12+
private @Getter BookingRequirements bookingRequirements;
13+
14+
@ToString
15+
public class BookingRequirements {
16+
protected BookingRequirements() {}
17+
18+
private @Getter Boolean invoiceAddressRequired;
19+
private @Getter Boolean mailingAddressRequired;
20+
private @Getter Boolean emailAddressRequired;
21+
private @Getter Boolean phoneCountryCodeRequired;
22+
private @Getter Boolean mobilePhoneNumberRequired;
23+
private @Getter Boolean phoneNumberRequired;
24+
private @Getter Boolean postalCodeRequired;
25+
private @Getter PassengerConditions[] travelerRequirements;
26+
}
27+
28+
@ToString
29+
public class PassengerConditions {
30+
protected PassengerConditions(){}
31+
32+
private @Getter String travelerId;
33+
private @Getter Boolean genderRequired;
34+
private @Getter Boolean documentRequired;
35+
private @Getter Boolean documentIssuanceCityRequired;
36+
private @Getter Boolean dateOfBirthRequired;
37+
private @Getter Boolean redressRequiredIfAny;
38+
private @Getter Boolean airFranceDiscountRequired;
39+
private @Getter Boolean spanishResidentDiscountRequired;
40+
private @Getter Boolean residenceRequired;
41+
}
42+
43+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.amadeus.exceptions.ResponseException;
77
import com.amadeus.resources.FlightOfferSearch;
88
import com.amadeus.resources.Resource;
9+
import com.amadeus.shopping.flightOffers.Pricing;
910
import com.google.gson.JsonObject;
1011

1112
/**
@@ -24,6 +25,7 @@
2425
*/
2526
public class FlightOffersSearch {
2627
private Amadeus client;
28+
public Pricing pricing;
2729

2830
/**
2931
* Constructor.
@@ -32,6 +34,7 @@ public class FlightOffersSearch {
3234
*/
3335
public FlightOffersSearch(Amadeus client) {
3436
this.client = client;
37+
this.pricing = new Pricing(client);
3538
}
3639

3740
/**

0 commit comments

Comments
 (0)