Skip to content

Commit

Permalink
Merge pull request #53 from amadeus4dev/seatmaps
Browse files Browse the repository at this point in the history
Add support for SeatMap
  • Loading branch information
tsolakoua committed Mar 5, 2020
2 parents ee7d849 + 2276e56 commit cdc8fc9
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ OnTime 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?
Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
.with("originLocationCode", "NCE")
.and("destinationLocationCode", "IST")
Expand All @@ -333,6 +334,14 @@ Delay[] flightDelay = amadeus.travel.predictions.flightDelay.get(Params
.and("carrierCode", "TK")
.and("flightNumber", "1816")
.and("duration", "PT31H10M"));

// 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);
```

## Development & Contributing
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
74 changes: 74 additions & 0 deletions src/main/java/com/amadeus/resources/SeatMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.amadeus.resources;

import lombok.Getter;
import lombok.ToString;

/**
* An SeatMap object as returned by the SeatMap API.
* @see com.amadeus.booking.SeatMaps#get()
* @see com.amadeus.booking.SeatMaps#post() */
@ToString
public class SeatMap extends Resource {
protected SeatMap() {}

private @Getter String type;
private @Getter String flightOfferid;
private @Getter String segmentid;
private @Getter String carrierCode;
private @Getter String number;
private @Getter Aircraft aircraft;
private @Getter Departure departure;
private @Getter Deck[] decks;

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

private @Getter String code;
}

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

private @Getter String iataCode;
private @Getter String at;
}

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

private @Getter String iataCode;
}

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

private @Getter String deckType;
private @Getter DeckConfiguration deckConfiguration;

}

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

private @Getter int width;
private @Getter int length;
private @Getter int startseatRow;
private @Getter int endSeatRow;
private @Getter int startWingsRow;
private @Getter int endWingsRow;
private @Getter int startWingsX;
private @Getter int endWingsX;

}

}
109 changes: 109 additions & 0 deletions src/main/java/com/amadeus/shopping/SeatMaps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.amadeus.shopping;

import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.Response;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.Resource;
import com.amadeus.resources.SeatMap;
import com.google.gson.JsonObject;

/**
* <p>
* A namespaced client for the
* <code>/v1/shopping/seatmaps</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder(API_KEY, API_SECRET).build();
* amadeus.shopping.seatMaps;</pre>
*/
public class SeatMaps {
private Amadeus client;

/**
* Constructor.
*
* @hide
*/
public SeatMaps(Amadeus client) {
this.client = client;
}

/**
* <p>
* The SeatMap API allows you to retrieve the seat map of one or several
* flights based on the flight-orderId returned by the Flight Create Orders API.
* </p>
*
* <pre>
* amadeus.shopping.seatMaps.get(params);</pre>
*
* @param params the parameters to send to the API
* @return an API resource
* @throws ResponseException when an exception occurs
*/
public SeatMap[] get(Params params) throws ResponseException {
Response response = client.get("/v1/shopping/seatmaps", params);
return (SeatMap[]) Resource.fromArray(response, SeatMap[].class);
}

/**
* Convenience method for calling <code>get</code> without any parameters.
* @see SeatMaps#get()
*/
public SeatMap[] get() throws ResponseException {
return get(null);
}

/**
* <p>
* The SeatMap API allows you to retrieve the seat map of one or several
* Take the body of a flight offer search or flight offer price and pass
* it in to this method to get a seatmap.
* </p>
*
* <pre>
* amadeus.shopping.seatMaps.post(body);</pre>
*
* @param body the parameters to send to the API as a JSonObject
* @return an API resource
* @throws ResponseException when an exception occurs
*/
public SeatMap[] post(JsonObject body) throws ResponseException {
Response response = client.post("/v1/shopping/seatmaps", body);
return (SeatMap[]) Resource.fromArray(response, SeatMap[].class);
}

/**
* <p>
* The SeatMap API allows you to retrieve the seat map of one or several
* Take the body of a flight offer search or flight offer price and pass
* it in to this method to get a seatmap.
* </p>
*
* <pre>
* amadeus.shopping.seatMaps.post(body);</pre>
*
* @param body the parameters to send to the API as a String
* @return an API resource
* @throws ResponseException when an exception occurs
*/
public SeatMap[] post(String body) throws ResponseException {
Response response = client.post("/v1/shopping/seatmaps", body);
return (SeatMap[]) Resource.fromArray(response, SeatMap[].class);
}

/**
* Convenience method for calling <code>post</code> without any parameters.
*
* @see SeatMaps#post()
*/
public SeatMap[] post() throws ResponseException {
return post((String) null);
}
}
22 changes: 21 additions & 1 deletion src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import com.amadeus.referenceData.locations.Airports;
import com.amadeus.referenceData.locations.PointsOfInterest;
import com.amadeus.referenceData.urls.CheckinLinks;
import com.amadeus.resources.Delay;
import com.amadeus.shopping.FlightDates;
import com.amadeus.shopping.FlightDestinations;
import com.amadeus.shopping.FlightOffers;
import com.amadeus.shopping.FlightOffersSearch;
import com.amadeus.shopping.HotelOffer;
import com.amadeus.shopping.HotelOffers;
import com.amadeus.shopping.HotelOffersByHotel;
import com.amadeus.shopping.SeatMaps;
import com.amadeus.shopping.flightOffers.Prediction;
import com.amadeus.travel.analytics.airTraffic.Booked;
import com.amadeus.travel.analytics.airTraffic.BusiestPeriod;
Expand Down Expand Up @@ -58,6 +58,7 @@ public void testAllNamespacesExist() {
TestCase.assertNotNull(client.shopping.flightOffers.prediction);
TestCase.assertNotNull(client.shopping.hotelOffers);
TestCase.assertNotNull(client.shopping.hotelOffersByHotel);
TestCase.assertNotNull(client.shopping.seatMaps);
TestCase.assertNotNull(client.ereputation.hotelSentiments);
TestCase.assertNotNull(client.shopping.hotelOffer("XXX"));
TestCase.assertNotNull(client.airport.predictions.onTime);
Expand Down Expand Up @@ -280,6 +281,14 @@ public void testGetMethods() throws ResponseException {
TestCase.assertNotNull(flightDelay.get());
TestCase.assertNotNull(flightDelay.get(params));

// Test SeatMaps get
Mockito.when(client.get("/v1/shopping/seatmaps", null))
.thenReturn(multiResponse);
Mockito.when(client.get("/v1/shopping/seatmaps", params))
.thenReturn(multiResponse);
SeatMaps seatmap = new SeatMaps(client);
TestCase.assertNotNull(seatmap.get(params));

// Test fetching a specific offer
Mockito.when(client.get("/v1/booking/flight-orders/XXX", null))
.thenReturn(singleResponse);
Expand Down Expand Up @@ -313,5 +322,16 @@ public void testPostMethods() throws ResponseException {
TestCase.assertNotNull(flightOfferSearch.post());
TestCase.assertNotNull(flightOfferSearch.post(body));
TestCase.assertEquals(flightOfferSearch.post().length, 2);

// Test SeatMaps post
Mockito.when(client.post("/v1/shopping/seatmaps", (String) null))
.thenReturn(multiResponse);
Mockito.when(client.post("/v1/shopping/seatmaps", body))
.thenReturn(multiResponse);
Mockito.when(client.post("/v1/shopping/seatmaps", jsonObject))
.thenReturn(multiResponse);
SeatMaps seatmap = new SeatMaps(client);
TestCase.assertNotNull(seatmap.post());
TestCase.assertNotNull(seatmap.post(body));
}
}

0 comments on commit cdc8fc9

Please sign in to comment.