|
| 1 | +# Amadeus Java SDK |
| 2 | + |
| 3 | +[][travis] |
| 4 | +[][support] |
| 5 | + |
| 6 | +Amadeus provides a set of APIs for the travel industry. Flights, Hotels, Locations and more. |
| 7 | + |
| 8 | +For more details see the [Java |
| 9 | +documentation](https://amadeus4dev.github.io/amadeus-java/) on |
| 10 | +[Amadeus.com](https://developers.amadeus.com). |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +This library requires Java 1.7+. You can install install it via Maven or Gradle. |
| 15 | + |
| 16 | +#### Maven |
| 17 | +```xml |
| 18 | +<dependency> |
| 19 | + <groupId>com.amadeus</groupId> |
| 20 | + <artifactId>amadeus-java</artifactId> |
| 21 | + <version>1.0.0</version> |
| 22 | +</dependency> |
| 23 | +``` |
| 24 | +#### Gradle |
| 25 | +```js |
| 26 | +compile "com.amadeus:amadeus-java:1.0.0" |
| 27 | +``` |
| 28 | + |
| 29 | +## Getting Started |
| 30 | + |
| 31 | +To send make your first API call you will need to [register for an Amadeus |
| 32 | +Developer Account](https://developers.amadeus.com/create-account) and set up |
| 33 | +your first application. |
| 34 | + |
| 35 | +```java |
| 36 | +import com.amadeus.Amadeus; |
| 37 | +import com.amadeus.Params; |
| 38 | + |
| 39 | +import com.amadeus.exceptions.ResponseException; |
| 40 | +import com.amadeus.referenceData.Locations; |
| 41 | +import com.amadeus.resources.Location; |
| 42 | + |
| 43 | +public class AmadeusExample { |
| 44 | + public static void main(String[] args) throws ResponseException { |
| 45 | + Amadeus amadeus = Amadeus |
| 46 | + .builder("[client_id]", "[client_secret]") |
| 47 | + .build(); |
| 48 | + |
| 49 | + Location[] locations = amadeus.referenceData.locations.get(Params |
| 50 | + .with("keyword", "LON") |
| 51 | + .and("subType", Locations.ANY)); |
| 52 | + |
| 53 | + System.out.println(locations); |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## Initialization |
| 59 | + |
| 60 | +The client can be initialized directly. |
| 61 | + |
| 62 | +```java |
| 63 | +//Initialize using parameters |
| 64 | +Amadeus amadeus = Amadeus |
| 65 | + .builder("[client_id]", "[client_secret]") |
| 66 | + .build(); |
| 67 | +``` |
| 68 | + |
| 69 | +Alternatively it can be initialized without any parameters if the environment |
| 70 | +variables `AMADEUS_CLIENT_ID` and `AMADEUS_CLIENT_SECRET` are present. |
| 71 | + |
| 72 | +```java |
| 73 | +Amadeus amadeus = Amadeus |
| 74 | + .builder(System.getenv()) |
| 75 | + .build(); |
| 76 | +``` |
| 77 | + |
| 78 | +Your credentials can be found on the [Amadeus |
| 79 | +dashboard](https://developers.amadeus.com/my-apps). [Sign |
| 80 | +up](https://developers.amadeus.com/create-account) for an account today. |
| 81 | + |
| 82 | +By default the environment for the SDK is the `test` environment. To switch to |
| 83 | +a production (paid-for) environment please switch the hostname as follows: |
| 84 | + |
| 85 | +```java |
| 86 | +Amadeus amadeus = Amadeus |
| 87 | + .builder(System.getenv()) |
| 88 | + .setHostname("production") |
| 89 | + .build(); |
| 90 | +``` |
| 91 | + |
| 92 | +## Documentation |
| 93 | + |
| 94 | +Amadeus has a large set of APIs, and our documentation is here to get you |
| 95 | +started today. Head over to our |
| 96 | +[Reference](https://amadeus4dev.github.io/amadeus-java/) documentation for |
| 97 | +in-depth information about every SDK method, its arguments and return types. |
| 98 | + |
| 99 | + |
| 100 | +* [Get Started](https://amadeus4dev.github.io/amadeus-java/) documentation |
| 101 | + * [Initialize the SDK](https://amadeus4dev.github.io/amadeus-java/) |
| 102 | + * [Find an Airport](https://amadeus4dev.github.io/amadeus-java/) |
| 103 | + * [Find a Flight](https://amadeus4dev.github.io/amadeus-ruby/) |
| 104 | + * [Get Flight Inspiration](https://amadeus4dev.github.io/amadeus-ruby/) |
| 105 | + |
| 106 | +## Making API calls |
| 107 | + |
| 108 | +This library conveniently maps every API path to a similar path. |
| 109 | + |
| 110 | +For example, `GET /v2/reference-data/urls/checkin-links?airline=1X` would be: |
| 111 | + |
| 112 | +```java |
| 113 | +amadeus.referenceData.urls.checkinLinks.get(Params.with("airline", "1X")); |
| 114 | +``` |
| 115 | + |
| 116 | +Similarly, to select a resource by ID, you can pass in the ID to the **singular** path. |
| 117 | + |
| 118 | +For example, `GET /v1/shopping/hotel/ABC123/offers/DEF234` would be: |
| 119 | + |
| 120 | +```java |
| 121 | +amadeus.hotel("ABC123").offer("DEF234").get(...); |
| 122 | +``` |
| 123 | + |
| 124 | +You can make any arbitrary API call as well directly with the `.get` method. |
| 125 | +Keep in mind, this returns a raw `Resource` |
| 126 | + |
| 127 | +```java |
| 128 | +Resource resource = amadeus.get('/v2/reference-data/urls/checkin-links', |
| 129 | + Params.with("airline", "1X")); |
| 130 | + |
| 131 | +resource.getResult(); |
| 132 | +``` |
| 133 | + |
| 134 | +## Response |
| 135 | + |
| 136 | +Every successful API call returns a `Resource` object. The underlying |
| 137 | +`Resource` with the raw available. |
| 138 | + |
| 139 | +```java |
| 140 | +Location[] locations = amadeus.referenceData.locations.get(Params |
| 141 | + .with("keyword", "LON") |
| 142 | + .and("subType", Locations.ANY)); |
| 143 | + |
| 144 | + // The raw response, as a string |
| 145 | +locations[0].getResponse().getBody(); |
| 146 | +``` |
| 147 | + |
| 148 | +## Pagination |
| 149 | + |
| 150 | +If an API endpoint supports pagination, the other pages are available under the |
| 151 | +`.next`, `.previous`, `.last` and `.first` methods. |
| 152 | + |
| 153 | +```java |
| 154 | +Location[] locations = amadeus.referenceData.locations.get(Params |
| 155 | + .with("keyword", "LON") |
| 156 | + .and("subType", Locations.ANY)); |
| 157 | + |
| 158 | +// Fetches the next page |
| 159 | +Location[] locations = (Location[]) amadeus.next(locations[0]); |
| 160 | +``` |
| 161 | + |
| 162 | +If a page is not available, the method will return `null`. |
| 163 | + |
| 164 | +## Logging & Debugging |
| 165 | + |
| 166 | +The SDK makes it easy to add your own logger. |
| 167 | + |
| 168 | +```java |
| 169 | +require 'logger' |
| 170 | + |
| 171 | +amadeus = Amadeus::Client.new( |
| 172 | + client_id: '...', |
| 173 | + client_secret: '...', |
| 174 | + logger: Logger.new(STDOUT) |
| 175 | +) |
| 176 | +``` |
| 177 | + |
| 178 | +Additionally, to enable more verbose logging, you can set the appropriate level |
| 179 | +on your own logger, though the easiest way would be to enable debugging via a |
| 180 | +parameter on initialization, or using the `AMADEUS_LOG_LEVEL` environment |
| 181 | +variable. |
| 182 | + |
| 183 | +```java |
| 184 | +Amadeus amadeus = Amadeus |
| 185 | + .builder("[client_id]", "[client_secret]") |
| 186 | + .setLogLevel("debug") // or warn |
| 187 | + .build(); |
| 188 | +``` |
| 189 | + |
| 190 | +## List of supported endpoints |
| 191 | + |
| 192 | +```java |
| 193 | +// Flight Cheapest Date Search |
| 194 | +FlightDate[] flightDates = amadeus.shopping.flightDates.get(Params |
| 195 | + .with("origin", "NCE") |
| 196 | + .and("destination", "PAR") |
| 197 | + .and("duration", 1)); |
| 198 | + |
| 199 | +// Flight Inspiration Search |
| 200 | +FlightDestination[] flightDestinations = amadeus.shopping.flightDestinations.get(Params |
| 201 | + .with("origin", "MAD")); |
| 202 | + |
| 203 | +// Flight Low-fare Search |
| 204 | +FlightOffer[] flightOffers = amadeus.shopping.flightOffers.get(Params |
| 205 | + .with("origin", "MAD") |
| 206 | + .and("destination", "OPO") |
| 207 | + .and("departureDate", "2018-07-08")); |
| 208 | + |
| 209 | +// Flight Check-in Links |
| 210 | +CheckinLink[] checkinLinks = amadeus.referenceData.urls.checkinLinks.get(Params |
| 211 | + .with("airline", "1X")); |
| 212 | + |
| 213 | +// Airport & City Search (autocomplete) |
| 214 | +// Find all the cities and airports starting by the keyword 'Lon' |
| 215 | +Locations[] locations = amadeus.referenceData.locations.get(Param |
| 216 | + .with("keyword", "lon") |
| 217 | + .and("subType", Locations.ANY)); |
| 218 | + |
| 219 | +// Get a specific city or airport based on its id |
| 220 | +Location location = amadeus.referenceData |
| 221 | + .location("ALHR").get(); |
| 222 | + |
| 223 | +// Airport Nearest Relevant |
| 224 | +Locations[] locations = amadeus.referenceData.locations.airports.get(Params |
| 225 | + .with("longitude", 49.0000) |
| 226 | + .and("latitude", 2.55)); |
| 227 | + |
| 228 | +// Flight Most Searched Destinations |
| 229 | +FareSearch[] fareSearches = amadeus.travel.analytics.fareSearches.get(Params |
| 230 | + .with("origin", "NCE") |
| 231 | + .and("sourceCountry", "FR") |
| 232 | + .and("period", "2017-08")); |
| 233 | + |
| 234 | +// Flight Most Traveled Destinations |
| 235 | +AirTraffic[] airTraffics = amadeus.travel.analytics.airTraffic.traveled.get(Params |
| 236 | + .with("origin", "NCE") |
| 237 | + .and("period", "2017-08")); |
| 238 | + |
| 239 | +// Hotel Search API |
| 240 | +// Get list of hotels by cityCode |
| 241 | +HotelOffer[] offers = amadeus.shopping.hotelOffers.get(Params |
| 242 | + .with("cityCode", "PAR")); |
| 243 | +// Get list of offers for a specific hotel |
| 244 | +HotelOffer offer = amadeus.shopping |
| 245 | + .hotel("SMPARCOL") |
| 246 | + .hotelOffers.get(); |
| 247 | +// Confirm the availability of a specific offer for a specific hotel |
| 248 | +Offer offer = amadeus.shopping |
| 249 | + .hotel("SMPARCOL") |
| 250 | + .offer("4BA070CE929E135B3268A9F2D0C51E9D4A6CF318BA10485322FA2C7E78C7852E").get(); |
| 251 | +``` |
| 252 | + |
| 253 | +## Development & Contributing |
| 254 | + |
| 255 | +Want to contribute? Read our [Contributors Guide](.github/CONTRIBUTING.md) for |
| 256 | +guidance on installing and running this code in a development environment. |
| 257 | + |
| 258 | + |
| 259 | +## License |
| 260 | + |
| 261 | +This library is released under the [MIT License](LICENSE). |
| 262 | + |
| 263 | +## Help |
| 264 | + |
| 265 | +Our [developer support team](https://developers.amadeus.com/support) is here |
| 266 | +to help you. You can find us on |
| 267 | +[StackOverflow](https://stackoverflow.com/questions/tagged/amadeus) and |
| 268 | +[email ](mailto:[email protected]). |
| 269 | + |
| 270 | +[travis]: http://travis-ci.org/amadeus4dev/amadeus-java |
| 271 | +[support]: http://developers.amadeus.com/support |
0 commit comments