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

Support for Flight Order #51

Merged
merged 5 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ 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 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 Choice Prediction
// Note that the example calls 2 APIs: Flight Low-fare Search & Flight Choice Prediction
FlightOffer[] flightOffers = amadeus.shopping.flightOffers
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/amadeus/Amadeus.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ public class Amadeus extends HTTPClient {
*/
public Airport airport;

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

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);
}

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

import com.amadeus.booking.FlightOrder;

public class Booking {
private Amadeus client;

/**
* <p>
* A namespaced client for the
* <code>/v1/booking/flightOrder</code> endpoints.
akshitsingla marked this conversation as resolved.
Show resolved Hide resolved
* </p>
*/
public FlightOrder flightOrder;

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

public FlightOrder flightOrder(String flightOrderId) {
akshitsingla marked this conversation as resolved.
Show resolved Hide resolved
return new FlightOrder(client, flightOrderId);
}
}
66 changes: 66 additions & 0 deletions src/main/java/com/amadeus/booking/FlightOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.amadeus.booking;

import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.Response;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.Resource;

/**
* <p>
* A namespaced client for the
* <code>/v1/booking/flight-orders/:flightOrderId</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.booking.flightOrder;</pre>
*/
public class FlightOrder {
private Amadeus client;
private String flightOfferId;

/**
* Constructor.
* @hide
*/
public FlightOrder(Amadeus client, String flightOfferId) {
this.client = client;
this.flightOfferId = flightOfferId;
}

/**
* <p>
* Allows you to manipulate a flight order. The flightOfferId
* used is an example for educational purposes. In test enviromnent
* it's temporary.
* </p>
*
* <pre>
* FlightOrder order = amadeus.booking.flightOrder.(
* "eJzTd9f3NjIJdzUGAAp%2fAiY=").get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe mention that "eJzTd9f3NjIJdzUGAAp%2fAiY=" is an example?

* </pre>
* @param params the parameters to send to the API
* @return an API response object
* @throws ResponseException when an exception occurs
*/

public com.amadeus.resources.FlightOrder get(Params params) throws ResponseException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid using fully-qualified name?

String path = String.format("/v1/booking/flight-orders/%s", flightOfferId);
Response response = client.get(path, params);
return (com.amadeus.resources.FlightOrder) Resource.fromObject(
response, com.amadeus.resources.FlightOrder.class);
}

/**
* Convenience method for calling <code>get</code> without any parameters.
* @see com.amadeus.booking.FlightOrder#get()
akshitsingla marked this conversation as resolved.
Show resolved Hide resolved
*/
public com.amadeus.resources.FlightOrder get() throws ResponseException {
return get(null);
}
}
85 changes: 85 additions & 0 deletions src/main/java/com/amadeus/resources/FlightOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.amadeus.resources;

import java.util.Date;
import lombok.Getter;
import lombok.ToString;

/**
* An Airline object as returned by the Airline Code LookUp API.
* @see com.amadeus.booking.flightOrder#get()
*/
@ToString
public class FlightOrder extends Resource {
protected FlightOrder() {}

private @Getter String type;
private @Getter String id;
private @Getter String queuingOfficeId;
private @Getter AssociatedRecord[] associatedRecords;
private @Getter Traveler[] travelers;
private @Getter FlightOfferSearch[] flightOffers;

@ToString
public class AssociatedRecord {
protected AssociatedRecord() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason to override the constructor?

}

private @Getter String reference;
private @Getter String creationDateTime;
private @Getter String originSystemCode;
private @Getter String flightOfferId;
}

@ToString
public class Traveler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there no existing class for "Traveler" entity?

protected Traveler() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same - Is there a specific reason to override the constructor?

}

private @Getter String id;
private @Getter Date dateOfBirth;
private @Getter Name name;
private @Getter Contact contact;
private @Getter Document[] documents;
}

@ToString
public class Name {
protected Name() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same - Is there a specific reason to override the constructor?

}

private @Getter String firstName;
private @Getter String lastName;
}

@ToString
public class Contact {
protected Contact() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same - Is there a specific reason to override the constructor?

}

private @Getter Phone[] phones;
}

@ToString
public class Document {
protected Document() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same - Is there a specific reason to override the constructor?

}

private @Getter String documentType;
private @Getter String number;
private @Getter Date expiryDate;
private @Getter String issuanceCountry;
private @Getter String nationality;
private @Getter boolean holder;
}

@ToString
public class Phone {

protected Phone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same - Is there a specific reason to override the constructor?

}

private @Getter String countryCallingCode;
private @Getter String number;
}

}
11 changes: 11 additions & 0 deletions src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.amadeus;

import com.amadeus.airport.predictions.AirportOnTime;
import com.amadeus.booking.FlightOrder;
import com.amadeus.ereputation.HotelSentiments;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.referenceData.Airlines;
Expand Down Expand Up @@ -64,6 +65,7 @@ public void testAllNamespacesExist() {
TestCase.assertNotNull(client.ereputation.hotelSentiments);
TestCase.assertNotNull(client.shopping.hotelOffer("XXX"));
TestCase.assertNotNull(client.airport.predictions.onTime);
TestCase.assertNotNull(client.booking.flightOrder("XXX"));
}

@Before
Expand Down Expand Up @@ -300,6 +302,15 @@ public void testGetMethods() throws ResponseException {
FlightDelay flightDelay = new FlightDelay(client);
TestCase.assertNotNull(flightDelay.get());
TestCase.assertNotNull(flightDelay.get(params));

// Test fetching a specific offer
Mockito.when(client.get("/v1/booking/flight-orders/XXX", null))
.thenReturn(singleResponse);
Mockito.when(client.get("/v1/booking/flight-orders/XXX", params))
.thenReturn(singleResponse);
FlightOrder flightOrder = new FlightOrder(client, "XXX");
TestCase.assertNotNull(flightOrder.get());
TestCase.assertNotNull(flightOrder.get(params));
}

@Test
Expand Down