Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Hotel Booking v2 #265

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ HotelOfferSearch offer = amadeus.shopping.hotelOfferSearch("QF3MNOBDQ8").get();
// The body can be a String version of your JSON or a JsonObject
HotelBooking[] hotel = amadeus.booking.hotelBookings.post(body);

// Hotel Booking v2
HotelOrder hotel = amadeus.booking.hotelOrders.post(body);

// Hotel Ratings / Sentiments
HotelSentiment[] hotelSentiments = amadeus.ereputation.hotelSentiments.get(Params.with("hotelIds", "ELONMFS,ADNYCCTB"));

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/amadeus/Booking.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.amadeus.booking.FlightOrder;
import com.amadeus.booking.FlightOrders;
import com.amadeus.booking.HotelBookings;
import com.amadeus.booking.HotelOrders;

public class Booking {
private Amadeus client;
Expand Down Expand Up @@ -31,6 +32,14 @@ public class Booking {
*/
public HotelBookings hotelBookings;

/**
* <p>
* A namespaced client for the
* <code>/v2/booking/hotelOrders</code> endpoints.
* </p>
*/
public HotelOrders hotelOrders;

/**
* Constructor.
* @hide
Expand All @@ -39,6 +48,7 @@ public Booking(Amadeus client) {
this.client = client;
this.flightOrders = new FlightOrders(client);
this.hotelBookings = new HotelBookings(client);
this.hotelOrders = new HotelOrders(client);
}

public FlightOrder flightOrder(String flightOrderId) {
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/com/amadeus/booking/HotelOrders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.amadeus.booking;

import com.amadeus.Amadeus;
import com.amadeus.Response;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.HotelOrder;
import com.amadeus.resources.Resource;
import com.google.gson.JsonObject;

/**
* <p>
* A namespaced client for the
* <code>/v2/booking/hotel-orders</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder(API_KEY, API_SECRET).build();
* amadeus.booking.HotelOrders;</pre>
*/
public class HotelOrders {
private Amadeus client;

/**
* Constructor.
*
* @hide
*/
public HotelOrders(Amadeus client) {
this.client = client;
}

/**
* <p>
* The Hotel Booking API allows you to perform hotel booking.
* </p>
*
* <pre>
* amadeus.booking.hotelOrders.post(body);</pre>
*
* @param body the parameters to send to the API as a JSonObject
* @return an API resource
* @throws ResponseException when an exception occurs
*/
public HotelOrder post(JsonObject body) throws ResponseException {
Response response = client.post("/v2/booking/hotel-orders", body);
return (HotelOrder) Resource.fromObject(response, HotelOrder.class);
}

/**
* <p>
* The Hotel Booking API allows you to perform hotel booking.
* </p>
*
* <pre>
* amadeus.booking.hotelOrders.post(body);</pre>
*
* @param body the parameters to send to the API as a String
* @return an API resource
* @throws ResponseException when an exception occurs
*/
public HotelOrder post(String body) throws ResponseException {
Response response = client.post("/v2/booking/hotel-orders", body);
return (HotelOrder) Resource.fromObject(response, HotelOrder.class);
}

/**
* Convenience method for calling <code>post</code> without any parameters.
*
* @see HotelBookings#post()
*/
public HotelOrder post() throws ResponseException {
return post((String) null);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/amadeus/resources/FlightOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class Traveler {

@AllArgsConstructor
@NoArgsConstructor

@ToString
public static class Name {

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/amadeus/resources/Hotel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.amadeus.resources;

import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.ToString;

Expand Down
91 changes: 91 additions & 0 deletions src/main/java/com/amadeus/resources/HotelOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.amadeus.resources;

import com.amadeus.resources.HotelOfferSearch.Offer;
import lombok.Getter;
import lombok.ToString;

/**
* An HotelOrder object as returned by the Hotel Booking v2 API.
* @see com.amadeus.booking.HotelOrders#get()
*/
@ToString
public class HotelOrder extends Resource {
private @Getter String self;
private @Getter String type;
private @Getter String id;
private @Getter HotelBooking[] hotelBookings;
private @Getter AssociatedRecord[] associatedRecords;
private @Getter Guest[] guests;

protected HotelOrder() {}

@ToString
public static class HotelBooking {
private @Getter String type;
private @Getter String id;
private @Getter String bookingStatus;
private @Getter RoomAssociation[] roomAssociations;
private @Getter Offer hotelOffer;
private @Getter Hotel hotel;

protected HotelBooking() {}
}

@ToString
public static class RoomAssociation {
private @Getter String hotelOfferId;
private GuestReference[] guestReferences;
private @Getter String specialRequest;

protected RoomAssociation() {}
}

@ToString
public static class GuestReference {
private @Getter String guestReference;
private @Getter String hotelLoyaltyId;

protected GuestReference() {}
}

@ToString
public static class Guest {
private @Getter int tid;
private @Getter int id;
private @Getter FrequentTraveler[] frequentTraveler;
private @Getter String phone;
private @Getter String email;
private @Getter String title;
private @Getter String firstName;
private @Getter String lastName;
private @Getter Integer childAge;

protected Guest() {}
}

@ToString
public static class FrequentTraveler {
private @Getter String airlineCode;
private @Getter String frequentTravelerId;

protected FrequentTraveler() {}
}

@ToString
public static class AssociatedRecord {
private @Getter String reference;
private @Getter String originSystemCode;

protected AssociatedRecord() {}
}

@ToString
public static class Hotel {
private @Getter String hotelId;
private @Getter String chainCode;
private @Getter String name;
private @Getter String self;

protected Hotel() {}
}
}
17 changes: 17 additions & 0 deletions src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.amadeus.booking.FlightOrder;
import com.amadeus.booking.FlightOrders;
import com.amadeus.booking.HotelBookings;
import com.amadeus.booking.HotelOrders;
import com.amadeus.ereputation.HotelSentiments;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.location.analytics.CategoryRatedAreas;
Expand All @@ -27,6 +28,7 @@
import com.amadeus.referencedata.locations.hotels.ByGeocode;
import com.amadeus.referencedata.locations.hotels.ByHotels;
import com.amadeus.referencedata.urls.CheckinLinks;
import com.amadeus.resources.HotelOrder;
import com.amadeus.resources.TransferCancellation;
import com.amadeus.schedule.Flights;
import com.amadeus.shopping.Activities;
Expand Down Expand Up @@ -95,6 +97,7 @@ public class NamespaceTest {
assertNotNull(client.airport.predictions.onTime);
assertNotNull(client.booking.flightOrder("XXX"));
assertNotNull(client.booking.hotelBookings);
assertNotNull(client.booking.hotelOrders);
assertNotNull(client.schedule.flights);
assertNotNull(client.travel.tripParser);
assertNotNull(client.airport.directDestinations);
Expand Down Expand Up @@ -674,6 +677,20 @@ public void testHotelBookings() throws ResponseException {
assertNotNull(hotel.post(body));
}

@Test
public void testHotelOrders() throws ResponseException {
// Test Trip Parser
Mockito.when(client.post("/v2/booking/hotel-orders", (String) null))
.thenReturn(singleResponse);
Mockito.when(client.post("/v2/booking/hotel-orders", body))
.thenReturn(singleResponse);
Mockito.when(client.post("/v2/booking/hotel-orders", jsonObject))
.thenReturn(singleResponse);
HotelOrders hotelOrder = new HotelOrders(client);
assertNotNull(hotelOrder.post());
assertNotNull(hotelOrder.post(body));
}

@Test
public void testTripParser() throws ResponseException {
// Test Trip Parser
Expand Down
99 changes: 99 additions & 0 deletions src/test/java/com/amadeus/booking/HotelOrdersIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.amadeus.booking;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.amadeus.Amadeus;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.HotelOrder;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

// https://developers.amadeus.com/self-service/category/hotels/api-doc/hotel-booking
public class HotelOrdersIT {

WireMockServer wireMockServer;

private Amadeus amadeus;

/**
* In every tests, we will authenticate.
*/
@BeforeEach
public void setup() {
wireMockServer = new WireMockServer(8080);
wireMockServer.start();

// API at https://developers.amadeus.com/self-service/apis-docs/guides/authorization-262
String address = "/v1/security/oauth2/token"
+ "?grant_type=client_credentials&client_secret=DEMO&client_id=DEMO";
wireMockServer.stubFor(post(urlEqualTo(address))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withStatus(200)
.withBodyFile("auth_ok.json")));

amadeus = Amadeus
.builder("DEMO", "DEMO")
.setHost("localhost")
.setPort(8080)
.setSsl(false)
.setLogLevel("debug")
.build();
}

@AfterEach
public void teardown() {
wireMockServer.stop();
}

@Test
public void given_client_when_call_hotel_orders_with_params_then_ok()
throws ResponseException, IOException {

// Given
String address = "/v2/booking/hotel-orders";

wireMockServer.stubFor(post(urlEqualTo(address))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withStatus(200)
.withBodyFile("hotel_orders_response_ok.json")));


JsonObject request = getRequestFromResources("hotel_orders_request_ok.json");

// When
HotelOrder result = amadeus.booking.hotelOrders.post(request);

// Then
assertNotNull(result);
}

private JsonObject getRequestFromResources(String jsonFile) throws IOException {

final String folder = "__files/";

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(folder + jsonFile).getFile());
String jsonString = new String(Files.readAllBytes(file.toPath()));

return new JsonParser().parse(jsonString).getAsJsonObject();
}

private File getFileRequestFromResources(String jsonFile) throws IOException {

final String folder = "__files/";

ClassLoader classLoader = getClass().getClassLoader();
return new File(classLoader.getResource(folder + jsonFile).getFile());
}

}
Loading
Loading