Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flight offers price update #38

Merged
merged 28 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8174e37
introduce flight pricing api
spirosbatzio Oct 23, 2019
eaac4cb
populate README for pricing request
spirosbatzio Oct 23, 2019
c6bbf7d
Adding other methods for Price API. Fixing the POST version with quer…
anthonyroux Nov 5, 2019
99ff6c7
update dates on readme
tsolakoua Jan 8, 2020
44e9eee
update low-fare example date
tsolakoua Jan 14, 2020
d295958
Merge pull request #39 from amadeus4dev/update-docs
tsolakoua Jan 14, 2020
b5a74c3
Fixing wrong links on README
anthonyroux Feb 5, 2020
a075523
Support for Flight Delay Prediction (#48)
tsolakoua Feb 20, 2020
3d3ae83
Add support for Airport on Time (#50)
tsolakoua Feb 20, 2020
6e80a1f
initial commit
tsolakoua Feb 21, 2020
f59b1fa
add FlightOrder method and fix model
tsolakoua Feb 21, 2020
a2fb023
add tests
tsolakoua Feb 21, 2020
58fa2d0
update docs
tsolakoua Feb 21, 2020
b4ec057
remove most search destinations support
tsolakoua Feb 24, 2020
f09aab4
Merge pull request #52 from amadeus4dev/remove-most-search-destinations
tsolakoua Feb 24, 2020
3620493
support docs and tests
tsolakoua Feb 25, 2020
9fa4c25
fix import order
tsolakoua Feb 25, 2020
7fd04d2
fix typo
tsolakoua Feb 25, 2020
1419491
update class names in docs
tsolakoua Feb 28, 2020
ee7d849
Merge pull request #51 from amadeus4dev/flight-order
tsolakoua Mar 3, 2020
2276e56
Merge branch 'master' into seatmaps
tsolakoua Mar 3, 2020
cdc8fc9
Merge pull request #53 from amadeus4dev/seatmaps
tsolakoua Mar 5, 2020
8ed52c6
Flight Create Orders (#54)
tsolakoua Mar 12, 2020
9e6cf0e
Add support for ai-generated photos (#55)
tsolakoua Mar 13, 2020
e241504
Fix typo
anthonyroux Mar 13, 2020
cad0689
DRAFT: Adding support for Trip Purpose Prediction API (#36)
anthonyroux Mar 18, 2020
24ed7f8
Merge branch 'master' into flight_offers_price_update
tsolakoua Mar 19, 2020
215f345
fix typo and add example
tsolakoua Mar 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.g
// body can be a String version of your JSON or a JsonObject
FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.post(body);

// Flight Offer price
FlightPrice[] flightPricing = amadeus.shopping.flightOffersSearch.pricing.post(
body,
Params.with("include", "other-services")
.and("forceClass", "false"))

// Flight Choice Prediction
// Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction
FlightOffer[] flightOffers = amadeus.shopping.flightOffers
Expand Down
67 changes: 66 additions & 1 deletion src/main/java/com/amadeus/HTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,54 @@ public Response post(String path, JsonObject body) throws ResponseException {
return request(Constants.POST, path, null, body.toString());
}

/**
* <p>
* A helper module for making generic POST requests calls. It is used by
* every namespaced API POST method.
* </p>
*
* <p>
* It can be used to make any generic API call that is automatically
* authenticated using your API credentials:
* </p>
*
* <pre>
* amadeus.post("/v1/foo/bar", Params.with("airline", "1X"), { "foo" : "bar" })
* </pre>
*
* @param path The full path for the API call
* @param params The optional POST params to pass to the API
* @param body The POST JsonObject body to pass to the API
* @return a Response object containing the status code, body, and parsed data.
*/
public Response post(String path, Params params, JsonObject body) throws ResponseException {
return request(Constants.POST, path, params, body.toString());
}

/**
* <p>
* A helper module for making generic POST requests calls. It is used by
* every namespaced API POST method.
* </p>
*
* <p>
* It can be used to make any generic API call that is automatically
* authenticated using your API credentials:
* </p>
*
* <pre>
* amadeus.post("/v1/foo/bar", Params.with("airline", "1X"), { "foo" : "bar" })
* </pre>
*
* @param path The full path for the API call
* @param params The optional POST params to pass to the API
* @param body The POST String object body to pass to the API
* @return a Response object containing the status code, body, and parsed data.
*/
public Response post(String path, Params params, String body) throws ResponseException {
return request(Constants.POST, path, params, body.toString());
}

/**
* A generic method for making any authenticated or unauthenticated request,
* passing in the bearer token explicitly. Used primarily by the
Expand Down Expand Up @@ -292,15 +340,32 @@ private Request fetch(Request request) throws NetworkException {
// Writes the parameters to the request.
private void write(Request request) throws IOException {

// POST with access token + body + URL parameters
if (request.getVerb() == Constants.POST && request.getParams() != null
&& request.getBearerToken() != null) {
OutputStream os = request.getConnection().getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
// writer.write(request.getParams().toQueryString());
if (request.getBody() != null) {
writer.write(request.getBody());
}
writer.flush();
writer.close();
os.close();
}

if (request.getVerb() == Constants.POST && request.getParams() != null) {
// POST with access without token (authentication call)
if (request.getVerb() == Constants.POST && request.getParams() != null
&& request.getBearerToken() == null) {
OutputStream os = request.getConnection().getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(request.getParams().toQueryString());
writer.flush();
writer.close();
os.close();
}

// POST with access token + body
if (request.getVerb() == Constants.POST && request.getParams() == null) {
OutputStream os = request.getConnection().getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amadeus/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private String buildUserAgent() {

// Gets the serialized params, only if this is a Get call
private String getQueryParams() {
if (verb == Constants.GET && params != null) {
if (params != null) {
return params.toQueryString();
} else {
return "";
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/amadeus/resources/FlightPayment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.amadeus.resources;

import lombok.Getter;
import lombok.ToString;

/**
* An Airline object as returned by the Airline Code LookUp API.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comment

* @see amadeus.shopping.flightOffersSearch.pricing#post()
*/
@ToString
public class FlightPayment extends Resource {
protected FlightPayment() {}

private @Getter String brand;
private @Getter Integer binNumber;
private @Getter String[] flightOfferIds;
}
43 changes: 43 additions & 0 deletions src/main/java/com/amadeus/resources/FlightPrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.amadeus.resources;

import lombok.Getter;
import lombok.ToString;

@ToString
public class FlightPrice extends Resource {
protected FlightPrice() {}

private @Getter String type;
private @Getter FlightOfferSearch[] flightOffers;
private @Getter BookingRequirements bookingRequirements;

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

private @Getter Boolean invoiceAddressRequired;
private @Getter Boolean mailingAddressRequired;
private @Getter Boolean emailAddressRequired;
private @Getter Boolean phoneCountryCodeRequired;
private @Getter Boolean mobilePhoneNumberRequired;
private @Getter Boolean phoneNumberRequired;
private @Getter Boolean postalCodeRequired;
private @Getter PassengerConditions[] travelerRequirements;
}

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

private @Getter String travelerId;
private @Getter Boolean genderRequired;
private @Getter Boolean documentRequired;
private @Getter Boolean documentIssuanceCityRequired;
private @Getter Boolean dateOfBirthRequired;
private @Getter Boolean redressRequiredIfAny;
private @Getter Boolean airFranceDiscountRequired;
private @Getter Boolean spanishResidentDiscountRequired;
private @Getter Boolean residenceRequired;
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/amadeus/shopping/FlightOffersSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.FlightOfferSearch;
import com.amadeus.resources.Resource;
import com.amadeus.shopping.flightOffers.Pricing;
import com.google.gson.JsonObject;

/**
Expand All @@ -24,6 +25,7 @@
*/
public class FlightOffersSearch {
private Amadeus client;
public Pricing pricing;

/**
* Constructor.
Expand All @@ -32,6 +34,7 @@ public class FlightOffersSearch {
*/
public FlightOffersSearch(Amadeus client) {
this.client = client;
this.pricing = new Pricing(client);
}

/**
Expand Down
Loading