Skip to content

Commit a02925b

Browse files
author
Anthony Roux
committed
Update authentication documentation and examples
1 parent fea9573 commit a02925b

File tree

3 files changed

+74
-72
lines changed

3 files changed

+74
-72
lines changed

README.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import com.amadeus.resources.Location;
5959
public class AmadeusExample {
6060
public static void main(String[] args) throws ResponseException {
6161
Amadeus amadeus = Amadeus
62-
.builder("[client_id]", "[client_secret]")
62+
.builder("REPLACE_BY_YOUR_API_KEY", "REPLACE_BY_YOUR_API_SECRET")
6363
.build();
6464

6565
Location[] locations = amadeus.referenceData.locations.get(Params
@@ -78,7 +78,7 @@ The client can be initialized directly.
7878
```java
7979
//Initialize using parameters
8080
Amadeus amadeus = Amadeus
81-
.builder("[client_id]", "[client_secret]")
81+
.builder("REPLACE_BY_YOUR_API_KEY", "REPLACE_BY_YOUR_API_SECRET")
8282
.build();
8383
```
8484

@@ -123,10 +123,10 @@ in-depth information about every SDK method, its arguments and return types.
123123

124124
This library conveniently maps every API path to a similar path.
125125

126-
For example, `GET /v2/reference-data/urls/checkin-links?airline=1X` would be:
126+
For example, `GET /v2/reference-data/urls/checkin-links?airline=BA` would be:
127127

128128
```java
129-
amadeus.referenceData.urls.checkinLinks.get(Params.with("airline", "1X"));
129+
amadeus.referenceData.urls.checkinLinks.get(Params.with("airline", "BA"));
130130
```
131131

132132
Similarly, to select a resource by ID, you can pass in the ID to the **singular** path.
@@ -142,7 +142,7 @@ Keep in mind, this returns a raw `Resource`
142142

143143
```java
144144
Resource resource = amadeus.get('/v2/reference-data/urls/checkin-links',
145-
Params.with("airline", "1X"));
145+
Params.with("airline", "BA"));
146146

147147
resource.getResult();
148148
```
@@ -181,13 +181,18 @@ If a page is not available, the method will return `null`.
181181

182182
The SDK makes it easy to add your own logger.
183183

184-
```java
185-
require 'logger'
184+
```java TO FIX
185+
import java.util.logging.Logger;
186+
187+
// Assumes the current class is called MyLogger
188+
private final static Logger LOGGER = Logger.getLogger(MyLogger.class.getName());
186189

187-
amadeus = Amadeus::Client.new(
188-
client_id: '...',
189-
client_secret: '...',
190-
logger: Logger.new(STDOUT)
190+
...
191+
192+
Amadeus amadeus = Amadeus
193+
.builder("REPLACE_BY_YOUR_API_KEY", "REPLACE_BY_YOUR_API_KEY")
194+
.setLogger(LOGGER)
195+
.build();
191196
)
192197
```
193198

@@ -198,29 +203,27 @@ variable.
198203

199204
```java
200205
Amadeus amadeus = Amadeus
201-
.builder("[client_id]", "[client_secret]")
206+
.builder("REPLACE_BY_YOUR_API_KEY", "REPLACE_BY_YOUR_API_KEY")
202207
.setLogLevel("debug") // or warn
203208
.build();
204209
```
205210

206211
## List of supported endpoints
207-
208212
```java
209-
// Flight Cheapest Date Search
210-
FlightDate[] flightDates = amadeus.shopping.flightDates.get(Params
211-
.with("origin", "LON")
212-
.and("destination", "FRA")
213-
.and("duration", 3));
214-
215213
// Flight Inspiration Search
216214
FlightDestination[] flightDestinations = amadeus.shopping.flightDestinations.get(Params
217-
.with("origin", "LON"));
215+
.with("origin", "MAD"));
216+
217+
// Flight Cheapest Date Search
218+
FlightDate[] flightDates = amadeus.shopping.flightDates.get(Params
219+
.with("origin", "NYC")
220+
.and("destination", "MAD");
218221

219222
// Flight Low-fare Search
220223
FlightOffer[] flightOffers = amadeus.shopping.flightOffers.get(Params
221-
.with("origin", "MAD")
222-
.and("destination", "OPO")
223-
.and("departureDate", "2018-11-01"));
224+
.with("origin", "NYC")
225+
.and("destination", "MAD")
226+
.and("departureDate", "2019-08-01"));
224227

225228
// Flight Check-in Links
226229
CheckinLink[] checkinLinks = amadeus.referenceData.urls.checkinLinks.get(Params
@@ -231,11 +234,10 @@ Airline[] airlines = amadeus.referenceData.airlines.get(Params
231234
.with("IATACode", "BA"));
232235

233236
// Airport & City Search (autocomplete)
234-
// Find all the cities and airports starting by the keyword 'Lon'
237+
// Find all the cities and airports starting by the keyword 'LON'
235238
Location[] locations = amadeus.referenceData.locations.get(Params
236-
.with("keyword", "lon")
239+
.with("keyword", "LON")
237240
.and("subType", Locations.ANY));
238-
239241
// Get a specific city or airport based on its id
240242
Location location = amadeus.referenceData
241243
.location("ALHR").get();
@@ -247,36 +249,34 @@ Location[] locations = amadeus.referenceData.locations.airports.get(Params
247249

248250
// Flight Most Searched Destinations
249251
FareSearch[] fareSearches = amadeus.travel.analytics.fareSearches.get(Params
250-
.with("origin", "SFO")
251-
.and("sourceCountry", "US")
252-
.and("period", "2017-08"));
253-
254-
// Flight Most Traveled Destinations
255-
AirTraffic[] airTraffics = amadeus.travel.analytics.airTraffic.traveled.get(Params
256-
.with("origin", "NCE")
252+
.with("origin", "MAD")
253+
.and("sourceCountry", "SP")
257254
.and("period", "2017-08"));
258255

259256
// Flight Most Booked Destinations
260257
AirTraffic[] airTraffics = amadeus.travel.analytics.airTraffic.booked.get(Params
261-
.with("origin", "NCE")
258+
.with("origin", "MAD")
262259
.and("period", "2017-08"));
263260

261+
// Flight Most Traveled Destinations
262+
AirTraffic[] airTraffics = amadeus.travel.analytics.airTraffic.traveled.get(Params
263+
.with("origin", "MAD")
264+
.and("period", "2017-01"));
265+
264266
// Flight Busiest Traveling Period
265267
Period[] busiestPeriods = amadeus.travel.analytics.airTraffic.busiestPeriod.get(Params
266268
.with("cityCode", "MAD")
267269
.and("period", "2017")
268270
.and("direction", BusiestPeriod.ARRIVING));
269271

270272
// Hotel Search API
271-
// Get list of hotels by cityCode
273+
// Get list of hotels by city code
272274
HotelOffer[] offers = amadeus.shopping.hotelOffers.get(Params
273-
.with("cityCode", "PAR"));
274-
275+
.with("cityCode", "MAD"));
275276
// Get list of offers for a specific hotel
276277
HotelOffer offer = amadeus.shopping
277278
.hotel("SMPARCOL")
278279
.hotelOffers.get();
279-
280280
// Confirm the availability of a specific offer for a specific hotel
281281
Offer offer = amadeus.shopping
282282
.hotel("SMPARCOL")

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
import lombok.NonNull;
55

66
/**
7-
* <p>The Amadeus API client. To initialize, use the builder as follows:</p>
7+
* <p>
8+
* The Amadeus API client. To initialize, use the builder as follows:
9+
* </p>
810
*
911
* <pre>
10-
* Amadeus amadeus = Amadeus.builder("CLIENT_ID", "CLIENT_SECRET").build();
12+
* Amadeus amadeus = Amadeus.builder("REPLACE_BY_YOUR_API_KEY", "REPLACE_BY_YOUR_API_SECRET").build();
1113
* </pre>
1214
*
13-
* <p>Or pass in environment variables directly:</p>
15+
* <p>
16+
* Or pass in environment variables directly:
17+
* </p>
1418
*
1519
* <pre>
16-
* Amadeus.builder(System.getenv()).build();
20+
* Amadeus.builder(System.getenv()).build();
1721
* </pre>
1822
*/
1923
public class Amadeus extends HTTPClient {
@@ -24,24 +28,21 @@ public class Amadeus extends HTTPClient {
2428

2529
/**
2630
* <p>
27-
* A namespaced client for the
28-
* <code>/v2/reference-data</code> endpoints.
31+
* A namespaced client for the <code>/v2/reference-data</code> endpoints.
2932
* </p>
3033
*/
3134
public ReferenceData referenceData;
3235

3336
/**
3437
* <p>
35-
* A namespaced client for the
36-
* <code>/v1/travel</code> endpoints.
38+
* A namespaced client for the <code>/v1/travel</code> endpoints.
3739
* </p>
3840
*/
3941
public Travel travel;
4042

4143
/**
4244
* <p>
43-
* A namespaced client for the
44-
* <code>/v1/shopping</code> endpoints.
45+
* A namespaced client for the <code>/v1/shopping</code> endpoints.
4546
* </p>
4647
*/
4748
public Shopping shopping;
@@ -54,14 +55,14 @@ protected Amadeus(Configuration configuration) {
5455
}
5556

5657
/**
57-
* Creates a builder object that can be used to build
58-
* an Amadeus com.amadeus.client.
58+
* Creates a builder object that can be used to build an Amadeus
59+
* com.amadeus.client.
5960
*
6061
* <pre>
6162
* Amadeus amadeus = Amadeus.builder("CLIENT_ID", "CLIENT_SECRET").build();
6263
* </pre>
6364
*
64-
* @param clientId Your API com.amadeus.client credential ID
65+
* @param clientId Your API com.amadeus.client credential ID
6566
* @param clientSecret Your API com.amadeus.client credential secret
6667
* @return a Configuration object
6768
*/
@@ -70,8 +71,8 @@ public static Configuration builder(@NonNull String clientId, @NonNull String cl
7071
}
7172

7273
/**
73-
* Creates a builder object initialized with the environment variables that can be used to
74-
* build an Amadeus API com.amadeus.client.
74+
* Creates a builder object initialized with the environment variables that can
75+
* be used to build an Amadeus API com.amadeus.client.
7576
*
7677
* <pre>
7778
* Amadeus amadeus = Amadeus.builder(System.getenv()).build();

src/main/java/com/amadeus/Configuration.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,28 @@
77
import lombok.ToString;
88
import lombok.experimental.Accessors;
99

10-
1110
/**
12-
* <p>The configuration for the Amadeus API client. To initialize, use the builder as follows:</p>
11+
* <p>
12+
* The configuration for the Amadeus API client. To initialize, use the builder
13+
* as follows:
14+
* </p>
1315
*
1416
* <pre>
15-
* Amadeus amadeus = Amadeus.builder("CLIENT_ID", "CLIENT_SECRET").build();
17+
* Amadeus amadeus = Amadeus.builder("REPLACE_BY_YOUR_API_KEY", "REPLACE_BY_YOUR_API_SECRET").build();
1618
* </pre>
1719
*
18-
* <p>Or pass in environment variables directly:</p>
20+
* <p>
21+
* Or pass in environment variables directly:
22+
* </p>
1923
*
2024
* <pre>
21-
* Amadeus.builder(System.getenv()).build();
25+
* Amadeus.builder(System.getenv()).build();
2226
* </pre>
2327
*/
2428
@Accessors(chain = true)
2529
@ToString
2630
public class Configuration {
27-
private static final Params HOSTS = Params
28-
.with("production", "api.amadeus.com")
29-
.and("test", "test.api.amadeus.com");
31+
private static final Params HOSTS = Params.with("production", "api.amadeus.com").and("test", "test.api.amadeus.com");
3032

3133
/**
3234
* The client ID used to authenticate the API calls.
@@ -48,8 +50,7 @@ public class Configuration {
4850
*/
4951
private @Getter @Setter Logger logger = Logger.getLogger("Amadeus");
5052
/**
51-
* The log level. Can be 'silent', 'warn', or 'debug'.
52-
* Defaults to 'silent'.
53+
* The log level. Can be 'silent', 'warn', or 'debug'. Defaults to 'silent'.
5354
*
5455
* @param logLevel The log level for the logger
5556
* @return The log level for the logger
@@ -64,8 +65,8 @@ public class Configuration {
6465
*/
6566
private @Getter String hostname = "test";
6667
/**
67-
* The optional custom host domain to use for API calls.
68-
* Defaults to internal value for 'hostname'.
68+
* The optional custom host domain to use for API calls. Defaults to internal
69+
* value for 'hostname'.
6970
*
7071
* @param host The optional custom host domain to use for API calls.
7172
* @return The optional custom host domain to use for API calls.
@@ -79,24 +80,24 @@ public class Configuration {
7980
*/
8081
private @Getter boolean ssl = true;
8182
/**
82-
* The port to use. Defaults to 443 for an SSL connection, and 80 for
83-
* a non SSL connection.
83+
* The port to use. Defaults to 443 for an SSL connection, and 80 for a non SSL
84+
* connection.
8485
*
8586
* @param port The port to use for the connection
8687
* @return The port to use for the connection
8788
*/
8889
private @Getter @Setter int port = 443;
8990
/**
90-
* An optional custom App ID to be passed in the User Agent to the
91-
* server (Defaults to null).
91+
* An optional custom App ID to be passed in the User Agent to the server
92+
* (Defaults to null).
9293
*
9394
* @param customAppId An optional custom App ID
9495
* @return The optional custom App ID
9596
*/
9697
private @Getter @Setter String customAppId;
9798
/**
98-
* An optional custom App version to be passed in the User Agent to the
99-
* server (Defaults to null).
99+
* An optional custom App version to be passed in the User Agent to the server
100+
* (Defaults to null).
100101
*
101102
* @param customAppVersion An optional custom App version
102103
* @return The optional custom App version
@@ -128,7 +129,7 @@ public Amadeus build() throws NullPointerException {
128129
public Configuration setHostname(String hostname) {
129130
if (!HOSTS.containsKey(hostname)) {
130131
throw new IllegalArgumentException(
131-
String.format("Hostname %s not found in %s", hostname, HOSTS.keySet().toString()));
132+
String.format("Hostname %s not found in %s", hostname, HOSTS.keySet().toString()));
132133
}
133134
this.hostname = hostname;
134135
this.host = HOSTS.get(hostname);

0 commit comments

Comments
 (0)