Skip to content

Commit dccb3a9

Browse files
authored
Merge pull request #90 from amadeus4dev/on-demand
Add on demand flight status support
2 parents 8a77ebb + 4faba50 commit dccb3a9

File tree

6 files changed

+259
-0
lines changed

6 files changed

+259
-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: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 FlightPoint[] flightPoints;
18+
private @Getter Segment[] segments;
19+
private @Getter Leg[] legs;
20+
21+
@ToString
22+
public class FlightDesignator {
23+
protected FlightDesignator() {
24+
}
25+
26+
private @Getter String carrierCode;
27+
private @Getter int flightNumber;
28+
private @Getter String operationalSuffix;
29+
30+
}
31+
32+
@ToString
33+
public class FlightPoint {
34+
protected FlightPoint() {
35+
}
36+
37+
private @Getter String iataCode;
38+
private @Getter Departure departure;
39+
private @Getter Arrival arrival;
40+
}
41+
42+
@ToString
43+
public class Departure {
44+
protected Departure() {
45+
}
46+
47+
private @Getter Timing[] timings;
48+
private @Getter Terminal[] terminal;
49+
private @Getter Gate[] gate;
50+
}
51+
52+
@ToString
53+
public class Arrival {
54+
protected Arrival() {
55+
}
56+
57+
private @Getter Timing[] timings;
58+
private @Getter Terminal[] terminal;
59+
private @Getter Gate[] gate;
60+
}
61+
62+
@ToString
63+
public class Timing {
64+
protected Timing() {
65+
}
66+
67+
private @Getter String qualifier;
68+
private @Getter String value;
69+
private @Getter Delay delays;
70+
}
71+
72+
@ToString
73+
public class Delay {
74+
protected Delay() {
75+
}
76+
77+
private @Getter String duration;
78+
}
79+
80+
@ToString
81+
public class Gate {
82+
protected Gate() {
83+
}
84+
85+
private @Getter String mainGate;
86+
}
87+
88+
@ToString
89+
public class Terminal {
90+
protected Terminal() {
91+
}
92+
93+
private @Getter String code;
94+
}
95+
96+
@ToString
97+
public class Segment {
98+
protected Segment() {
99+
}
100+
101+
private @Getter String boardPointIataCode;
102+
private @Getter String offPointIataCode;
103+
private @Getter String scheduledSegmentDuration;
104+
private @Getter Partnership partnership;
105+
}
106+
107+
@ToString
108+
public class Partnership {
109+
protected Partnership() {
110+
}
111+
112+
private @Getter FlightDesignator operatingFlight;
113+
}
114+
115+
@ToString
116+
public class Leg {
117+
protected Leg() {
118+
}
119+
120+
private @Getter String boardPointIataCode;
121+
private @Getter String offPointIataCode;
122+
private @Getter AircraftEquipment aircraftEquipment;
123+
private @Getter String scheduledLegDuration;
124+
}
125+
126+
@ToString
127+
public class AircraftEquipment {
128+
protected AircraftEquipment() {
129+
}
130+
131+
private @Getter String aircraftType;
132+
}
133+
134+
}
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)