Skip to content

Commit b609ee3

Browse files
committed
Add actual resources
1 parent 2758456 commit b609ee3

26 files changed

+634
-100
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ javadoc {
7575

7676
cobertura {
7777
coverageFormats = ['html', 'xml']
78-
coverageIgnores = [ 'java.io.UnsupportedEncodingException' ]
78+
coverageIgnores = [ 'java.io.UnsupportedEncodingException', 'com.amadeus.resources.*' ]
7979
coverageIgnoreTrivial = true
8080
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.amadeus.exceptions.ParserException;
77
import com.amadeus.exceptions.ResponseException;
88
import com.amadeus.exceptions.ServerException;
9-
import com.google.gson.JsonArray;
9+
import com.google.gson.JsonElement;
1010
import com.google.gson.JsonObject;
1111
import com.google.gson.JsonParser;
1212
import java.io.BufferedReader;
@@ -39,7 +39,7 @@ public class Response {
3939
/**
4040
* The data extracted from the JSON data - if the body contained JSON.
4141
*/
42-
private @Getter JsonArray data;
42+
private @Getter JsonElement data;
4343
/**
4444
* The raw body received from the API.
4545
*/
@@ -97,7 +97,12 @@ private void parseData(HTTPClient client) {
9797
this.result = parseJson(client);
9898
this.parsed = this.result != null;
9999
if (parsed && result.has("data")) {
100-
this.data = result.get("data").getAsJsonArray();
100+
if (result.get("data").isJsonArray()) {
101+
this.data = result.get("data").getAsJsonArray();
102+
}
103+
if (result.get("data").isJsonObject()) {
104+
this.data = result.get("data").getAsJsonObject();
105+
}
101106
}
102107
}
103108

src/main/java/com/amadeus/referenceData/Location.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
77
import com.amadeus.referenceData.locations.Airports;
8+
import com.google.gson.Gson;
89

910
/**
1011
* <p>
@@ -47,16 +48,17 @@ public Location(Amadeus client, String locationId) {
4748
* @return an API response object
4849
* @throws ResponseException when an exception occurs
4950
*/
50-
public Response get(Params params) throws ResponseException {
51+
public com.amadeus.resources.Location get(Params params) throws ResponseException {
5152
String path = String.format("/v1/reference-data/locations/%s", locationId);
52-
return client.get(path, params);
53+
Response response = client.get(path, params);
54+
return new Gson().fromJson(response.getData(), com.amadeus.resources.Location.class);
5355
}
5456

5557
/**
5658
* Convenience method for calling <code>get</code> without any parameters.
5759
* @see Airports#get()
5860
*/
59-
public Response get() throws ResponseException {
61+
public com.amadeus.resources.Location get() throws ResponseException {
6062
return get(null);
6163
}
6264
}

src/main/java/com/amadeus/referenceData/Locations.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
77
import com.amadeus.referenceData.locations.Airports;
8-
import com.amadeus.referenceData.urls.CheckinLinks;
8+
import com.amadeus.resources.Location;
9+
import com.google.gson.Gson;
910

1011
/**
1112
* <p>
@@ -61,15 +62,16 @@ public Locations(Amadeus client) {
6162
* @return an API response object
6263
* @throws ResponseException when an exception occurs
6364
*/
64-
public Response get(Params params) throws ResponseException {
65-
return client.get("/v1/reference-data/locations", params);
65+
public Location[] get(Params params) throws ResponseException {
66+
Response response = client.get("/v1/reference-data/locations", params);
67+
return new Gson().fromJson(response.getData(), Location[].class);
6668
}
6769

6870
/**
6971
* Convenience method for calling <code>get</code> without any parameters.
7072
* @see Airports#get()
7173
*/
72-
public Response get() throws ResponseException {
74+
public Location[] get() throws ResponseException {
7375
return get(null);
7476
}
7577
}

src/main/java/com/amadeus/referenceData/locations/Airports.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.amadeus.Params;
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.Location;
8+
import com.google.gson.Gson;
79

810
/**
911
* <p>
@@ -44,15 +46,16 @@ public Airports(Amadeus client) {
4446
* @return an API response object
4547
* @throws ResponseException when an exception occurs
4648
*/
47-
public Response get(Params params) throws ResponseException {
48-
return client.get("/v1/reference-data/locations/airports", params);
49+
public Location[] get(Params params) throws ResponseException {
50+
Response response = client.get("/v1/reference-data/locations/airports", params);
51+
return new Gson().fromJson(response.getData(), Location[].class);
4952
}
5053

5154
/**
5255
* Convenience method for calling <code>get</code> without any parameters.
5356
* @see Airports#get()
5457
*/
55-
public Response get() throws ResponseException {
58+
public Location[] get() throws ResponseException {
5659
return get(null);
5760
}
5861
}

src/main/java/com/amadeus/referenceData/urls/CheckinLinks.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.amadeus.Params;
55
import com.amadeus.Response;
66
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.CheckinLink;
8+
import com.google.gson.Gson;
79

810
/**
911
* <p>
@@ -40,18 +42,19 @@ public CheckinLinks(Amadeus client) {
4042
* amadeus.referenceData.urls.checkinLinks.get(Params.with("airline", "1X"));</pre>
4143
*
4244
* @param params the parameters to send to the API
43-
* @return an API response object
45+
* @return an API resource
4446
* @throws ResponseException when an exception occurs
4547
*/
46-
public Response get(Params params) throws ResponseException {
47-
return client.get("/v2/reference-data/urls/checkin-links", params);
48+
public CheckinLink[] get(Params params) throws ResponseException {
49+
Response response = client.get("/v2/reference-data/urls/checkin-links", params);
50+
return new Gson().fromJson(response.getData(), CheckinLink[].class);
4851
}
4952

5053
/**
5154
* Convenience method for calling <code>get</code> without any parameters.
5255
* @see CheckinLinks#get()
5356
*/
54-
public Response get() throws ResponseException {
57+
public CheckinLink[] get() throws ResponseException {
5558
return get(null);
5659
}
5760
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
@ToString
7+
public class AirTraffic extends Resource {
8+
private @Getter String type;
9+
private @Getter String subType;
10+
private @Getter String destination;
11+
private @Getter Analytics analytics;
12+
13+
@ToString
14+
private class Analytics {
15+
private @Getter Flights flights;
16+
private @Getter Travellers travellers;
17+
18+
@ToString
19+
private class Flights {
20+
private @Getter Double score;
21+
}
22+
23+
@ToString
24+
private class Travellers {
25+
private @Getter Double score;
26+
}
27+
}
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
@ToString
7+
public class CheckinLink extends Resource {
8+
private @Getter String type;
9+
private @Getter String id;
10+
private @Getter String href;
11+
private @Getter String channel;
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.amadeus.resources;
2+
3+
import java.util.HashMap;
4+
import lombok.Getter;
5+
import lombok.ToString;
6+
7+
@ToString
8+
public class FareSearch extends Resource {
9+
private @Getter String type;
10+
private @Getter String period;
11+
private @Getter String origin;
12+
private @Getter String sourceCountry;
13+
private @Getter NumberOfSearches numberOfSearches;
14+
15+
@ToString
16+
private class NumberOfSearches {
17+
private @Getter HashMap<String, String> perDestination;
18+
private @Getter HashMap<String, Integer> perTripDuration;
19+
private @Getter HashMap<String, Integer> perDaysInAdvance;
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.amadeus.resources;
2+
3+
import java.util.Date;
4+
import lombok.Getter;
5+
import lombok.ToString;
6+
7+
@ToString
8+
public class FlightDate extends Resource {
9+
private @Getter String type;
10+
private @Getter String origin;
11+
private @Getter String destination;
12+
private @Getter Date departureDate;
13+
private @Getter Date returnDate;
14+
private @Getter Price price;
15+
16+
@ToString
17+
private class Price {
18+
private @Getter double total;
19+
}
20+
}

0 commit comments

Comments
 (0)