Skip to content

Commit 22eb597

Browse files
committed
add on demand flight status support
1 parent 8a77ebb commit 22eb597

File tree

6 files changed

+219
-0
lines changed

6 files changed

+219
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ Prediction tripPurpose = amadeus.travel.predictions.tripPurpose.get(Params
356356
Location destinations = amadeus.referenceData.recommendedLocations.get(Params
357357
.with("cityCodes", "PAR")
358358
.and("travelerCountryCode", "FR"));
359+
360+
// On Demand Flight Status
361+
DatedFlight[] flightStatus = amadeus.schedule.flights.get(Params
362+
.with("carrierCode", "AZ")
363+
.and("flightNumber", "319")
364+
.and("scheduledDepartureDate", "2021-03-13"));
359365
```
360366

361367
## Development & Contributing

src/main/java/com/amadeus/Amadeus.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ public class Amadeus extends HTTPClient {
8383
*/
8484
public Safety safety;
8585

86+
/**
87+
* <p>
88+
* A namespaced client for the <code>/v2/schedule</code> endpoints.
89+
* </p>
90+
*/
91+
public Schedule schedule;
92+
8693
protected Amadeus(Configuration configuration) {
8794
super(configuration);
8895
this.referenceData = new ReferenceData(this);
@@ -93,6 +100,7 @@ protected Amadeus(Configuration configuration) {
93100
this.booking = new Booking(this);
94101
this.media = new Media(this);
95102
this.safety = new Safety(this);
103+
this.schedule = new Schedule(this);
96104

97105
}
98106

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.amadeus;
2+
3+
import com.amadeus.schedule.Flights;
4+
5+
/**
6+
* <p>
7+
* A namespaced client for the
8+
* <code>/v2/schedule</code> endpoints.
9+
* </p>
10+
*
11+
* <p>
12+
* Access via the Amadeus client object.
13+
* </p>
14+
*
15+
* <pre>
16+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
17+
* amadeus.schedule;</pre>
18+
*
19+
* @hide
20+
*/
21+
public class Schedule {
22+
/**
23+
* <p>
24+
* A namespaced client for the
25+
* <code>/v2/schedule/flights</code> endpoints.
26+
* </p>
27+
*/
28+
public Flights flights;
29+
30+
/**
31+
* Constructor.
32+
* @hide
33+
*/
34+
public Schedule(Amadeus client) {
35+
this.flights = new Flights(client);
36+
}
37+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* An DatedFlight object as returned by the On Flight Status Demand API.
8+
* @see com.amadeus.schedule.Flights#get()
9+
*/
10+
@ToString
11+
public class DatedFlight extends Resource {
12+
protected DatedFlight() {}
13+
14+
private @Getter String type;
15+
private @Getter String scheduledDepartureDate;
16+
private @Getter FlightDesignator flightDesignator;
17+
private @Getter FlightPoints[] flightPoints;
18+
private @Getter Segments[] segments;
19+
private @Getter Legs[] legs;
20+
21+
@ToString
22+
public class FlightDesignator {
23+
protected FlightDesignator() {
24+
}
25+
26+
private @Getter String carrierCode;
27+
private @Getter int flightNumber;
28+
}
29+
30+
@ToString
31+
public class FlightPoints {
32+
protected FlightPoints() {
33+
}
34+
35+
private @Getter String iataCode;
36+
private @Getter Departure departure;
37+
private @Getter Arrival arrival;
38+
}
39+
40+
@ToString
41+
public class Departure {
42+
protected Departure() {
43+
}
44+
45+
private @Getter Timings[] timings;
46+
}
47+
48+
@ToString
49+
public class Arrival {
50+
protected Arrival() {
51+
}
52+
53+
private @Getter Timings[] timings;
54+
}
55+
56+
@ToString
57+
public class Timings {
58+
protected Timings() {
59+
}
60+
61+
private @Getter String qualifier;
62+
private @Getter String value;
63+
}
64+
65+
@ToString
66+
public class Segments {
67+
protected Segments() {
68+
}
69+
70+
private @Getter String boardPointIataCode;
71+
private @Getter String offPointIataCode;
72+
private @Getter String scheduledSegmentDuration;
73+
}
74+
75+
@ToString
76+
public class Legs {
77+
protected Legs() {
78+
}
79+
80+
private @Getter String boardPointIataCode;
81+
private @Getter String offPointIataCode;
82+
private @Getter AircraftEquipment aircraftEquipment;
83+
private @Getter String scheduledLegDuration;
84+
}
85+
86+
@ToString
87+
public class AircraftEquipment {
88+
protected AircraftEquipment() {
89+
}
90+
91+
private @Getter String aircraftType;
92+
}
93+
94+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.amadeus.schedule;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.DatedFlight;
8+
import com.amadeus.resources.Resource;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v2/schedule/flights</code> endpoints.
14+
* </p>
15+
*
16+
* <p>
17+
* Access via the Amadeus client object.
18+
* </p>
19+
*
20+
* <pre>
21+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
22+
* amadeus.schedule.flights;</pre>
23+
*/
24+
public class Flights {
25+
private Amadeus client;
26+
27+
/**
28+
* Constructor.
29+
* @hide
30+
*/
31+
public Flights(Amadeus client) {
32+
this.client = client;
33+
}
34+
35+
/**
36+
* <p>
37+
* Retrieves status of a given flight.
38+
* </p>
39+
*
40+
* <pre>
41+
* amadeus.schedule.flights.get(Params
42+
* .with("carrierCode", "AZ")
43+
* .and("flightNumber", "319")
44+
* .and("scheduledDepartureDate", "2021-03-13"));</pre>
45+
*
46+
* @param params the parameters to send to the API
47+
* @return an API response object
48+
* @throws ResponseException when an exception occurs
49+
*/
50+
public DatedFlight[] get(Params params) throws ResponseException {
51+
Response response = client.get("/v2/schedule/flights", params);
52+
return (DatedFlight[]) Resource.fromArray(response, DatedFlight[].class);
53+
}
54+
55+
/**
56+
* Convenience method for calling <code>get</code> without any parameters.
57+
* @see DatedFlight#get()
58+
*/
59+
public DatedFlight[] get() throws ResponseException {
60+
return get(null);
61+
}
62+
}

src/test/java/com/amadeus/NamespaceTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.amadeus.referenceData.locations.PointsOfInterest;
1616
import com.amadeus.referenceData.urls.CheckinLinks;
1717
import com.amadeus.safety.SafetyRatedLocations;
18+
import com.amadeus.schedule.Flights;
1819
import com.amadeus.shopping.FlightDates;
1920
import com.amadeus.shopping.FlightDestinations;
2021
import com.amadeus.shopping.FlightOffers;
@@ -79,6 +80,7 @@ public void testAllNamespacesExist() {
7980
TestCase.assertNotNull(client.safety.safetyRatedLocations);
8081
TestCase.assertNotNull(client.safety.safetyRatedLocations.bySquare);
8182
TestCase.assertNotNull(client.safety.safetyRatedLocation("XXX"));
83+
TestCase.assertNotNull(client.schedule.flights);
8284
}
8385

8486
@Before
@@ -369,6 +371,16 @@ public void testGetMethods() throws ResponseException {
369371
GeneratedPhotos photo = new GeneratedPhotos(client);
370372
TestCase.assertNotNull(photo.get());
371373
TestCase.assertNotNull(photo.get(params));
374+
375+
// Testing on demand flight status
376+
Mockito.when(client.get("/v2/schedule/flights", null))
377+
.thenReturn(multiResponse);
378+
Mockito.when(client.get("/v2/schedule/flights", params))
379+
.thenReturn(multiResponse);
380+
Flights flightStatus = new Flights(client);
381+
TestCase.assertNotNull(flightStatus.get());
382+
TestCase.assertNotNull(flightStatus.get(params));
383+
TestCase.assertEquals(flightStatus.get().length, 2);
372384
}
373385

374386
@Test

0 commit comments

Comments
 (0)