-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmadeus_Integration.java
More file actions
53 lines (41 loc) · 1.84 KB
/
Amadeus_Integration.java
File metadata and controls
53 lines (41 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example.airlinebooking;
import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.exceptions.ResponseException;
import java.util.Scanner;
public class Amadeus_Integration {
// API KEY to initialize Amadeus API client
private static final Amadeus amadeus = Amadeus.builder("API_key", "API_secret").build();
public static void main( String[] args )
{
// User credentials
boolean isAuthenticated = authenicateUser();
if (isAuthenticated) {
try {
//User Inputs...integrate with html form
// Amadeus API to search flights
FlightOfferSearch[] flightOffers = amadeus.shopping.flightOfferSearch.get(
Params.with("originalLocationCode", origin).and("destinationLocationCode", destination).and("departureDate", departureDate).and("adults", passengers)
//add: infants, children, ....
);
//Print search results
for (flightOfferSearch offer : flightOffers) {
System.out.println("Airline " + offer.getItineraries()[0].getSegments()[0].getCarrierCode());
System.out.println("Departure Time: " + offer.getItineraries()[0].getSegments()[0].getDeparture().getAt());
System.out.println("Arrival Time: " + offer.getItineraries()[0].getSegments()[0].getArrival().getAt());
System.out.println("Price: " + offer.getPrice().getCurrency());
}
}
catch (ResponseException e) {
System.err.println("Error: " + e.getMessage()); //error message occured while calling API
}
} else{
System.out.println("failed to authenticate. Exiting...");
}
}
private static boolean userLogin() {
// TO DO: Implement user authentication logic
// until we implement auth, return true for testing purposes
return true;
}
}