Skip to content

Commit 107f1c6

Browse files
authored
Merge pull request #92 from amadeus4dev/flight-price-analysis
Add support for Flight Price Analysis
2 parents b205f62 + 4f2cc55 commit 107f1c6

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ DatedFlight[] flightStatus = amadeus.schedule.flights.get(Params
378378
.with("carrierCode", "AZ")
379379
.and("flightNumber", "319")
380380
.and("scheduledDepartureDate", "2021-03-13"));
381+
382+
// Flight Price Analysis
383+
ItineraryPriceMetric[] metrics = amadeus.analytics.itineraryPriceMetrics.get(Params
384+
.with("originIataCode", "MAD")
385+
.and("destinationIataCode", "CDG")
386+
.and("departureDate", "2021-03-21"));
381387
```
382388

383389
## Development & Contributing

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public class Amadeus extends HTTPClient {
9090
*/
9191
public Schedule schedule;
9292

93+
/**
94+
* <p>
95+
* A namespaced client for the <code>/v1/analytics</code> endpoints.
96+
* </p>
97+
*/
98+
public Analytics analytics;
99+
93100
protected Amadeus(Configuration configuration) {
94101
super(configuration);
95102
this.referenceData = new ReferenceData(this);
@@ -101,6 +108,7 @@ protected Amadeus(Configuration configuration) {
101108
this.media = new Media(this);
102109
this.safety = new Safety(this);
103110
this.schedule = new Schedule(this);
111+
this.analytics = new Analytics(this);
104112

105113
}
106114

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.analytics.ItineraryPriceMetrics;
4+
5+
/**
6+
* <p>
7+
* A namespaced client for the
8+
* <code>/v1/analytics</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.analytics;</pre>
18+
*
19+
* @hide
20+
*/
21+
public class Analytics {
22+
/**
23+
* <p>
24+
* A namespaced client for the
25+
* <code>/v1/analytics/itineraryPriceMetrics</code> endpoints.
26+
* </p>
27+
*/
28+
public ItineraryPriceMetrics itineraryPriceMetrics;
29+
30+
/**
31+
* Constructor.
32+
* @hide
33+
*/
34+
public Analytics(Amadeus client) {
35+
this.itineraryPriceMetrics = new ItineraryPriceMetrics(client);
36+
}
37+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.amadeus.analytics;
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.ItineraryPriceMetric;
8+
import com.amadeus.resources.Resource;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v1/analytics/itinerary-price-metrics</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.analytics.itineraryPriceMetrics;</pre>
23+
*/
24+
public class ItineraryPriceMetrics {
25+
private Amadeus client;
26+
27+
/**
28+
* Constructor.
29+
* @hide
30+
*/
31+
public ItineraryPriceMetrics(Amadeus client) {
32+
this.client = client;
33+
}
34+
35+
/**
36+
* <p>
37+
* Retrieves itinerary price metrics.
38+
* </p>
39+
*
40+
* <pre>
41+
* amadeus.analytics.itineraryPriceMetrics.get(Params
42+
* .with("originIataCode", "MAD")
43+
* .and("destinationIataCode", "CDG")
44+
* .and("departureDate", "2021-03-21"));</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 ItineraryPriceMetric[] get(Params params) throws ResponseException {
51+
Response response = client.get("/v1/analytics/itinerary-price-metrics", params);
52+
return (ItineraryPriceMetric[]) Resource.fromArray(response, ItineraryPriceMetric[].class);
53+
}
54+
55+
/**
56+
* Convenience method for calling <code>get</code> without any parameters.
57+
* @see ItineraryPriceMetric#get()
58+
*/
59+
public ItineraryPriceMetric[] get() throws ResponseException {
60+
return get(null);
61+
}
62+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* A ItineraryPriceMetric object as returned by the Flight Price Analysis API.
8+
* @see com.amadeus.analytics.ItineraryPriceMetrics#get()
9+
*/
10+
@ToString
11+
public class ItineraryPriceMetric extends Resource {
12+
protected ItineraryPriceMetric() {}
13+
14+
private @Getter String type;
15+
private @Getter Location origin;
16+
private @Getter Location destination;
17+
private @Getter String departureDate;
18+
private @Getter String transportType;
19+
private @Getter String currencyCode;
20+
private @Getter Boolean oneWay;
21+
private @Getter PriceMetrics[] priceMetrics;
22+
23+
@ToString
24+
public class Location {
25+
protected Location() {}
26+
27+
private @Getter String iataCode;
28+
}
29+
30+
@ToString
31+
public class PriceMetrics {
32+
protected PriceMetrics() {}
33+
34+
private @Getter String amount;
35+
private @Getter String quartileRanking;
36+
}
37+
38+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.amadeus;
22

33
import com.amadeus.airport.predictions.AirportOnTime;
4+
import com.amadeus.analytics.ItineraryPriceMetrics;
45
import com.amadeus.booking.FlightOrder;
56
import com.amadeus.booking.FlightOrders;
67
import com.amadeus.booking.HotelBookings;
@@ -415,6 +416,16 @@ public void testGetMethods() throws ResponseException {
415416
TestCase.assertNotNull(flightStatus.get());
416417
TestCase.assertNotNull(flightStatus.get(params));
417418
TestCase.assertEquals(flightStatus.get().length, 2);
419+
420+
// Testing flight price analysis
421+
Mockito.when(client.get("/v1/analytics/itinerary-price-metrics", null))
422+
.thenReturn(multiResponse);
423+
Mockito.when(client.get("/v1/analytics/itinerary-price-metrics", params))
424+
.thenReturn(multiResponse);
425+
ItineraryPriceMetrics metrics = new ItineraryPriceMetrics(client);
426+
TestCase.assertNotNull(metrics.get());
427+
TestCase.assertNotNull(metrics.get(params));
428+
TestCase.assertEquals(metrics.get().length, 2);
418429
}
419430

420431
@Test

0 commit comments

Comments
 (0)