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 all 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ build
out
.DS_Store
amadeus-java.iml
Bin/
Bin/
.vscode/
85 changes: 63 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Amadeus Java SDK

[![Build Status](https://travis-ci.org/amadeus4dev/amadeus-java.svg?branch=master)][travis]
[![Contact Support](https://github.com/amadeus4dev/amadeus-ruby/raw/master/.github/images/support.svg?sanitize=true)][support]
[![Contact Support](https://github.com/amadeus4dev/amadeus-java/raw/master/.github/images/support.svg?sanitize=true)][support]

Amadeus provides a set of APIs for the travel industry. Flights, Hotels, Locations and more.

Expand Down Expand Up @@ -116,8 +116,8 @@ in-depth information about every SDK method, its arguments and return types.
* [Get Started](https://amadeus4dev.github.io/amadeus-java/) documentation
* [Initialize the SDK](https://amadeus4dev.github.io/amadeus-java/)
* [Find an Airport](https://amadeus4dev.github.io/amadeus-java/)
* [Find a Flight](https://amadeus4dev.github.io/amadeus-ruby/)
* [Get Flight Inspiration](https://amadeus4dev.github.io/amadeus-ruby/)
* [Find a Flight](https://amadeus4dev.github.io/amadeus-java/)
* [Get Flight Inspiration](https://amadeus4dev.github.io/amadeus-java/)

## Making API calls

Expand All @@ -141,10 +141,9 @@ You can make any arbitrary API call as well directly with the `.get` method.
Keep in mind, this returns a raw `Resource`

```java
Resource resource = amadeus.get('/v2/reference-data/urls/checkin-links',
Params.with("airlineCode", "BA"));
Response response = amadeus.get("/v2/reference-data/urls/checkin-links", Params.with("airlineCode", "BA"));

resource.getResult();
response.getResult();
```

## Response
Expand Down Expand Up @@ -229,19 +228,29 @@ FlightOffer[] flightOffers = amadeus.shopping.flightOffers.get(Params
FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.get(
Params.with("originLocationCode", "SYD")
.and("destinationLocationCode", "BKK")
.and("departureDate", "2020-04-01")
.and("returnDate", "2020-04-05")
.and("departureDate", "2020-11-01")
.and("returnDate", "2020-11-08")
.and("adults", 2)
.and("max", 3));

// Flight Offer Search v2 POST
// body can be a String version of your JSON or a JsonObject
FlightOfferSearch[] flightOffersSearches = amadeus.shopping.flightOffersSearch.post(body);

// Flight Order Management
// The flightOrderID comes from the Flight Create Orders (in test environment it's temporary)
FlightOrder order = amadeus.booking.flightOrder("eJzTd9f3NjIJdzUGAAp%2fAiY=").get();

// 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
.get(Params.with("origin", "MAD").and("destination", "NYC").and("departureDate", "2020-04-01").and("max", "2"));
.get(Params.with("origin", "MAD").and("destination", "NYC").and("departureDate", "2020-08-01").and("max", "2"));

// Using a JSonObject
JsonObject result = flightOffers[0].getResponse().getResult();
Expand Down Expand Up @@ -273,19 +282,6 @@ Location[] locations = amadeus.referenceData.locations.airports.get(Params
.with("latitude", 0.1278)
.and("longitude", 51.5074));

// Flight Most Searched Destinations
// Which were the most searched flight destinations from Madrid in August 2017?
SearchedDestination searchedDestination = amadeus.travel.analytics.airTraffic.searchedByDestination.get(Params
.with("originCityCode", "MAD")
.and("destinationCityCode", "NYC")
.and("searchPeriod", "2017-08")
.and("marketCountryCode", "ES"));
// How many people in Spain searched for a trip from Madrid to New-York in September 2017?
Search[] search = amadeus.travel.analytics.airTraffic.searched.get(Params
.with("originCityCode", "MAD")
.and("searchPeriod", "2017-08")
.and("marketCountryCode", "ES"));

// Flight Most Booked Destinations
AirTraffic[] airTraffics = amadeus.travel.analytics.airTraffic.booked.get(Params
.with("originCityCode", "MAD")
Expand Down Expand Up @@ -325,6 +321,51 @@ PointOfInterest[] pointsOfInterest = amadeus.referenceData.locations.pointsOfInt
.and("west", "2.160873")
.and("south", "41.394582")
.and("east", "2.177181"));

// What's the likelihood flights from this airport will leave on time?
Prediction AirportOnTime = amadeus.airport.predictions.onTime.get(Params
.with("airportCode", "NCE")
.and("date", "2020-09-01"));

// What's the likelihood of a given flight to be delayed?
Prediction[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
.with("originLocationCode", "NCE")
.and("destinationLocationCode", "IST")
.and("departureDate", "2020-08-01")
.and("departureTime", "18:20:00")
.and("arrivalDate", "2020-08-01")
.and("arrivalTime", "22:15:00")
.and("aircraftCode", "321")
.and("carrierCode", "TK")
.and("flightNumber", "1816")
.and("duration", "PT31H10M"));

// Flight Create Orders to book a flight
// Using a JSonObject or String
FlightOrder createdOrder = amadeus.booking.flightOrders.pricing.post(body);

// Using a JsonObject for flight offer and Traveler[] as traveler information
// see example at src/main/java/examples/flight/createorders/FlightCreateOrders.java
FlightOrder createdOrder = amadeus.booking.flightOrders.post(flightOffersSearches, travelerArray);

// What is the the seat map of a given flight?
SeatMap[] seatmap = amadeus.shopping.seatMaps.get(Params
.with("flight-orderId", "eJzTd9f3NjIJdzUGAAp%2fAiY="));

// What is the the seat map of a given flight?
// The body can be a String version of your JSON or a JsonObject
SeatMap[] seatmap = amadeus.shopping.seatMaps.post(body);

// AI-Generated Photos
GeneratedPhoto photo = amadeus.media.files.generatedPhotos.get(Params
.with("category", "BEACH"));

// Trip Purpose Prediction
Prediction tripPurpose = amadeus.travel.predictions.tripPurpose.get(Params
.with("originLocationCode", "NYC")
.and("destinationLocationCode", "MAD")
.and("departureDate", "2020-08-01")
.and("returnDate", "2020-08-12"));
```

## Development & Contributing
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/amadeus/Airport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.amadeus;

import com.amadeus.airport.predictions.Predictions;

/**
* <p>
* A namespaced client for the
* <code>/v1/airport</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.airport</pre>
*
* @hide
*/
public class Airport {
/**
* <p>
* A namespaced client for the
* <code>/v1/airport/predictions</code> endpoints.
* </p>
*/
public Predictions predictions;

/**
* Constructor.
* @hide
*/
public Airport(Amadeus client) {
this.predictions = new Predictions(client);
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/amadeus/Amadeus.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,37 @@ public class Amadeus extends HTTPClient {
*/
public EReputation ereputation;

/**
* <p>
* A namespaced client for the <code>/v1/airport</code> endpoints.
* </p>
*/
public Airport airport;

/**
* <p>
* A namespaced client for the <code>/v1/booking</code> endpoints.
* </p>
*/
public Booking booking;

/**
* <p>
* A namespaced client for the <code>/v2/media</code> endpoints.
* </p>
*/
public Media media;

protected Amadeus(Configuration configuration) {
super(configuration);
this.referenceData = new ReferenceData(this);
this.travel = new Travel(this);
this.shopping = new Shopping(this);
this.ereputation = new EReputation(this);
this.airport = new Airport(this);
this.booking = new Booking(this);
this.media = new Media(this);

}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/amadeus/Booking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.amadeus;

import com.amadeus.booking.FlightOrder;
import com.amadeus.booking.FlightOrders;

public class Booking {
private Amadeus client;

/**
* <p>
* A namespaced client for the
* <code>/v1/booking/flightOrder</code> endpoints.
* </p>
*/
public FlightOrder flightOrder;

/**
* <p>
* A namespaced client for the
* <code>/v1/booking/flightOrders</code> endpoints.
* </p>
*/
public FlightOrders flightOrders;

public Booking(Amadeus client) {
this.client = client;
this.flightOrders = new FlightOrders(client);
}

public FlightOrder flightOrder(String flightOrderId) {
return new FlightOrder(client, flightOrderId);
}
}
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
37 changes: 37 additions & 0 deletions src/main/java/com/amadeus/Media.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.amadeus;

import com.amadeus.media.Files;

/**
* <p>
* A namespaced client for the
* <code>/v2/media</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.media;</pre>
*
* @hide
*/
public class Media {
/**
* <p>
* A namespaced client for the
* <code>/v2/media/files</code> endpoints.
* </p>
*/
public Files files;

/**
* Constructor.
* @hide
*/
public Media(Amadeus client) {
this.files = new Files(client);
}
}
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