Skip to content

Commit

Permalink
Merge branch 'flight_offers_price_update' into flight_offers_price
Browse files Browse the repository at this point in the history
  • Loading branch information
tsolakoua committed Mar 19, 2020
2 parents 6b547cd + 215f345 commit abbf480
Show file tree
Hide file tree
Showing 41 changed files with 1,705 additions and 335 deletions.
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/
79 changes: 57 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,15 +228,19 @@ 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,
Expand All @@ -247,7 +250,7 @@ FlightPrice[] flightPricing = amadeus.shopping.flightOffersSearch.pricing.post(
// 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 @@ -279,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 @@ -331,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);
}
}
19 changes: 18 additions & 1 deletion src/main/java/com/amadeus/HTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,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
10 changes: 10 additions & 0 deletions src/main/java/com/amadeus/Shopping.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.amadeus.shopping.HotelOffer;
import com.amadeus.shopping.HotelOffers;
import com.amadeus.shopping.HotelOffersByHotel;
import com.amadeus.shopping.SeatMaps;

/**
* <p>
Expand Down Expand Up @@ -75,6 +76,14 @@ public class Shopping {
*/
public HotelOffersByHotel hotelOffersByHotel;

/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/seatmaps</code> endpoints.
* </p>
*/
public SeatMaps seatMaps;

/**
* Constructor.
* @hide
Expand All @@ -87,6 +96,7 @@ public Shopping(Amadeus client) {
this.hotelOffers = new HotelOffers(client);
this.hotelOffersByHotel = new HotelOffersByHotel(client);
this.flightOffersSearch = new FlightOffersSearch(client);
this.seatMaps = new SeatMaps(client);
}

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

import com.amadeus.travel.Predictions;
import com.amadeus.travel.analytics.Analytics;

/**
Expand All @@ -26,12 +27,20 @@ public class Travel {
* </p>
*/
public Analytics analytics;
/**
* <p>
* A namespaced client for the
* <code>/v1/travel/predictions</code> endpoints.
* </p>
*/
public Predictions predictions;

/**
* Constructor.
* @hide
*/
public Travel(Amadeus client) {
this.analytics = new Analytics(client);
this.predictions = new Predictions(client);
}
}
Loading

0 comments on commit abbf480

Please sign in to comment.