Skip to content

Commit 6bb7412

Browse files
spirosbatzioanthonyroux
authored andcommitted
Introduce hotel ratings Api Support (#34)
#29 Add support for Hotel Ratings API
1 parent bb82f4a commit 6bb7412

File tree

7 files changed

+143
-1
lines changed

7 files changed

+143
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ HotelOffer[] offers = amadeus.shopping.hotelOffers.get(Params
307307
HotelOffer hotelOffer = amadeus.shopping.hotelOffersByHotel.get(Params.with("hotelId", "BGLONBGB"));
308308
// Confirm the availability of a specific offer
309309
HotelOffer offer = amadeus.shopping.hotelOffer("4BA070CE929E135B3268A9F2D0C51E9D4A6CF318BA10485322FA2C7E78C7852E").get();
310+
// Hotel Ratings / Sentiments
311+
HotelSentiment[] hotelSentiments = amadeus.ereputation.hotelSentiments.get(Params.with("hotelIds", "ELONMFS,ADNYCCTB"));
310312

311313
// Points of Interest
312314
// What are the popular places in Barcelona (based a geo location and a radius)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@ public class Amadeus extends HTTPClient {
4848
*/
4949
public Shopping shopping;
5050

51+
/**
52+
* <p>
53+
* A namespaced client for the <code>/v2/e-reputation</code> endpoints.
54+
* </p>
55+
*/
56+
public EReputation ereputation;
57+
5158
protected Amadeus(Configuration configuration) {
5259
super(configuration);
5360
this.referenceData = new ReferenceData(this);
5461
this.travel = new Travel(this);
5562
this.shopping = new Shopping(this);
63+
this.ereputation = new EReputation(this);
5664
}
5765

5866
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.amadeus;
2+
3+
import com.amadeus.ereputation.HotelSentiments;
4+
5+
public class EReputation {
6+
private Amadeus client;
7+
8+
/**
9+
* <p>
10+
* A namespaced client for the
11+
* <code>/v2/e-reputation/hotel-sentiments</code> endpoints.
12+
* </p>
13+
*/
14+
public HotelSentiments hotelSentiments;
15+
16+
public EReputation(Amadeus client) {
17+
this.client = client;
18+
this.hotelSentiments = new HotelSentiments(client);
19+
}
20+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public class Response {
4141
* The data extracted from the JSON data - if the body contained JSON.
4242
*/
4343
private @Getter JsonElement data;
44+
/**
45+
* The warnings received from the API call.
46+
*/
47+
private @Getter JsonElement warnings;
4448
/**
4549
* The raw body received from the API.
4650
*/
@@ -105,6 +109,14 @@ private void parseData(HTTPClient client) {
105109
this.data = result.get("data").getAsJsonObject();
106110
}
107111
}
112+
if (parsed && result.has("warnings")) {
113+
if (result.get("warnings").isJsonArray()) {
114+
this.warnings = result.get("warnings").getAsJsonArray();
115+
}
116+
if (result.get("warnings").isJsonObject()) {
117+
this.warnings = result.get("warnings").getAsJsonObject();
118+
}
119+
}
108120
}
109121

110122
// Tries to read the body.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.amadeus.ereputation;
2+
3+
import com.amadeus.Amadeus;
4+
import com.amadeus.Params;
5+
import com.amadeus.Response;
6+
import com.amadeus.exceptions.ResponseException;
7+
import com.amadeus.resources.HotelSentiment;
8+
import com.amadeus.resources.Resource;
9+
10+
/**
11+
* <p>
12+
* A namespaced client for the
13+
* <code>/v2/e-reputation/hotel-sentiments</code> endpoints.
14+
* </p>
15+
*
16+
* <p>
17+
* Access via the Amadeus client object.
18+
* </p>
19+
*
20+
* <pre>
21+
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
22+
* amadeus.ereputation.hotelSentiments;</pre>
23+
*/
24+
25+
public class HotelSentiments {
26+
private Amadeus client;
27+
28+
/**
29+
* Constructor.
30+
* @hide
31+
*/
32+
public HotelSentiments(Amadeus client) {
33+
this.client = client;
34+
}
35+
36+
/**
37+
* <p>
38+
* Hotel ratings based on automated sentiment analysis algorithm
39+
* applied on the online reviews.
40+
* </p>
41+
*
42+
* <pre>
43+
* amadeus.ereputation.hotelSentiments.get(Params
44+
* .with("hotelIds", "ELONMFS,ADNYCCTB"));</pre>
45+
*
46+
* @param params the parameters to send to the API
47+
* @return an API response object
48+
* @throws ResponseException when an exception occurs
49+
*/
50+
public HotelSentiment[] get(Params params) throws ResponseException {
51+
Response response = client.get("/v2/e-reputation/hotel-sentiments", params);
52+
return (HotelSentiment[]) Resource.fromArray(response, HotelSentiment[].class);
53+
}
54+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.amadeus.resources;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* An HotelSentiment object as returned by the Hotel Ratings API.
8+
* @see HotelSentiments#get()
9+
*/
10+
11+
@ToString
12+
public class HotelSentiment extends Resource {
13+
protected HotelSentiment() {}
14+
15+
private @Getter String hotelId;
16+
private @Getter String type;
17+
private @Getter int overallRating;
18+
private @Getter int numberOfReviews;
19+
private @Getter Sentiment sentiments;
20+
21+
@ToString
22+
public class Sentiment {
23+
protected Sentiment() {}
24+
25+
private @Getter int staff;
26+
private @Getter int location;
27+
private @Getter int service;
28+
private @Getter int roomComforts;
29+
private @Getter int sleepQuality;
30+
private @Getter int swimmingPool;
31+
private @Getter int valueForMoney;
32+
private @Getter int facilities;
33+
private @Getter int catering;
34+
private @Getter int pointsOfInterest;
35+
}
36+
37+
}

src/test/java/com/amadeus/NamespaceTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.amadeus;
22

3+
import com.amadeus.ereputation.HotelSentiments;
34
import com.amadeus.exceptions.ResponseException;
45
import com.amadeus.referenceData.Airlines;
56
import com.amadeus.referenceData.Location;
67
import com.amadeus.referenceData.Locations;
78
import com.amadeus.referenceData.locations.Airports;
89
import com.amadeus.referenceData.locations.PointsOfInterest;
9-
import com.amadeus.referenceData.locations.pointsOfInterest.BySquare;
1010
import com.amadeus.referenceData.urls.CheckinLinks;
1111
import com.amadeus.shopping.FlightDates;
1212
import com.amadeus.shopping.FlightDestinations;
@@ -56,6 +56,7 @@ public void testAllNamespacesExist() {
5656
TestCase.assertNotNull(client.shopping.flightOffers.prediction);
5757
TestCase.assertNotNull(client.shopping.hotelOffers);
5858
TestCase.assertNotNull(client.shopping.hotelOffersByHotel);
59+
TestCase.assertNotNull(client.ereputation.hotelSentiments);
5960
TestCase.assertNotNull(client.shopping.hotelOffer("XXX"));
6061
}
6162

@@ -268,6 +269,14 @@ public void testGetMethods() throws ResponseException {
268269
FlightOffersSearch flightOfferSearch = new FlightOffersSearch(client);
269270
TestCase.assertNotNull(flightOfferSearch.get(params));
270271

272+
// Test hotel ratings
273+
Mockito.when(client.get("/v2/e-reputation/hotel-sentiments", null))
274+
.thenReturn(multiResponse);
275+
Mockito.when(client.get("/v2/e-reputation/hotel-sentiments", params))
276+
.thenReturn(multiResponse);
277+
HotelSentiments hotelSentiments = new HotelSentiments(client);
278+
TestCase.assertNotNull(hotelSentiments.get(params));
279+
271280
}
272281

273282
@Test

0 commit comments

Comments
 (0)