-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from amadeus4dev/hotel-booking-v2
Add support for Hotel Booking v2
- Loading branch information
Showing
10 changed files
with
459 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
Oops, something went wrong.