Skip to content

Commit 7b73f7e

Browse files
authored
Merge pull request #240 from amadeus4dev/fix-issues
Fix small issues
2 parents d852c05 + c554832 commit 7b73f7e

File tree

10 files changed

+39
-31
lines changed

10 files changed

+39
-31
lines changed

src/main/java/com/amadeus/HTTPClient.java

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

3-
import com.amadeus.Constants;
43
import com.amadeus.client.AccessToken;
54
import com.amadeus.exceptions.NetworkException;
65
import com.amadeus.exceptions.ResponseException;
@@ -378,11 +377,13 @@ private Request fetch(Request request) throws NetworkException {
378377
// Writes the parameters to the request.
379378
private void write(Request request) throws IOException {
380379

380+
final String encoding = "UTF-8";
381+
381382
// POST with access token + body + URL parameters
382383
if (request.getVerb() == HttpVerbs.POST && request.getParams() != null
383384
&& request.getBearerToken() != null) {
384385
OutputStream os = request.getConnection().getOutputStream();
385-
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
386+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
386387
// writer.write(request.getParams().toQueryString());
387388
if (request.getBody() != null) {
388389
writer.write(request.getBody());
@@ -396,7 +397,7 @@ private void write(Request request) throws IOException {
396397
if (request.getVerb() == HttpVerbs.POST && request.getParams() != null
397398
&& request.getBearerToken() == null) {
398399
OutputStream os = request.getConnection().getOutputStream();
399-
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
400+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
400401
writer.write(request.getParams().toQueryString());
401402
writer.flush();
402403
writer.close();
@@ -406,7 +407,7 @@ private void write(Request request) throws IOException {
406407
// POST with access token + body
407408
if (request.getVerb() == HttpVerbs.POST && request.getParams() == null) {
408409
OutputStream os = request.getConnection().getOutputStream();
409-
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
410+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
410411
if (request.getBody() != null) {
411412
writer.write(request.getBody());
412413
}

src/main/java/com/amadeus/Response.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private void parseStatusCode() {
100100

101101
// Tries to parse the data
102102
private void parseData() {
103+
final String warningsValue = "warnings";
103104
this.parsed = false;
104105
this.body = readBody();
105106
this.result = parseJson();
@@ -112,12 +113,12 @@ private void parseData() {
112113
this.data = result.get("data").getAsJsonObject();
113114
}
114115
}
115-
if (parsed && result.has("warnings")) {
116-
if (result.get("warnings").isJsonArray()) {
117-
this.warnings = result.get("warnings").getAsJsonArray();
116+
if (parsed && result.has(warningsValue)) {
117+
if (result.get(warningsValue).isJsonArray()) {
118+
this.warnings = result.get(warningsValue).getAsJsonArray();
118119
}
119-
if (result.get("warnings").isJsonObject()) {
120-
this.warnings = result.get("warnings").getAsJsonObject();
120+
if (result.get(warningsValue).isJsonObject()) {
121+
this.warnings = result.get(warningsValue).getAsJsonObject();
121122
}
122123
}
123124
}

src/main/java/com/amadeus/booking/FlightOrders.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232
public class FlightOrders {
3333
private Amadeus client;
34+
private static final String FLIGHT_ORDERS_URL = "/v1/booking/flight-orders";
3435

3536
/**
3637
* Constructor.
@@ -89,7 +90,7 @@ private JsonArray buildFlightOffersJSON(FlightOfferSearch[] flightOffers) {
8990
* @throws ResponseException when an exception occurs
9091
*/
9192
public FlightOrder post(JsonObject body) throws ResponseException {
92-
Response response = client.post("/v1/booking/flight-orders", body);
93+
Response response = client.post(FLIGHT_ORDERS_URL, body);
9394
return (FlightOrder) Resource.fromObject(response, FlightOrder.class);
9495
}
9596

@@ -106,7 +107,7 @@ public FlightOrder post(JsonObject body) throws ResponseException {
106107
* @throws ResponseException when an exception occurs
107108
*/
108109
public FlightOrder post(String body) throws ResponseException {
109-
Response response = client.post("/v1/booking/flight-orders", body);
110+
Response response = client.post(FLIGHT_ORDERS_URL, body);
110111
return (FlightOrder) Resource.fromObject(response, FlightOrder.class);
111112
}
112113

@@ -140,7 +141,7 @@ public FlightOrder post(FlightOfferSearch[] flightOffersSearches,
140141
JsonObject jsonObject = new JsonObject();
141142
jsonObject.add("data", typeObject);
142143

143-
Response response = client.post("/v1/booking/flight-orders", jsonObject);
144+
Response response = client.post(FLIGHT_ORDERS_URL, jsonObject);
144145
return (FlightOrder) Resource.fromObject(response, FlightOrder.class);
145146
}
146147

@@ -194,7 +195,7 @@ public FlightOrder post(FlightPrice flightPrice,
194195
JsonObject jsonObject = new JsonObject();
195196
jsonObject.add("data", typeObject);
196197

197-
Response response = client.post("/v1/booking/flight-orders", jsonObject);
198+
Response response = client.post(FLIGHT_ORDERS_URL, jsonObject);
198199
return (FlightOrder) Resource.fromObject(response, FlightOrder.class);
199200
}
200201

src/main/java/com/amadeus/exceptions/ResponseException.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private static StringBuffer getErrorDescription(Response response) {
8181

8282
private static StringBuffer getErrorsDescription(Response response) {
8383
StringBuffer message = new StringBuffer();
84+
final String detail = "detail";
8485
for (JsonElement error : response.getResult().get("errors").getAsJsonArray()) {
8586
JsonObject json = error.getAsJsonObject();
8687
message.append("\n");
@@ -90,8 +91,8 @@ private static StringBuffer getErrorsDescription(Response response) {
9091
message.append(String.format("[%s] ", source.get("parameter").getAsString()));
9192
}
9293
}
93-
if (json.has("detail") && !json.get("detail").isJsonNull()) {
94-
message.append(String.format("%s", json.get("detail").getAsString()));
94+
if (json.has(detail) && !json.get(detail).isJsonNull()) {
95+
message.append(String.format("%s", json.get(detail).getAsString()));
9596
}
9697
}
9798
return message;

src/main/java/com/amadeus/shopping/FlightOffersSearch.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
public class FlightOffersSearch {
2727
private Amadeus client;
2828
public Pricing pricing;
29+
private static final String FLIGHT_OFFERS_URL = "/v2/shopping/flight-offers";
2930

3031
/**
3132
* Constructor.
@@ -54,7 +55,7 @@ public FlightOffersSearch(Amadeus client) {
5455
* @throws ResponseException when an exception occurs
5556
*/
5657
public FlightOfferSearch[] get(Params params) throws ResponseException {
57-
Response response = client.get("/v2/shopping/flight-offers", params);
58+
Response response = client.get(FLIGHT_OFFERS_URL, params);
5859
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
5960
}
6061

@@ -83,7 +84,7 @@ public FlightOfferSearch[] get() throws ResponseException {
8384
* @throws ResponseException when an exception occurs
8485
*/
8586
public FlightOfferSearch[] post(JsonObject body) throws ResponseException {
86-
Response response = client.post("/v2/shopping/flight-offers", body);
87+
Response response = client.post(FLIGHT_OFFERS_URL, body);
8788
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
8889
}
8990

@@ -104,7 +105,7 @@ public FlightOfferSearch[] post(JsonObject body) throws ResponseException {
104105
* @throws ResponseException when an exception occurs
105106
*/
106107
public FlightOfferSearch[] post(String body) throws ResponseException {
107-
Response response = client.post("/v2/shopping/flight-offers", body);
108+
Response response = client.post(FLIGHT_OFFERS_URL, body);
108109
return (FlightOfferSearch[]) Resource.fromArray(response, FlightOfferSearch[].class);
109110
}
110111

src/main/java/com/amadeus/shopping/SeatMaps.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
public class SeatMaps {
2626
private Amadeus client;
27+
private static final String SEATMAP_URL = "/v1/shopping/seatmaps";
2728

2829
/**
2930
* Constructor.
@@ -48,7 +49,7 @@ public SeatMaps(Amadeus client) {
4849
* @throws ResponseException when an exception occurs
4950
*/
5051
public SeatMap[] get(Params params) throws ResponseException {
51-
Response response = client.get("/v1/shopping/seatmaps", params);
52+
Response response = client.get(SEATMAP_URL, params);
5253
return (SeatMap[]) Resource.fromArray(response, SeatMap[].class);
5354
}
5455

@@ -75,7 +76,7 @@ public SeatMap[] get() throws ResponseException {
7576
* @throws ResponseException when an exception occurs
7677
*/
7778
public SeatMap[] post(JsonObject body) throws ResponseException {
78-
Response response = client.post("/v1/shopping/seatmaps", body);
79+
Response response = client.post(SEATMAP_URL, body);
7980
return (SeatMap[]) Resource.fromArray(response, SeatMap[].class);
8081
}
8182

@@ -94,7 +95,7 @@ public SeatMap[] post(JsonObject body) throws ResponseException {
9495
* @throws ResponseException when an exception occurs
9596
*/
9697
public SeatMap[] post(String body) throws ResponseException {
97-
Response response = client.post("/v1/shopping/seatmaps", body);
98+
Response response = client.post(SEATMAP_URL, body);
9899
return (SeatMap[]) Resource.fromArray(response, SeatMap[].class);
99100
}
100101

src/main/java/com/amadeus/shopping/flightOffers/Pricing.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
public class Pricing {
3232

3333
private Amadeus client;
34+
private static final String PRICING_URL = "/v1/shopping/flight-offers/pricing";
3435

3536
/**
3637
* Constructor.
@@ -89,7 +90,7 @@ private JsonArray buildPaymentJSON(FlightPayment flightPayment) {
8990
* @throws ResponseException when an exception occurs
9091
*/
9192
public FlightPrice post(JsonObject body, Params params) throws ResponseException {
92-
Response response = client.post("/v1/shopping/flight-offers/pricing", params, body);
93+
Response response = client.post(PRICING_URL, params, body);
9394
return (FlightPrice) Resource.fromObject(response, FlightPrice.class);
9495
}
9596

@@ -110,7 +111,7 @@ public FlightPrice post(JsonObject body, Params params) throws ResponseException
110111
* @throws ResponseException when an exception occurs
111112
*/
112113
public FlightPrice post(String body, Params params) throws ResponseException {
113-
Response response = client.post("/v1/shopping/flight-offers/pricing", params, body);
114+
Response response = client.post(PRICING_URL, params, body);
114115
return (FlightPrice) Resource.fromObject(response, FlightPrice.class);
115116
}
116117

@@ -130,7 +131,7 @@ public FlightPrice post(String body, Params params) throws ResponseException {
130131
* @throws ResponseException when an exception occurs
131132
*/
132133
public FlightPrice post(JsonObject body) throws ResponseException {
133-
Response response = client.post("/v1/shopping/flight-offers/pricing", body);
134+
Response response = client.post(PRICING_URL, body);
134135
return (FlightPrice) Resource.fromObject(response, FlightPrice.class);
135136
}
136137

@@ -150,7 +151,7 @@ public FlightPrice post(JsonObject body) throws ResponseException {
150151
* @throws ResponseException when an exception occurs
151152
*/
152153
public FlightPrice post(String body) throws ResponseException {
153-
Response response = client.post("/v1/shopping/flight-offers/pricing", body);
154+
Response response = client.post(PRICING_URL, body);
154155
return (FlightPrice) Resource.fromObject(response, FlightPrice.class);
155156
}
156157

@@ -227,9 +228,9 @@ public FlightPrice post(FlightOfferSearch[] flightOffersSearches,
227228
// Is it a call with param or without param?
228229
if (params != null) {
229230
response = client.post(
230-
"/v1/shopping/flight-offers/pricing", params, jsonObject);
231+
PRICING_URL, params, jsonObject);
231232
} else {
232-
response = client.post("/v1/shopping/flight-offers/pricing", jsonObject);
233+
response = client.post(PRICING_URL, jsonObject);
233234
}
234235
return (FlightPrice) Resource.fromObject(response, FlightPrice.class);
235236
}
@@ -287,7 +288,7 @@ public FlightPrice post(FlightOfferSearch[] flightOffersSearches,
287288
JsonObject jsonObject = new JsonObject();
288289
jsonObject.add("data", typeObject);
289290

290-
Response response = client.post("/v1/shopping/flight-offers/pricing", jsonObject);
291+
Response response = client.post(PRICING_URL, jsonObject);
291292
return (FlightPrice) Resource.fromObject(response, FlightPrice.class);
292293
}
293294

src/main/java/com/amadeus/travel/TripParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
public class TripParser {
2929
private Amadeus client;
30+
private static final String TRIP_PARSER_URL = "/v3/travel/trip-parser";
3031

3132
/**
3233
* Constructor.
@@ -51,7 +52,7 @@ public TripParser(Amadeus client) {
5152
* @throws ResponseException when an exception occurs
5253
*/
5354
public TripDetail post(JsonObject body) throws ResponseException {
54-
Response response = client.post("/v3/travel/trip-parser", body);
55+
Response response = client.post(TRIP_PARSER_URL, body);
5556
return (TripDetail) Resource.fromObject(response, TripDetail.class);
5657
}
5758

@@ -69,7 +70,7 @@ public TripDetail post(JsonObject body) throws ResponseException {
6970
* @throws ResponseException when an exception occurs
7071
*/
7172
public TripDetail post(String body) throws ResponseException {
72-
Response response = client.post("/v3/travel/trip-parser", body);
73+
Response response = client.post(TRIP_PARSER_URL, body);
7374
return (TripDetail) Resource.fromObject(response, TripDetail.class);
7475
}
7576

@@ -98,7 +99,7 @@ public TripDetail post(File file) throws ResponseException, IOException {
9899
body.addProperty("payload", encodedFile);
99100
count = count + fileInputStreamReader.read(bytes);
100101

101-
Response response = client.post("/v3/travel/trip-parser", body);
102+
Response response = client.post(TRIP_PARSER_URL, body);
102103
return (TripDetail) Resource.fromObject(response, TripDetail.class);
103104
}
104105
}

0 commit comments

Comments
 (0)