diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts
new file mode 100644
index 000000000..d659be059
--- /dev/null
+++ b/examples/build.gradle.kts
@@ -0,0 +1,25 @@
+group = project.property("GROUP_ID") as String
+
+plugins {
+ checkstyle
+}
+
+checkstyle {
+ val archive =
+ configurations.checkstyle.get().resolve().filter {
+ it.name.startsWith("checkstyle")
+ }
+
+ config = resources.text.fromArchiveEntry(archive, "google_checks.xml")
+}
+
+dependencies {
+ api(project(":xap-sdk"))
+
+ implementation("com.expediagroup:expediagroup-sdk-transport-okhttp:0.0.4-alpha")
+
+ implementation("org.apache.logging.log4j:log4j-api:2.24.3")
+ implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.24.3")
+ implementation("com.fasterxml.jackson.core:jackson-databind:2.18.3")
+ implementation("org.apache.commons:commons-lang3:3.17.0")
+}
diff --git a/examples/pom.xml b/examples/pom.xml
deleted file mode 100644
index b6c24c92e..000000000
--- a/examples/pom.xml
+++ /dev/null
@@ -1,125 +0,0 @@
-
-
-
-
- 4.0.0
-
- com.expediagroup
- xap-java-sdk-examples
- 1.0-SNAPSHOT
- XAP Java SDK Examples
- Expedia Group XAP Java SDK Examples
-
-
- 1.8
- 1.8
- 1.8
- UTF-8
- 1.1.0
- 5.0.0
-
-
-
-
- oss.sonatype.org-snapshot
- https://oss.sonatype.org/content/repositories/snapshots
-
- false
-
-
- true
-
-
-
-
-
-
- com.expediagroup
- xap-sdk
- ${xap-java-sdk.sdk.version}
-
-
-
- org.apache.logging.log4j
- log4j-api
- 2.24.3
-
-
-
- org.apache.logging.log4j
- log4j-slf4j2-impl
- 2.24.3
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
- 2.18.3
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 3.6.0
-
- google_checks.xml
- true
- warning
-
-
-
-
- check
-
-
-
-
-
- com.mycila
- license-maven-plugin
- ${maven.licence.plugin.version}
-
-
- 2025
-
-
-
-
-
- **/*.java
-
-
-
-
-
-
- add-license-header
- validate
-
- format
-
-
-
-
-
-
-
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/XapSdkDemoTestRun.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/XapSdkDemoTestRun.java
index bf97539ef..93f07515f 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/XapSdkDemoTestRun.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/XapSdkDemoTestRun.java
@@ -32,60 +32,60 @@
* For reference, see the individual scenarios in the scenarios package.
*/
public class XapSdkDemoTestRun {
- private static final Logger logger = LoggerFactory.getLogger(XapSdkDemoTestRun.class);
+ private static final Logger logger = LoggerFactory.getLogger(XapSdkDemoTestRun.class);
- /**
- * Main method.
- */
- public static void main(String[] args) {
+ /**
+ * Main method.
+ */
+ public static void main(String[] args) {
- logger.info(
- "============================== Running Lodging Scenarios =============================");
+ logger.info(
+ "============================== Running Lodging Scenarios =============================");
- AvailabilityCalendarsQuickStartScenario availabilityCalendarsQuickStartScenario =
- new AvailabilityCalendarsQuickStartScenario();
- availabilityCalendarsQuickStartScenario.run();
+ AvailabilityCalendarsQuickStartScenario availabilityCalendarsQuickStartScenario =
+ new AvailabilityCalendarsQuickStartScenario();
+ availabilityCalendarsQuickStartScenario.run();
- ListingsQuickStartScenario listingsQuickStartScenario = new ListingsQuickStartScenario();
- listingsQuickStartScenario.run();
+ ListingsQuickStartScenario listingsQuickStartScenario = new ListingsQuickStartScenario();
+ listingsQuickStartScenario.run();
- HotelIdsSearchEndToEndScenario hotelIdsSearchEndToEndScenario =
- new HotelIdsSearchEndToEndScenario();
- hotelIdsSearchEndToEndScenario.run();
+ HotelIdsSearchEndToEndScenario hotelIdsSearchEndToEndScenario =
+ new HotelIdsSearchEndToEndScenario();
+ hotelIdsSearchEndToEndScenario.run();
- VrboPropertySearchEndToEndScenario vrboPropertySearchEndToEndScenario =
- new VrboPropertySearchEndToEndScenario();
- vrboPropertySearchEndToEndScenario.run();
+ VrboPropertySearchEndToEndScenario vrboPropertySearchEndToEndScenario =
+ new VrboPropertySearchEndToEndScenario();
+ vrboPropertySearchEndToEndScenario.run();
- logger.info(
- "=============================== End of Lodging Scenarios ==============================");
+ logger.info(
+ "=============================== End of Lodging Scenarios ==============================");
- logger.info(
- "============================== Running Car Scenarios =============================");
- CarListingsQuickStartScenario carListingsQuickStartScenario =
- new CarListingsQuickStartScenario();
+ logger.info(
+ "============================== Running Car Scenarios =============================");
+ CarListingsQuickStartScenario carListingsQuickStartScenario =
+ new CarListingsQuickStartScenario();
- carListingsQuickStartScenario.run();
+ carListingsQuickStartScenario.run();
- CarDetailsQuickStartScenario carDetailsQuickStartScenario = new CarDetailsQuickStartScenario();
- carDetailsQuickStartScenario.run();
- logger.info(
- "=============================== End of Car Scenarios ==============================");
+ CarDetailsQuickStartScenario carDetailsQuickStartScenario = new CarDetailsQuickStartScenario();
+ carDetailsQuickStartScenario.run();
+ logger.info(
+ "=============================== End of Car Scenarios ==============================");
- logger.info(
- "============================== Running Activity Scenarios =============================");
- ActivityListingsQuickStartScenario activityListingsQuickStartScenario =
- new ActivityListingsQuickStartScenario();
+ logger.info(
+ "============================== Running Activity Scenarios =============================");
- activityListingsQuickStartScenario.run();
+ ActivityListingsQuickStartScenario activityListingsQuickStartScenario =
+ new ActivityListingsQuickStartScenario();
- ActivityDetailsQuickStartScenario activityDetailsQuickStartScenario =
- new ActivityDetailsQuickStartScenario();
- activityDetailsQuickStartScenario.run();
- logger.info(
- "=============================== End of Activity Scenarios ==============================");
+ activityListingsQuickStartScenario.run();
+ ActivityDetailsQuickStartScenario activityDetailsQuickStartScenario =
+ new ActivityDetailsQuickStartScenario();
+ activityDetailsQuickStartScenario.run();
+ logger.info(
+ "=============================== End of Activity Scenarios ==============================");
- System.exit(0);
- }
+ System.exit(0);
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/XapScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/XapScenario.java
index 3856f5f7f..9c4248af1 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/XapScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/XapScenario.java
@@ -16,6 +16,7 @@
package com.expediagroup.sdk.xap.examples.scenarios;
+import com.expediagroup.sdk.core.auth.basic.BasicAuthCredentials;
import com.expediagroup.sdk.xap.client.XapClient;
/**
@@ -23,22 +24,27 @@
*/
public interface XapScenario {
- String PARTNER_TRANSACTION_ID = "xap-java-sdk-examples";
-
- void run();
-
- /**
- * Create a client.
- *
- * @return XapClient
- */
- default XapClient createClient() {
- String key = System.getProperty("com.expediagroup.xapjavasdk.apikey");
- String secret = System.getProperty("com.expediagroup.xapjavasdk.apisecret");
- return XapClient
- .builder()
- .key(key)
- .secret(secret)
- .build();
- }
+ String PARTNER_TRANSACTION_ID = "xap-java-sdk-examples";
+
+ void run();
+
+ /**
+ * Create a client.
+ *
+ * @return XapClient
+ */
+ default XapClient createClient() {
+ String key = System.getProperty("com.expediagroup.xapjavasdk.apikey");
+ String secret = System.getProperty("com.expediagroup.xapjavasdk.apisecret");
+
+ BasicAuthCredentials credentials = new BasicAuthCredentials(key, secret);
+
+ // Or enable OAuth by passing OAuthCredentials instead:
+ // OAuthCredentials credentials = new OAuthCredentials("api-key", "api-secret");
+
+ return XapClient
+ .builder()
+ .credentials(credentials)
+ .build();
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityDetailsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityDetailsQuickStartScenario.java
index a526f2909..d7c45b60f 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityDetailsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityDetailsQuickStartScenario.java
@@ -16,7 +16,7 @@
package com.expediagroup.sdk.xap.examples.scenarios.activity;
-import com.expediagroup.sdk.core.model.Response;
+import com.expediagroup.sdk.rest.model.Response;
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
import com.expediagroup.sdk.xap.models.ActivitiesAddress;
@@ -32,6 +32,7 @@
import com.expediagroup.sdk.xap.operations.GetActivityListingsOperationParams;
import java.time.LocalDate;
import java.util.Arrays;
+import java.util.Collections;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,302 +42,302 @@
*/
public class ActivityDetailsQuickStartScenario implements XapScenario {
- private static final Logger LOGGER =
- LoggerFactory.getLogger(ActivityDetailsQuickStartScenario.class);
-
- public static void main(String[] args) {
- new ActivityDetailsQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example demonstrates how to obtain the Activity Details Deep Link from the Activity
- // Listings.
- // For information on using activity search, refer to Activity ListingsQuickStartExample.
- LOGGER.info(
- "========================== Running DetailsQuickStartScenario =========================");
-
- // Execute the operation and get the ActivityListingsRespons
- XapClient xapClient = createClient();
-
- GetActivityListingsOperationParams getActivityListingsOperationParams =
- GetActivityListingsOperationParams.builder()
- .partnerTransactionId(XapScenario.PARTNER_TRANSACTION_ID).location("seattle")
- .links(Arrays.asList(GetActivityListingsOperationParams.Links.AD))
- .startDate(LocalDate.now().plusDays(5)).endDate(LocalDate.now().plusDays(8))
- .locale("en_US").build();
-
- Response listingsResponse =
- xapClient.execute(new GetActivityListingsOperation(getActivityListingsOperationParams));
-
- if (listingsResponse == null || listingsResponse.getData() == null
- || listingsResponse.getData().getActivities() == null) {
- throw new IllegalStateException("No activity details found.");
- }
-
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(ActivityDetailsQuickStartScenario.class);
- Activity listingsActivity = listingsResponse.getData().getActivities().get(0);
+ public static void main(String[] args) {
+ new ActivityDetailsQuickStartScenario().run();
+ System.exit(0);
+ }
- // Get offerToken from APIDetails link url
- String adLink = listingsActivity.getLinks().get("ApiDetails").getHref();
- String offerToken = adLink.substring(adLink.lastIndexOf("/") + 1);
+ @Override
+ public void run() {
+ // This example demonstrates how to obtain the Activity Details Deep Link from the Activity
+ // Listings.
+ // For information on using activity search, refer to Activity ListingsQuickStartExample.
+ LOGGER.info(
+ "========================== Running DetailsQuickStartScenario =========================");
+
+ // Execute the operation and get the ActivityListingsRespons
+ XapClient xapClient = createClient();
+
+ GetActivityListingsOperationParams getActivityListingsOperationParams =
+ GetActivityListingsOperationParams.builder()
+ .partnerTransactionId(XapScenario.PARTNER_TRANSACTION_ID).location("seattle")
+ .links(Collections.singletonList(GetActivityListingsOperationParams.Links.AD))
+ .startDate(LocalDate.now().plusDays(5)).endDate(LocalDate.now().plusDays(8))
+ .locale("en_US").build();
+
+ Response listingsResponse =
+ xapClient.execute(new GetActivityListingsOperation(getActivityListingsOperationParams));
+
+ if (listingsResponse == null || listingsResponse.getData() == null
+ || listingsResponse.getData().getActivities() == null) {
+ throw new IllegalStateException("No activity details found.");
+ }
- // Execute the operation and get the ActivityDetailsResponse
- GetActivityDetailsOperationParams getActivityDetailsOperationParams =
- GetActivityDetailsOperationParams.builder()
- .partnerTransactionId(XapScenario.PARTNER_TRANSACTION_ID).offerToken(offerToken)
- .build();
- Response detalisResponse =
- xapClient.execute(new GetActivityDetailsOperation(getActivityDetailsOperationParams));
+ Activity listingsActivity = listingsResponse.getData().getActivities().get(0);
+ // Get offerToken from APIDetails link url
+ String adLink = listingsActivity.getLinks().get("ApiDetails").getHref();
+ String offerToken = adLink.substring(adLink.lastIndexOf("/") + 1);
- LOGGER.info(
- "======================== GetActivityDetailsOperation Executed ========================");
+ // Execute the operation and get the ActivityDetailsResponse
+ GetActivityDetailsOperationParams getActivityDetailsOperationParams =
+ GetActivityDetailsOperationParams.builder()
+ .partnerTransactionId(XapScenario.PARTNER_TRANSACTION_ID).offerToken(offerToken)
+ .build();
- if (detalisResponse == null || detalisResponse.getData() == null
- || detalisResponse.getData().getActivityDetails() == null
- || detalisResponse.getData().getActivityDetails() == null) {
- throw new IllegalStateException("No activity details found.");
- }
+ Response detalisResponse =
+ xapClient.execute(new GetActivityDetailsOperation(getActivityDetailsOperationParams));
- // The ActivityListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", detalisResponse.getData().getTransactionId());
+ LOGGER.info(
+ "======================== GetActivityDetailsOperation Executed ========================");
- LOGGER.info(
- "============================ Activity details Start ============================");
- Activity activity = detalisResponse.getData().getActivityDetails();
- // To get the activity title
- if (StringUtils.isNotEmpty(activity.getTitle())) {
- LOGGER.info("Activity title: {}", activity.getTitle());
- }
- // To get the activity description
- if (StringUtils.isNotEmpty(activity.getDescription())) {
- LOGGER.info("Activity description: {}", activity.getDescription());
- }
+ if (detalisResponse == null || detalisResponse.getData() == null
+ || detalisResponse.getData().getActivityDetails() == null
+ || detalisResponse.getData().getActivityDetails() == null) {
+ throw new IllegalStateException("No activity details found.");
+ }
- // To get the activity duration
- if (StringUtils.isNotEmpty(activity.getDuration())) {
- LOGGER.info("Activity duration: {}", activity.getDuration());
- }
+ // The ActivityListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", detalisResponse.getData().getTransactionId());
- // To get the activity image
- if (activity.getMedia() != null) {
- LOGGER.info(
- "============================ Activity Images ============================ ");
- activity.getMedia().forEach(image -> {
- LOGGER.info("Image title: {}", image.getTitle());
- LOGGER.info("Image url: {}", image.getUrl());
- });
- LOGGER.info(
- "============================ Activity Images ============================ ");
- }
+ LOGGER.info(
+ "============================ Activity details Start ============================");
+ Activity activity = detalisResponse.getData().getActivityDetails();
+ // To get the activity title
+ if (StringUtils.isNotEmpty(activity.getTitle())) {
+ LOGGER.info("Activity title: {}", activity.getTitle());
+ }
+ // To get the activity description
+ if (StringUtils.isNotEmpty(activity.getDescription())) {
+ LOGGER.info("Activity description: {}", activity.getDescription());
+ }
- // To get the activity free cancellation available
- LOGGER.info("Activity free cancellation available: {}", activity.getFreeCancellation());
+ // To get the activity duration
+ if (StringUtils.isNotEmpty(activity.getDuration())) {
+ LOGGER.info("Activity duration: {}", activity.getDuration());
+ }
- // To get the activity price
- if (activity.getPrice() != null) {
- LOGGER.info("Activity price currency: {}", activity.getPrice().getTotalRate().getCurrency());
- LOGGER.info("Activity price value: {}", activity.getPrice().getTotalRate().getValue());
- }
+ // To get the activity image
+ if (activity.getMedia() != null) {
+ LOGGER.info(
+ "============================ Activity Images ============================ ");
+ activity.getMedia().forEach(image -> {
+ LOGGER.info("Image title: {}", image.getTitle());
+ LOGGER.info("Image url: {}", image.getUrl());
+ });
+ LOGGER.info(
+ "============================ Activity Images ============================ ");
+ }
- // To get the activity redemption
- if (activity.getRedemption() != null) {
- LOGGER.info(
- "============================ Activity Redemption ============================ ");
- if (StringUtils.isNotEmpty(activity.getDuration())) {
- LOGGER.info("Activity Redemption type: {}", activity.getRedemption().getType());
- }
-
- if (activity.getRedemption().getRedemptionLocations() != null) {
- activity.getRedemption().getRedemptionLocations().forEach(location -> {
- printLocation(location);
- });
- }
- LOGGER.info(
- "============================ Activity Redemption ============================ ");
- }
+ // To get the activity free cancellation available
+ LOGGER.info("Activity free cancellation available: {}", activity.getFreeCancellation());
- // To get the activity location
- if (activity.getActivityLocations() != null) {
- activity.getActivityLocations().forEach(location -> {
- printLocation(location);
- });
- }
+ // To get the activity price
+ if (activity.getPrice() != null) {
+ LOGGER.info("Activity price currency: {}", activity.getPrice().getTotalRate().getCurrency());
+ LOGGER.info("Activity price value: {}", activity.getPrice().getTotalRate().getValue());
+ }
- // To get the activity cancellation policy
- printCancellationPolicy(activity.getCancellationPolicy());
+ // To get the activity redemption
+ if (activity.getRedemption() != null) {
+ LOGGER.info(
+ "============================ Activity Redemption ============================ ");
+ if (StringUtils.isNotEmpty(activity.getDuration())) {
+ LOGGER.info("Activity Redemption type: {}", activity.getRedemption().getType());
+ }
- // To get activity highlight
- if (activity.getHighlights() != null) {
- LOGGER.info(
- "============================ Activity Highlight ============================ ");
- activity.getHighlights().forEach(highlight -> {
- LOGGER.info(highlight);
- });
- LOGGER.info(
- "============================ Activity Highlight ============================ ");
- }
+ if (activity.getRedemption().getRedemptionLocations() != null) {
+ activity.getRedemption().getRedemptionLocations().forEach(location -> {
+ printLocation(location);
+ });
+ }
+ LOGGER.info(
+ "============================ Activity Redemption ============================ ");
+ }
- // To get activity inclusions
- if (activity.getInclusions() != null) {
- LOGGER.info(
- "============================ Activity Inclusions ============================ ");
- activity.getInclusions().forEach(inclusion -> {
- LOGGER.info(inclusion);
- });
- LOGGER.info(
- "============================ Activity Inclusions ============================ ");
- }
+ // To get the activity location
+ if (activity.getActivityLocations() != null) {
+ activity.getActivityLocations().forEach(location -> {
+ printLocation(location);
+ });
+ }
- // To get activity exclusion
- if (activity.getExclusions() != null) {
- LOGGER.info(
- "============================ Activity Exclusions ============================ ");
- activity.getExclusions().forEach(exclusion -> {
- LOGGER.info(exclusion);
- });
- LOGGER.info(
- "============================ Activity Exclusions ============================ ");
- }
- // To get activity knowBeforeYouBook
- if (activity.getKnowBeforeYouBook() != null) {
- LOGGER.info(
- "============================ Activity KnowBeforeYouBook ============================ ");
- activity.getKnowBeforeYouBook().forEach(knowBeforeYouBook -> {
- LOGGER.info(knowBeforeYouBook);
- });
- LOGGER.info(
- "============================ Activity KnowBeforeYouBook ============================ ");
- }
+ // To get the activity cancellation policy
+ printCancellationPolicy(activity.getCancellationPolicy());
- // To get activity offers
- if (activity.getOffers() != null) {
- LOGGER.info(
- "============================ Activity Offers ============================ ");
- activity.getOffers().forEach(offer -> {
- // To get the Offer title
- if (StringUtils.isNotEmpty(offer.getTitle())) {
- LOGGER.info("Offer title: {}", offer.getTitle());
+ // To get activity highlight
+ if (activity.getHighlights() != null) {
+ LOGGER.info(
+ "============================ Activity Highlight ============================ ");
+ activity.getHighlights().forEach(highlight -> {
+ LOGGER.info(highlight);
+ });
+ LOGGER.info(
+ "============================ Activity Highlight ============================ ");
}
- // To get the Offer description
- if (StringUtils.isNotEmpty(offer.getDescription())) {
- LOGGER.info("Offer description: {}", offer.getDescription());
+
+ // To get activity inclusions
+ if (activity.getInclusions() != null) {
+ LOGGER.info(
+ "============================ Activity Inclusions ============================ ");
+ activity.getInclusions().forEach(inclusion -> {
+ LOGGER.info(inclusion);
+ });
+ LOGGER.info(
+ "============================ Activity Inclusions ============================ ");
}
- // To get the Offer duration
- if (StringUtils.isNotEmpty(offer.getDuration())) {
- LOGGER.info("Offer duration: {}", offer.getDuration());
+ // To get activity exclusion
+ if (activity.getExclusions() != null) {
+ LOGGER.info(
+ "============================ Activity Exclusions ============================ ");
+ activity.getExclusions().forEach(exclusion -> {
+ LOGGER.info(exclusion);
+ });
+ LOGGER.info(
+ "============================ Activity Exclusions ============================ ");
}
- // To get the offer price
- if (offer.getOfferPrice() != null) {
- LOGGER.info("Offer price currency: {}",
- offer.getOfferPrice().getTotalRate().getCurrency());
- LOGGER.info("Offer price value: {}", offer.getOfferPrice().getTotalRate().getValue());
+ // To get activity knowBeforeYouBook
+ if (activity.getKnowBeforeYouBook() != null) {
+ LOGGER.info(
+ "============================ Activity KnowBeforeYouBook ============================ ");
+ activity.getKnowBeforeYouBook().forEach(knowBeforeYouBook -> {
+ LOGGER.info(knowBeforeYouBook);
+ });
+ LOGGER.info(
+ "============================ Activity KnowBeforeYouBook ============================ ");
}
- // To get the Offer availableTimeSlots
- if (offer.getAvailableTimeSlots() != null) {
- LOGGER.info(
- "========================= Activity AvailableTimeSlots =========================");
-
- offer.getAvailableTimeSlots().forEach(availableTimeSlot -> {
- LOGGER.info("DateTime: {}", availableTimeSlot.getDateTime());
- LOGGER.info("AllDayActivity: {}", availableTimeSlot.getAllDayActivity());
- printCancellationPolicy(availableTimeSlot.getCancellationPolicy());
-
- // To get ticket info
- if (availableTimeSlot.getTickets() != null) {
- LOGGER.info(
- "============================ Activity ticket ============================= ");
- availableTimeSlot.getTickets().forEach(ticket -> {
- LOGGER.info("Code: {}", ticket.getCode());
- LOGGER.info("Ticket price currency: {}",
- ticket.getTicketPrice().getTotalRate().getCurrency());
- LOGGER.info("Ticket price value: {}",
- ticket.getTicketPrice().getTotalRate().getValue());
-
- });
- LOGGER.info(
- "============================ Activity ticket ============================ ");
- }
+ // To get activity offers
+ if (activity.getOffers() != null) {
+ LOGGER.info(
+ "============================ Activity Offers ============================ ");
+ activity.getOffers().forEach(offer -> {
+ // To get the Offer title
+ if (StringUtils.isNotEmpty(offer.getTitle())) {
+ LOGGER.info("Offer title: {}", offer.getTitle());
+ }
+ // To get the Offer description
+ if (StringUtils.isNotEmpty(offer.getDescription())) {
+ LOGGER.info("Offer description: {}", offer.getDescription());
+ }
+
+ // To get the Offer duration
+ if (StringUtils.isNotEmpty(offer.getDuration())) {
+ LOGGER.info("Offer duration: {}", offer.getDuration());
+ }
+
+ // To get the offer price
+ if (offer.getOfferPrice() != null) {
+ LOGGER.info("Offer price currency: {}",
+ offer.getOfferPrice().getTotalRate().getCurrency());
+ LOGGER.info("Offer price value: {}", offer.getOfferPrice().getTotalRate().getValue());
+ }
+
+ // To get the Offer availableTimeSlots
+ if (offer.getAvailableTimeSlots() != null) {
+ LOGGER.info(
+ "========================= Activity AvailableTimeSlots =========================");
+
+ offer.getAvailableTimeSlots().forEach(availableTimeSlot -> {
+ LOGGER.info("DateTime: {}", availableTimeSlot.getDateTime());
+ LOGGER.info("AllDayActivity: {}", availableTimeSlot.getAllDayActivity());
+ printCancellationPolicy(availableTimeSlot.getCancellationPolicy());
+
+ // To get ticket info
+ if (availableTimeSlot.getTickets() != null) {
+ LOGGER.info(
+ "============================ Activity ticket ============================= ");
+ availableTimeSlot.getTickets().forEach(ticket -> {
+ LOGGER.info("Code: {}", ticket.getCode());
+ LOGGER.info("Ticket price currency: {}",
+ ticket.getTicketPrice().getTotalRate().getCurrency());
+ LOGGER.info("Ticket price value: {}",
+ ticket.getTicketPrice().getTotalRate().getValue());
+
+ });
+ LOGGER.info(
+ "============================ Activity ticket ============================ ");
+ }
+
+ });
+
+ LOGGER.info(
+ "======================== Activity AvailableTimeSlots ===========================");
+ }
+ });
+ LOGGER.info(
+ "============================ Activity Offers ============================ ");
+ }
- });
+ LOGGER.info(
+ "============================= Activity End =============================");
- LOGGER.info(
- "======================== Activity AvailableTimeSlots ===========================");
- }
- });
- LOGGER.info(
- "============================ Activity Offers ============================ ");
+ LOGGER.info(
+ "============================ End ListingsQuickStartScenario ===========================");
}
- LOGGER.info(
- "============================= Activity End =============================");
+ private void printCancellationPolicy(ActivitiesCancellationPolicy cancellationPolicy) {
+ if (cancellationPolicy != null) {
+ LOGGER.info("Activity free cancellation available: {}",
+ cancellationPolicy.getFreeCancellation());
- LOGGER.info(
- "============================ End ListingsQuickStartScenario ===========================");
- }
+ LOGGER.info("FreeCancellationMinHours: {}", cancellationPolicy.getFreeCancellationMinHours());
+ LOGGER.info("FreeCancellationEndDateTime: {}",
+ cancellationPolicy.getFreeCancellationEndDateTime());
+ LOGGER.info("CancelPolicyDescription: {}", cancellationPolicy.getCancelPolicyDescription());
- private void printCancellationPolicy(ActivitiesCancellationPolicy cancellationPolicy) {
- if (cancellationPolicy != null) {
- LOGGER.info("Activity free cancellation available: {}",
- cancellationPolicy.getFreeCancellation());
+ }
+ }
- LOGGER.info("FreeCancellationMinHours: {}", cancellationPolicy.getFreeCancellationMinHours());
- LOGGER.info("FreeCancellationEndDateTime: {}",
- cancellationPolicy.getFreeCancellationEndDateTime());
- LOGGER.info("CancelPolicyDescription: {}", cancellationPolicy.getCancelPolicyDescription());
+ private void printLocation(ActivitiesLocation location) {
+ if (location != null) {
+ if (location.getAddress() != null) {
+ ActivitiesAddress address = location.getAddress();
+ if (StringUtils.isNotEmpty(address.getCountry())) {
+ LOGGER.info("Country: {}", address.getCountry());
+ }
- }
- }
-
- private void printLocation(ActivitiesLocation location) {
- if (location != null) {
- if (location.getAddress() != null) {
- ActivitiesAddress address = location.getAddress();
- if (StringUtils.isNotEmpty(address.getCountry())) {
- LOGGER.info("Country: {}", address.getCountry());
- }
+ if (StringUtils.isNotEmpty(address.getProvince())) {
+ LOGGER.info("Province: {}", address.getProvince());
+ }
- if (StringUtils.isNotEmpty(address.getProvince())) {
- LOGGER.info("Province: {}", address.getProvince());
- }
+ if (StringUtils.isNotEmpty(address.getCity())) {
+ LOGGER.info("City: {}", address.getCity());
+ }
- if (StringUtils.isNotEmpty(address.getCity())) {
- LOGGER.info("City: {}", address.getCity());
- }
+ if (StringUtils.isNotEmpty(address.getAddress1())) {
+ LOGGER.info("Address1: {}", address.getAddress1());
+ }
- if (StringUtils.isNotEmpty(address.getAddress1())) {
- LOGGER.info("Address1: {}", address.getAddress1());
- }
+ if (StringUtils.isNotEmpty(address.getAddress2())) {
+ LOGGER.info("Address2: {}", address.getAddress2());
+ }
- if (StringUtils.isNotEmpty(address.getAddress2())) {
- LOGGER.info("Address2: {}", address.getAddress2());
- }
+ }
- }
+ if (location.getGeoLocation() != null) {
+ ActivitiesGeoLocation geoLocation = location.getGeoLocation();
+ if (StringUtils.isNotEmpty(geoLocation.getLatitude())) {
+ LOGGER.info("Latitude: {}", geoLocation.getLatitude());
+ }
- if (location.getGeoLocation() != null) {
- ActivitiesGeoLocation geoLocation = location.getGeoLocation();
- if (StringUtils.isNotEmpty(geoLocation.getLatitude())) {
- LOGGER.info("Latitude: {}", geoLocation.getLatitude());
- }
+ if (StringUtils.isNotEmpty(geoLocation.getLongitude())) {
+ LOGGER.info("Longitude: {}", geoLocation.getLongitude());
+ }
+ }
- if (StringUtils.isNotEmpty(geoLocation.getLongitude())) {
- LOGGER.info("Longitude: {}", geoLocation.getLongitude());
}
- }
}
-
- }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityListingsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityListingsQuickStartScenario.java
index c6f668730..68f3c8a53 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityListingsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/activity/ActivityListingsQuickStartScenario.java
@@ -32,123 +32,122 @@
*/
public class ActivityListingsQuickStartScenario implements XapScenario {
- private static final Logger LOGGER =
- LoggerFactory.getLogger(ActivityListingsQuickStartScenario.class);
-
- public static void main(String[] args) {
- new ActivityListingsQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example will search for activities with the following criteria:
- // 1. Activities located in Seattle;
- // 2. Start date 5 days from now, end date 8 days from now;
- // 3. Return Expedia Web details and api details links.
- LOGGER.info(
- "========================== Running ListingsQuickStartScenario =========================");
-
- LOGGER.info(
- "======================== Executing GetActivityListingsOperation =======================");
-
-
-
- // Build the query parameters with GetActivityListingsOperationParams
- GetActivityListingsOperationParams getActivityListingsOperationParams =
- GetActivityListingsOperationParams.builder()
- .partnerTransactionId(XapScenario.PARTNER_TRANSACTION_ID).location("seattle")
- .links(Arrays.asList(GetActivityListingsOperationParams.Links.WD,
- GetActivityListingsOperationParams.Links.AD))
- .startDate(LocalDate.now().plusDays(5)).endDate(LocalDate.now().plusDays(8)).build();
-
- XapClient xapClient = createClient();
-
- // Execute the operation and get the HotelListingsResponse
- ActivityListingsResponse activityListingsResponse = xapClient
- .execute(new GetActivityListingsOperation(getActivityListingsOperationParams)).getData();
-
- // If you want to use the async method, you can use the following code:
- // ---------------------------------------------------------------
- // CompletableFuture> completableFuture =
- // xapClient.executeAsync(
- // new GetActivityListingsOperation(getActivityListingsOperationParams));
- // completableFuture.thenAccept(activityListingsResponse -> {
- // // Your code here
- // });
- // ---------------------------------------------------------------
-
- LOGGER.info(
- "======================== GetActivityListingsOperation Executed ========================");
-
- if (activityListingsResponse == null || activityListingsResponse.getActivities() == null
- || activityListingsResponse.getActivities().isEmpty()) {
- throw new IllegalStateException("No activities found.");
- }
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(ActivityListingsQuickStartScenario.class);
- // The ActivityListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", activityListingsResponse.getTransactionId());
-
- // To access the activities, iterate through the list of activity properties
- activityListingsResponse.getActivities().forEach(activity -> {
- LOGGER.info(
- "=================================== Activity Start ===================================");
- // To get the activity title
- if (StringUtils.isNotEmpty(activity.getTitle())) {
- LOGGER.info("Activity title: {}", activity.getTitle());
- }
- // To get the activity description
- if (StringUtils.isNotEmpty(activity.getDescription())) {
- LOGGER.info("Activity description: {}", activity.getDescription());
- }
-
- // To get the activity duration
- if (StringUtils.isNotEmpty(activity.getDuration())) {
- LOGGER.info("Activity duration: {}", activity.getDuration());
- }
-
-
- // To get the activity image
- if (activity.getMedia() != null) {
- LOGGER.info("Activity image: {}", activity.getMedia().get(0).getUrl());
- }
-
- // To get the activity review count
- if (activity.getReviewCount() != null) {
- LOGGER.info("Activity review count: {}", activity.getReviewCount());
- }
-
- // To get the activity review score
- if (activity.getReviewScore() != null) {
- LOGGER.info("Activity review score: {}", activity.getReviewScore());
- }
-
- // To get the activity free cancellation available
- LOGGER.info("Activity free cancellation available: {}", activity.getFreeCancellation());
-
- // To get the activity price
- if (activity.getPrice() != null) {
- LOGGER.info("Activity price currency: {}",
- activity.getPrice().getTotalRate().getCurrency());
- LOGGER.info("Activity price value: {}", activity.getPrice().getTotalRate().getValue());
- }
-
- // Get the API details link and web details link from the links collection.
- if (!activity.getLinks().isEmpty()) {
- if (activity.getLinks().get("ApiDetails") != null) {
- LOGGER.info("ApiDetails Link: {}", activity.getLinks().get("ApiDetails"));
- }
+ public static void main(String[] args) {
+ new ActivityListingsQuickStartScenario().run();
+ System.exit(0);
+ }
- if (activity.getLinks().get("WebDetails") != null) {
- LOGGER.info("WebDetails Link: {}", activity.getLinks().get("WebDetails"));
+ @Override
+ public void run() {
+ // This example will search for activities with the following criteria:
+ // 1. Activities located in Seattle;
+ // 2. Start date 5 days from now, end date 8 days from now;
+ // 3. Return Expedia Web details and api details links.
+ LOGGER.info(
+ "========================== Running ListingsQuickStartScenario =========================");
+
+ LOGGER.info(
+ "======================== Executing GetActivityListingsOperation =======================");
+
+
+ // Build the query parameters with GetActivityListingsOperationParams
+ GetActivityListingsOperationParams getActivityListingsOperationParams =
+ GetActivityListingsOperationParams.builder()
+ .partnerTransactionId(XapScenario.PARTNER_TRANSACTION_ID).location("seattle")
+ .links(Arrays.asList(GetActivityListingsOperationParams.Links.WD,
+ GetActivityListingsOperationParams.Links.AD))
+ .startDate(LocalDate.now().plusDays(5)).endDate(LocalDate.now().plusDays(8)).build();
+
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the HotelListingsResponse
+ ActivityListingsResponse activityListingsResponse = xapClient
+ .execute(new GetActivityListingsOperation(getActivityListingsOperationParams)).getData();
+
+ // If you want to use the async method, you can use the following code:
+ // ---------------------------------------------------------------
+ // CompletableFuture> completableFuture =
+ // xapClient.executeAsync(
+ // new GetActivityListingsOperation(getActivityListingsOperationParams));
+ // completableFuture.thenAccept(activityListingsResponse -> {
+ // // Your code here
+ // });
+ // ---------------------------------------------------------------
+
+ LOGGER.info(
+ "======================== GetActivityListingsOperation Executed ========================");
+
+ if (activityListingsResponse == null || activityListingsResponse.getActivities() == null
+ || activityListingsResponse.getActivities().isEmpty()) {
+ throw new IllegalStateException("No activities found.");
}
- }
- LOGGER.info(
- "==================================== Activity End ====================================");
- });
-
- LOGGER.info(
- "============================ End ListingsQuickStartScenario ===========================");
- }
+ // The ActivityListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", activityListingsResponse.getTransactionId());
+
+ // To access the activities, iterate through the list of activity properties
+ activityListingsResponse.getActivities().forEach(activity -> {
+ LOGGER.info(
+ "=================================== Activity Start ===================================");
+ // To get the activity title
+ if (StringUtils.isNotEmpty(activity.getTitle())) {
+ LOGGER.info("Activity title: {}", activity.getTitle());
+ }
+ // To get the activity description
+ if (StringUtils.isNotEmpty(activity.getDescription())) {
+ LOGGER.info("Activity description: {}", activity.getDescription());
+ }
+
+ // To get the activity duration
+ if (StringUtils.isNotEmpty(activity.getDuration())) {
+ LOGGER.info("Activity duration: {}", activity.getDuration());
+ }
+
+
+ // To get the activity image
+ if (activity.getMedia() != null) {
+ LOGGER.info("Activity image: {}", activity.getMedia().get(0).getUrl());
+ }
+
+ // To get the activity review count
+ if (activity.getReviewCount() != null) {
+ LOGGER.info("Activity review count: {}", activity.getReviewCount());
+ }
+
+ // To get the activity review score
+ if (activity.getReviewScore() != null) {
+ LOGGER.info("Activity review score: {}", activity.getReviewScore());
+ }
+
+ // To get the activity free cancellation available
+ LOGGER.info("Activity free cancellation available: {}", activity.getFreeCancellation());
+
+ // To get the activity price
+ if (activity.getPrice() != null) {
+ LOGGER.info("Activity price currency: {}",
+ activity.getPrice().getTotalRate().getCurrency());
+ LOGGER.info("Activity price value: {}", activity.getPrice().getTotalRate().getValue());
+ }
+
+ // Get the API details link and web details link from the links collection.
+ if (!activity.getLinks().isEmpty()) {
+ if (activity.getLinks().get("ApiDetails") != null) {
+ LOGGER.info("ApiDetails Link: {}", activity.getLinks().get("ApiDetails"));
+ }
+
+ if (activity.getLinks().get("WebDetails") != null) {
+ LOGGER.info("WebDetails Link: {}", activity.getLinks().get("WebDetails"));
+ }
+ }
+
+ LOGGER.info(
+ "==================================== Activity End ====================================");
+ });
+
+ LOGGER.info(
+ "============================ End ListingsQuickStartScenario ===========================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarDetailsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarDetailsQuickStartScenario.java
index e96ceda05..385f33e2e 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarDetailsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarDetailsQuickStartScenario.java
@@ -16,7 +16,7 @@
package com.expediagroup.sdk.xap.examples.scenarios.car;
-import com.expediagroup.sdk.core.model.Response;
+import com.expediagroup.sdk.rest.model.Response;
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
import com.expediagroup.sdk.xap.models.CarDetails;
@@ -40,225 +40,239 @@
*/
public class CarDetailsQuickStartScenario implements XapScenario {
- private static final Logger LOGGER = LoggerFactory.getLogger(CarDetailsQuickStartScenario.class);
-
- /**
- * Summary: main function.
- */
- public static void main(String[] args) {
- new CarListingsQuickStartScenario().run();
- new CarDetailsQuickStartScenario().run();
- System.exit(0);
- }
-
- /**
- * Summary: split URL into components.
- */
- public static String[] splitUrl(String url) {
- String[] parts = url.split("\\?");
- String base = parts[0];
- String query = parts[1];
-
- String offerToken = base.substring(base.lastIndexOf("/") + 1);
- String[] queryParams = query.split("&");
- String price = queryParams[0].split("=")[1];
- String currency = queryParams[1].split("=")[1];
-
- return new String[] {offerToken, price, currency};
- }
-
- @Override
- public void run() {
- LOGGER.info("========== Start QuickStartScenario ==========");
-
- LOGGER.info("========== Car Listing Start ==========");
-
- // This example demonstrates how to obtain the Car Details Deep Link from the CarListing.
- // For information on using car search, refer to
- // car/shopping/listings/ListingsQuickStartExample.
- List linksList = new ArrayList<>();
- linksList.add(GetCarsListingsOperationParams.Links.AD);
- linksList.add(GetCarsListingsOperationParams.Links.WS);
- linksList.add(GetCarsListingsOperationParams.Links.WD);
- GetCarsListingsOperationParams getCarsListingsOperationParams =
- GetCarsListingsOperationParams.builder()
- .partnerTransactionId("EWSCar_Automation")
- .dropOffAirport("MCO")
- .pickupAirport("MCO")
- .pickupTime(LocalDateTime.now().plusDays(5))
- .dropOffTime(LocalDateTime.now().plusDays(8))
- .limit(1)
- .links(linksList)
- .build();
-
- XapClient xapClient = createClient();
- GetCarsListingsOperation getCarsListingsOperation =
- new GetCarsListingsOperation(getCarsListingsOperationParams);
- Response carListingsResponse = xapClient.execute(getCarsListingsOperation);
-
- LOGGER.info("========== Car Listing Property End ==========");
-
- // Iterate through the car listings and retrieve the Car Details Deep Link.
- LOGGER.info("========== Car Details Start ==========");
- Objects.requireNonNull(carListingsResponse.getData().getCars()).forEach(car -> {
- if (!car.getLinks().get("ApiDetails").getHref().isEmpty()) {
- // Retrieve the Car Details Deep Link from the car listing.
- LOGGER.info("Car Details Deep Link: " + car.getLinks().get("ApiDetails").getHref());
- String[] strings = splitUrl(car.getLinks().get("ApiDetails").getHref());
-
- // Retrieve the Car Details information using the Car Details Deep Link, which
- // includes (offerToken, price, currency)
- GetCarDetailsOperationParams getCarDetailsOperationParams =
- GetCarDetailsOperationParams.builder().partnerTransactionId("EWSCar_Automation")
- .offerToken(strings[0]).price(strings[1]).currency(strings[2]).build();
-
- // Execute the operation and get the CarDetailsResponse
- LOGGER.info("========== Executing GetCarDetailsOperation ==========");
- CarDetailsResponse carDetailsResponse = xapClient.execute(
- new GetCarDetailsOperation(getCarDetailsOperationParams)).getData();
- LOGGER.info("========== GetCarDetailsOperation Executed ==========");
-
- if (carDetailsResponse == null || carDetailsResponse.getLinks() == null) {
- throw new IllegalStateException("No car found.");
- }
-
- LOGGER.info("========== Car Properties Start ==========");
-
- // The CarDetailsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", carDetailsResponse.getTransactionId());
-
- // List Container for warning messages
- if (carDetailsResponse.getWarnings() != null) {
- LOGGER.info("Warnings: {}", carDetailsResponse.getWarnings());
- }
-
- // Details of requested car.
- // Details refer to the CarDetails Section table below.
- if (carDetailsResponse.getValidFormsOfPayment() != null) {
- LOGGER.info("Valid Forms Of Payment: {}", carDetailsResponse.getValidFormsOfPayment());
- }
-
- // A map of links to other Car APIs.
- if (carDetailsResponse.getLinks() != null) {
- LOGGER.info("Links: {}", carDetailsResponse.getLinks());
- }
-
- // Specific information for a car.
- CarDetails carDetails = carDetailsResponse.getCarDetails();
- VehicleDetails vehicleDetails = carDetails.getVehicleDetails();
- if (vehicleDetails.getMake() != null) {
- //Car manufacturer and model.
- LOGGER.info("Make: {}", vehicleDetails.getMake());
- }
-
- // Car category and type.
- LOGGER.info("Car Class: {}", vehicleDetails.getCarClass());
-
- // Minimal car door count.
- if (vehicleDetails.getMinDoors() != null) {
- LOGGER.info("Min Doors: {}", vehicleDetails.getMinDoors());
- }
-
- // Maximum car door count.
- if (vehicleDetails.getMaxDoors() != null) {
- LOGGER.info("Max Doors: {}", vehicleDetails.getMaxDoors());
- }
-
- // Car fuel information.
- if (vehicleDetails.getFuelLevel() != null) {
- // Fuel level of the car.
- LOGGER.info("Fuel Level: {}", vehicleDetails.getFuelLevel());
- }
-
- // Car category.
- LOGGER.info("Car Category: {}", vehicleDetails.getCarCategory());
-
- // Car type.
- LOGGER.info("Car Type: {}", vehicleDetails.getCarType());
-
- // Car transmission and drive.
- LOGGER.info("Transmission Drive: {}", vehicleDetails.getTransmissionDrive());
-
- // Car fuel type and whether Air Conditioning is included.
- LOGGER.info("Fuel AC: {}", vehicleDetails.getFuelAC());
-
- // Capacity for car's properties, which include AdultCount, ChildCount, SmallLuggageCount
- // and LargeLuggageCount.
- if (vehicleDetails.getCapacity() != null) {
- LOGGER.info("Capacity: {}", vehicleDetails.getCapacity());
- }
-
- // Car rental supplier.
- LOGGER.info(" : {}", carDetails.getSupplier());
-
- // Pickup information
- LOGGER.info("Pickup Details: {}", carDetails.getPickupDetails());
-
- // Drop off information, include drop off date time and drop off location information.
- LOGGER.info("Drop Off Details: {}", carDetails.getDropOffDetails());
-
- // The rate information for a car product.
- LOGGER.info("Rate Details: {}", carDetails.getRateDetails());
-
- // Base price per rate period.
- LOGGER.info("Price: {}", carDetails.getPrice());
-
- // List of TaxesAndFees Details.
- if (carDetails.getTaxesAndFeesDetails() != null) {
- LOGGER.info("Taxes And Fees Details: {}", carDetails.getTaxesAndFeesDetails());
- }
-
- // List of ExtraFeesDetails
- if (carDetails.getExtraFeesDetails() != null) {
- LOGGER.info("Extra Fees Details: {}", carDetails.getExtraFeesDetails());
- }
-
- // ReferencePrice is the totalPrice for the comparable standalone car, when there is
- // a discounted car or need to show strike through pricing.
- if (carDetails.getReferencePrice() != null) {
- LOGGER.info("Reference Price: {}", carDetails.getReferencePrice());
- }
-
- // List of additional fees including both mandatory and optional fees such as young driver
- // fee/drop off fee /CollisionDamageWaiver.
- if (carDetails.getAdditionalFees() != null) {
- LOGGER.info("Additional Fees: {}", carDetails.getAdditionalFees());
- }
-
- // Description and costs of any optional special equipment that may be rented with the car.
- if (carDetails.getSpecialEquipments() != null) {
- LOGGER.info("Special Equipments: {}", carDetails.getSpecialEquipments());
- }
-
- // Limitations that are part of this rental agreement.
- if (carDetails.getRentalLimits() != null) {
- LOGGER.info("Rental Limits: {}", carDetails.getRentalLimits());
- }
-
- // Cancellation Policy Container.
- LOGGER.info("Cancellation Policy: {}", carDetails.getCancellationPolicy());
-
- // Container for no show penalty
- if (carDetails.getNoShowPenalty() != null) {
- LOGGER.info("No Show Penalty: {}", carDetails.getNoShowPenalty());
- }
-
- // A list of policies that apply to this car rental.
- if (carDetails.getCarPolicies() != null) {
- LOGGER.info("Policies: {}", carDetails.getCarPolicies());
- }
-
- // List of image resources of the car product.
- if (carDetails.getImages() != null) {
- LOGGER.info("Images: {}", carDetails.getImages());
- }
-
- LOGGER.info("========== Property End ==========");
- }
-
- });
+ private static final Logger LOGGER = LoggerFactory.getLogger(CarDetailsQuickStartScenario.class);
+
+ /**
+ * Summary: main function.
+ */
+ public static void main(String[] args) {
+ new CarListingsQuickStartScenario().run();
+ new CarDetailsQuickStartScenario().run();
+ System.exit(0);
+ }
+
+ /**
+ * Summary: split URL into components.
+ */
+ public static String[] splitUrl(String url) {
+ String[] parts = url.split("\\?");
+ String base = parts[0];
+ String query = parts[1];
+
+ String offerToken = base.substring(base.lastIndexOf("/") + 1);
+ String[] queryParams = query.split("&");
+ String price = queryParams[0].split("=")[1];
+ String currency = queryParams[1].split("=")[1];
+
+ return new String[]{offerToken, price, currency};
+ }
+
+ @Override
+ public void run() {
+ LOGGER.info("========== Start QuickStartScenario ==========");
+
+ LOGGER.info("========== Car Listing Start ==========");
+
+ // This example demonstrates how to obtain the Car Details Deep Link from the CarListing.
+ // For information on using car search, refer to
+ // car/shopping/listings/ListingsQuickStartExample.
+ List linksList = new ArrayList<>();
+ linksList.add(GetCarsListingsOperationParams.Links.AD);
+ linksList.add(GetCarsListingsOperationParams.Links.WS);
+ linksList.add(GetCarsListingsOperationParams.Links.WD);
+ GetCarsListingsOperationParams getCarsListingsOperationParams =
+ GetCarsListingsOperationParams.builder()
+ .partnerTransactionId("EWSCar_Automation")
+ .dropOffAirport("MCO")
+ .pickupAirport("MCO")
+ .pickupTime(
+ LocalDateTime.now()
+ .withNano(0)
+ .withSecond(0)
+ .withHour(10)
+ .plusDays(10)
+ .plusMonths(1)
+ )
+ .dropOffTime(
+ LocalDateTime.now()
+ .withNano(0)
+ .withSecond(0)
+ .withHour(10)
+ .plusDays(15)
+ .plusMonths(1)
+ )
+ .limit(1)
+ .links(linksList)
+ .build();
+
+ XapClient xapClient = createClient();
+ GetCarsListingsOperation getCarsListingsOperation =
+ new GetCarsListingsOperation(getCarsListingsOperationParams);
+ Response carListingsResponse = xapClient.execute(getCarsListingsOperation);
+
+ LOGGER.info("========== Car Listing Property End ==========");
+
+ // Iterate through the car listings and retrieve the Car Details Deep Link.
+ LOGGER.info("========== Car Details Start ==========");
+ Objects.requireNonNull(carListingsResponse.getData().getCars()).forEach(car -> {
+ if (!car.getLinks().get("ApiDetails").getHref().isEmpty()) {
+ // Retrieve the Car Details Deep Link from the car listing.
+ LOGGER.info("Car Details Deep Link: " + car.getLinks().get("ApiDetails").getHref());
+ String[] strings = splitUrl(car.getLinks().get("ApiDetails").getHref());
+
+ // Retrieve the Car Details information using the Car Details Deep Link, which
+ // includes (offerToken, price, currency)
+ GetCarDetailsOperationParams getCarDetailsOperationParams =
+ GetCarDetailsOperationParams.builder().partnerTransactionId("EWSCar_Automation")
+ .offerToken(strings[0]).price(strings[1]).currency(strings[2]).build();
+
+ // Execute the operation and get the CarDetailsResponse
+ LOGGER.info("========== Executing GetCarDetailsOperation ==========");
+ CarDetailsResponse carDetailsResponse = xapClient.execute(
+ new GetCarDetailsOperation(getCarDetailsOperationParams)).getData();
+ LOGGER.info("========== GetCarDetailsOperation Executed ==========");
+
+ if (carDetailsResponse == null || carDetailsResponse.getLinks() == null) {
+ throw new IllegalStateException("No car found.");
+ }
+
+ LOGGER.info("========== Car Properties Start ==========");
+
+ // The CarDetailsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", carDetailsResponse.getTransactionId());
+
+ // List Container for warning messages
+ if (carDetailsResponse.getWarnings() != null) {
+ LOGGER.info("Warnings: {}", carDetailsResponse.getWarnings());
+ }
+
+ // Details of requested car.
+ // Details refer to the CarDetails Section table below.
+ if (carDetailsResponse.getValidFormsOfPayment() != null) {
+ LOGGER.info("Valid Forms Of Payment: {}", carDetailsResponse.getValidFormsOfPayment());
+ }
+
+ // A map of links to other Car APIs.
+ if (carDetailsResponse.getLinks() != null) {
+ LOGGER.info("Links: {}", carDetailsResponse.getLinks());
+ }
+
+ // Specific information for a car.
+ CarDetails carDetails = carDetailsResponse.getCarDetails();
+ VehicleDetails vehicleDetails = carDetails.getVehicleDetails();
+ if (vehicleDetails.getMake() != null) {
+ //Car manufacturer and model.
+ LOGGER.info("Make: {}", vehicleDetails.getMake());
+ }
+
+ // Car category and type.
+ LOGGER.info("Car Class: {}", vehicleDetails.getCarClass());
+
+ // Minimal car door count.
+ if (vehicleDetails.getMinDoors() != null) {
+ LOGGER.info("Min Doors: {}", vehicleDetails.getMinDoors());
+ }
+
+ // Maximum car door count.
+ if (vehicleDetails.getMaxDoors() != null) {
+ LOGGER.info("Max Doors: {}", vehicleDetails.getMaxDoors());
+ }
+
+ // Car fuel information.
+ if (vehicleDetails.getFuelLevel() != null) {
+ // Fuel level of the car.
+ LOGGER.info("Fuel Level: {}", vehicleDetails.getFuelLevel());
+ }
+
+ // Car category.
+ LOGGER.info("Car Category: {}", vehicleDetails.getCarCategory());
+
+ // Car type.
+ LOGGER.info("Car Type: {}", vehicleDetails.getCarType());
+
+ // Car transmission and drive.
+ LOGGER.info("Transmission Drive: {}", vehicleDetails.getTransmissionDrive());
+
+ // Car fuel type and whether Air Conditioning is included.
+ LOGGER.info("Fuel AC: {}", vehicleDetails.getFuelAC());
+
+ // Capacity for car's properties, which include AdultCount, ChildCount, SmallLuggageCount
+ // and LargeLuggageCount.
+ if (vehicleDetails.getCapacity() != null) {
+ LOGGER.info("Capacity: {}", vehicleDetails.getCapacity());
+ }
+
+ // Car rental supplier.
+ LOGGER.info(" : {}", carDetails.getSupplier());
+
+ // Pickup information
+ LOGGER.info("Pickup Details: {}", carDetails.getPickupDetails());
+
+ // Drop off information, include drop off date time and drop off location information.
+ LOGGER.info("Drop Off Details: {}", carDetails.getDropOffDetails());
+
+ // The rate information for a car product.
+ LOGGER.info("Rate Details: {}", carDetails.getRateDetails());
+
+ // Base price per rate period.
+ LOGGER.info("Price: {}", carDetails.getPrice());
+
+ // List of TaxesAndFees Details.
+ if (carDetails.getTaxesAndFeesDetails() != null) {
+ LOGGER.info("Taxes And Fees Details: {}", carDetails.getTaxesAndFeesDetails());
+ }
+
+ // List of ExtraFeesDetails
+ if (carDetails.getExtraFeesDetails() != null) {
+ LOGGER.info("Extra Fees Details: {}", carDetails.getExtraFeesDetails());
+ }
+
+ // ReferencePrice is the totalPrice for the comparable standalone car, when there is
+ // a discounted car or need to show strike through pricing.
+ if (carDetails.getReferencePrice() != null) {
+ LOGGER.info("Reference Price: {}", carDetails.getReferencePrice());
+ }
+
+ // List of additional fees including both mandatory and optional fees such as young driver
+ // fee/drop off fee /CollisionDamageWaiver.
+ if (carDetails.getAdditionalFees() != null) {
+ LOGGER.info("Additional Fees: {}", carDetails.getAdditionalFees());
+ }
+
+ // Description and costs of any optional special equipment that may be rented with the car.
+ if (carDetails.getSpecialEquipments() != null) {
+ LOGGER.info("Special Equipments: {}", carDetails.getSpecialEquipments());
+ }
+
+ // Limitations that are part of this rental agreement.
+ if (carDetails.getRentalLimits() != null) {
+ LOGGER.info("Rental Limits: {}", carDetails.getRentalLimits());
+ }
+
+ // Cancellation Policy Container.
+ LOGGER.info("Cancellation Policy: {}", carDetails.getCancellationPolicy());
+
+ // Container for no show penalty
+ if (carDetails.getNoShowPenalty() != null) {
+ LOGGER.info("No Show Penalty: {}", carDetails.getNoShowPenalty());
+ }
+
+ // A list of policies that apply to this car rental.
+ if (carDetails.getCarPolicies() != null) {
+ LOGGER.info("Policies: {}", carDetails.getCarPolicies());
+ }
+
+ // List of image resources of the car product.
+ if (carDetails.getImages() != null) {
+ LOGGER.info("Images: {}", carDetails.getImages());
+ }
+
+ LOGGER.info("========== Property End ==========");
+ }
+
+ });
- LOGGER.info("========== End QuickStartExample ==========");
- }
+ LOGGER.info("========== End QuickStartExample ==========");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarListingsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarListingsQuickStartScenario.java
index 0d2d6406f..c2ebf056b 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarListingsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarListingsQuickStartScenario.java
@@ -33,140 +33,160 @@
*/
public class CarListingsQuickStartScenario implements XapScenario {
- private static final Logger LOGGER = LoggerFactory.getLogger(CarListingsQuickStartScenario.class);
-
- /**
- * Summary: main function.
- */
- public static void main(String[] args) {
- new CarListingsQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- LOGGER.info(
- "========================= Running CarListingsQuickStartScenario ========================");
-
- LOGGER.info(
- "======================== Executing GetCarsListingsOperation =======================");
- // This example will search for properties based on the following criteria:
- // 1. The pickup airport is MCO, and the drop-off airport is MCO;
- // 2. The pickup time is "2025-01-15T11:00", and the drop-off time is "2025-01-19T11:00";
- // 3. The results should include API details, web search, and web details link;
- // 4. Limit the results to 5;
-
- // Create a list to store the types of links to be returned.
- // The added link types include(API details link, Web search link, and Web details link).
- List linksList = new ArrayList<>();
- linksList.add(GetCarsListingsOperationParams.Links.AD);
- linksList.add(GetCarsListingsOperationParams.Links.WS);
- linksList.add(GetCarsListingsOperationParams.Links.WD);
-
- GetCarsListingsOperationParams getCarsListingsOperationParams =
- GetCarsListingsOperationParams.builder().partnerTransactionId("EWSCar_Automation")
- //Three letter code for the airport at which the customer would like to pick up the car.
- //Supported values: standard 3 letter IATA Airport Code.
- //Cannot coexist with other pickup parameters, only one pickup parameter is allowed per
- //request.
- .pickupAirport("MCO")
- //Three letter code for the airport at which the customer would like to drop off the
- //car.
- //Supported values: standard 3 letter IATA Airport Code.
- //Cannot coexist with other drop off parameters, only one drop off parameter is allowed
- //per request.
- //If no drop off location is specified, it is assumed that the customer will be dropping
- //the car off at the same location at which they picked it up.
- .dropOffAirport("MCO")
- //Requested car pickup date and time.
- //Date should be ISO8601 Date format.The supported search window is today to 330 days in
- //the future.
- //(Note that each rental counter has different hours of operation. If you select a time
- //in the middle of the night there may be no inventory available as all locations may be
- //closed.)
- .pickupTime(LocalDateTime.now().plusDays(5))
- //Requested car drop off date and time.
- //Date should be ISO8601 Date format.The supported search window is today to 330 days in
- //the future.
- //The drop-off datetime should occur at least 2 hours after the pickup datetime.
- .dropOffTime(LocalDateTime.now().plusDays(8))
- //The maximum number of search results that will be returned by the query.
- .limit(5).links(linksList).build();
- XapClient xapClient = createClient();
-
- // Execute the operation and get the CarListingsResponse
- CarListingsResponse carListingsResponse =
- xapClient.execute(new GetCarsListingsOperation(getCarsListingsOperationParams)).getData();
- LOGGER.info(
- "======================== GetCarsListingsOperation Executed ========================");
-
- if (carListingsResponse == null || carListingsResponse.getCars() == null
- || carListingsResponse.getCars().isEmpty()) {
- throw new IllegalStateException("No cars found.");
+ private static final Logger LOGGER = LoggerFactory.getLogger(CarListingsQuickStartScenario.class);
+
+ /**
+ * Summary: main function.
+ */
+ public static void main(String[] args) {
+ new CarListingsQuickStartScenario().run();
+ System.exit(0);
}
- // The CarListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", carListingsResponse.getTransactionId());
- // To get the total number of car found
- LOGGER.info("Car Count: {}", carListingsResponse.getCarCount());
-
- // To access the properties, iterate through the list of car properties
- carListingsResponse.getCars().forEach(car -> {
- LOGGER.info("======================== Car Properties Start ========================");
-
- // Uniquely identifies a Car Offer.
- LOGGER.info("Car Id: {}", car.getId());
-
- // Specific information for a car.
- LOGGER.info("Car VehicleDetails: {}", car.getVehicleDetails());
-
- // The supplier of the car being offered.
- LOGGER.info("Car Supplier: {}", car.getSupplier());
-
- // Get Pickup information of the car.
- LOGGER.info("Pick up Details: {}", car.getPickupDetails());
-
- // Get Drop off information of the car.
- LOGGER.info("Drop Off Details: {}", car.getDropOffDetails());
-
- // Get the API details link, web search link, and web details link from the links collection.
- if (!car.getLinks().isEmpty()) {
- if (car.getLinks().get("ApiDetails") != null) {
- LOGGER.info("ApiDetails Link: {}", car.getLinks().get("ApiDetails"));
- }
- if (car.getLinks().get("WebSearch") != null) {
- LOGGER.info("WebSearch Link: {}", car.getLinks().get("WebSearch"));
+ @Override
+ public void run() {
+ LOGGER.info(
+ "========================= Running CarListingsQuickStartScenario ========================");
+
+ LOGGER.info(
+ "======================== Executing GetCarsListingsOperation =======================");
+ // This example will search for properties based on the following criteria:
+ // 1. The pickup airport is MCO, and the drop-off airport is MCO;
+ // 2. The pickup time is "2025-01-15T11:00", and the drop-off time is "2025-01-19T11:00";
+ // 3. The results should include API details, web search, and web details link;
+ // 4. Limit the results to 5;
+
+ // Create a list to store the types of links to be returned.
+ // The added link types include(API details link, Web search link, and Web details link).
+ List linksList = new ArrayList<>();
+ linksList.add(GetCarsListingsOperationParams.Links.AD);
+ linksList.add(GetCarsListingsOperationParams.Links.WS);
+ linksList.add(GetCarsListingsOperationParams.Links.WD);
+
+ GetCarsListingsOperationParams getCarsListingsOperationParams =
+ GetCarsListingsOperationParams.builder().partnerTransactionId("EWSCar_Automation")
+ //Three letter code for the airport at which the customer would like to pick up the car.
+ //Supported values: standard 3 letter IATA Airport Code.
+ //Cannot coexist with other pickup parameters, only one pickup parameter is allowed per
+ //request.
+ .pickupAirport("MCO")
+ //Three letter code for the airport at which the customer would like to drop off the
+ //car.
+ //Supported values: standard 3 letter IATA Airport Code.
+ //Cannot coexist with other drop off parameters, only one drop off parameter is allowed
+ //per request.
+ //If no drop off location is specified, it is assumed that the customer will be dropping
+ //the car off at the same location at which they picked it up.
+ .dropOffAirport("MCO")
+ //Requested car pickup date and time.
+ //Date should be ISO8601 Date format.The supported search window is today to 330 days in
+ //the future.
+ //(Note that each rental counter has different hours of operation. If you select a time
+ //in the middle of the night there may be no inventory available as all locations may be
+ //closed.)
+ .pickupTime(
+ LocalDateTime.now()
+ .withNano(0)
+ .withSecond(0)
+ .withHour(10)
+ .plusDays(10)
+ .plusMonths(1)
+ )
+ //Requested car drop off date and time.
+ //Date should be ISO8601 Date format.The supported search window is today to 330 days in
+ //the future.
+ //The drop-off datetime should occur at least 2 hours after the pickup datetime.
+ .dropOffTime(
+ LocalDateTime.now()
+ .withNano(0)
+ .withSecond(0)
+ .withHour(10)
+ .plusDays(15)
+ .plusMonths(1)
+ )
+ .pickupRadius(10)
+ .dropOffRadius(10)
+ //The maximum number of search results that will be returned by the query.
+ .limit(5)
+ .partnerTransactionId("BestTravel-123456-798101112")
+ .links(linksList)
+ .build();
+
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the CarListingsResponse
+ CarListingsResponse carListingsResponse =
+ xapClient.execute(new GetCarsListingsOperation(getCarsListingsOperationParams)).getData();
+ LOGGER.info(
+ "======================== GetCarsListingsOperation Executed ========================");
+
+ if (carListingsResponse == null || carListingsResponse.getCars() == null
+ || carListingsResponse.getCars().isEmpty()) {
+ throw new IllegalStateException("No cars found.");
}
- if (car.getLinks().get("WebDetails") != null) {
- LOGGER.info("WebDetails Link: {}", car.getLinks().get("WebDetails"));
- }
- }
-
- // The rate detail information for a car offer.
- if (car.getRateDetails() != null) {
- LOGGER.info("Rate Details: {}", car.getRateDetails());
- }
-
- // Get the detailed pricing information for the rental of the car offer,
- LOGGER.info("Car Price: {}", car.getPrice());
-
- // Get a list of additional fees, including both mandatory and optional fees.
- if (car.getAdditionalFees() != null) {
- LOGGER.info("Additional Fees: {}", car.getAdditionalFees());
- }
-
- // Get the cancellation policy for the car offer,
- LOGGER.info("Cancellation Policy: {}", car.getCancellationPolicy());
-
- // Container for no show penalty element.
- if (car.getNoShowPenalty() != null) {
- LOGGER.info("No Show Penalty: {}", car.getNoShowPenalty());
- }
-
- LOGGER.info("======================== Property End ========================");
- });
- LOGGER.info(
- "======================== End CarListingsQuickStartScenario ========================");
- }
+ // The CarListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", carListingsResponse.getTransactionId());
+ // To get the total number of car found
+ LOGGER.info("Car Count: {}", carListingsResponse.getCarCount());
+
+ // To access the properties, iterate through the list of car properties
+ carListingsResponse.getCars().forEach(car -> {
+ LOGGER.info("======================== Car Properties Start ========================");
+
+ // Uniquely identifies a Car Offer.
+ LOGGER.info("Car Id: {}", car.getId());
+
+ // Specific information for a car.
+ LOGGER.info("Car VehicleDetails: {}", car.getVehicleDetails());
+
+ // The supplier of the car being offered.
+ LOGGER.info("Car Supplier: {}", car.getSupplier());
+
+ // Get Pickup information of the car.
+ LOGGER.info("Pick up Details: {}", car.getPickupDetails());
+
+ // Get Drop off information of the car.
+ LOGGER.info("Drop Off Details: {}", car.getDropOffDetails());
+
+ // Get the API details link, web search link, and web details link from the links collection.
+ if (!car.getLinks().isEmpty()) {
+ if (car.getLinks().get("ApiDetails") != null) {
+ LOGGER.info("ApiDetails Link: {}", car.getLinks().get("ApiDetails"));
+ }
+ if (car.getLinks().get("WebSearch") != null) {
+ LOGGER.info("WebSearch Link: {}", car.getLinks().get("WebSearch"));
+ }
+ if (car.getLinks().get("WebDetails") != null) {
+ LOGGER.info("WebDetails Link: {}", car.getLinks().get("WebDetails"));
+ }
+ }
+
+ // The rate detail information for a car offer.
+ if (car.getRateDetails() != null) {
+ LOGGER.info("Rate Details: {}", car.getRateDetails());
+ }
+
+ // Get the detailed pricing information for the rental of the car offer,
+ LOGGER.info("Car Price: {}", car.getPrice());
+
+
+ // Get a list of additional fees, including both mandatory and optional fees.
+ if (car.getAdditionalFees() != null) {
+ LOGGER.info("Additional Fees: {}", car.getAdditionalFees());
+ }
+
+ // Get the cancellation policy for the car offer,
+ LOGGER.info("Cancellation Policy: {}", car.getCancellationPolicy());
+
+ // Container for no show penalty element.
+ if (car.getNoShowPenalty() != null) {
+ LOGGER.info("No Show Penalty: {}", car.getNoShowPenalty());
+ }
+
+ LOGGER.info("======================== Property End ========================");
+ });
+ LOGGER.info(
+ "======================== End CarListingsQuickStartScenario ========================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java
index fc645a330..0c652a89c 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java
@@ -16,6 +16,7 @@
package com.expediagroup.sdk.xap.examples.scenarios.lodging;
+
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.models.AvailabilityCalendarResponse;
import com.expediagroup.sdk.xap.operations.GetLodgingAvailabilityCalendarsOperation;
@@ -33,77 +34,77 @@
*/
public class AvailabilityCalendarsQuickStartScenario implements VrboScenario {
- private static final Logger LOGGER =
- LoggerFactory.getLogger(AvailabilityCalendarsQuickStartScenario.class);
-
- public static void main(String[] args) {
- new AvailabilityCalendarsQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example returns the availability of each day for a range of dates for given Expedia
- // lodging properties.
-
- LOGGER.info(
- "=================== Running AvailabilityCalendarsQuickStartScenario ===================");
-
- LOGGER.info(
- "================= Executing GetLodgingAvailabilityCalendars Operation ================");
-
-
- // Build the query parameters with GetLodgingAvailabilityCalendarsOperationParams
- GetLodgingAvailabilityCalendarsOperationParams availabilityCalendarsOperationParams =
- GetLodgingAvailabilityCalendarsOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
- // Set of Expedia Property IDs.
- .propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201")))
- .build();
-
- XapClient xapClient = createClient();
-
- // Execute the operation and get the AvailabilityCalendarsResponse
- AvailabilityCalendarResponse availabilityCalendarResponse =
- xapClient.execute(new GetLodgingAvailabilityCalendarsOperation(
- availabilityCalendarsOperationParams)).getData();
-
- // If you want to use the async method, you can use the following code:
- // ---------------------------------------------------------------
- // CompletableFuture> completableFuture =
- // xapClient.executeAsync(
- // new GetLodgingAvailabilityCalendarsOperation(availabilityCalendarsOperationParams));
- // completableFuture.thenAccept(availCalendarResponse -> {
- // // Your code here
- // });
- // ---------------------------------------------------------------
-
- LOGGER.info(
- "================== GetLodgingAvailabilityCalendarsOperation Executed =================");
-
- if (availabilityCalendarResponse == null
- || availabilityCalendarResponse.getAvailabilityCalendars() == null
- || availabilityCalendarResponse.getAvailabilityCalendars().isEmpty()) {
- throw new IllegalStateException("No properties found.");
- }
-
- // The AvailabilityCalendarsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", availabilityCalendarResponse.getTransactionId());
-
- // To access the properties, iterate through the list of properties
- availabilityCalendarResponse.getAvailabilityCalendars().forEach(availCalendar -> {
- LOGGER.info("========== Property:{} Start ==========", availCalendar.getPropertyId());
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(AvailabilityCalendarsQuickStartScenario.class);
- // Availability of property: A string of codes that shows property availability, one for every
- // day in the specified date range.
- // Valid values include Y (available) and N (unavailable).
- LOGGER.info("Availability: {}", availCalendar.getAvailability());
-
- LOGGER.info(
- "==================================== Property End ===================================");
+ public static void main(String[] args) {
+ new AvailabilityCalendarsQuickStartScenario().run();
+ System.exit(0);
+ }
- LOGGER.info(
- "===================== End AvailabilityCalendarsQuickStartScenario ====================");
- });
- }
+ @Override
+ public void run() {
+ // This example returns the availability of each day for a range of dates for given Expedia
+ // lodging properties.
+
+ LOGGER.info(
+ "=================== Running AvailabilityCalendarsQuickStartScenario ===================");
+
+ LOGGER.info(
+ "================= Executing GetLodgingAvailabilityCalendars Operation ================");
+
+
+ // Build the query parameters with GetLodgingAvailabilityCalendarsOperationParams
+ GetLodgingAvailabilityCalendarsOperationParams availabilityCalendarsOperationParams =
+ GetLodgingAvailabilityCalendarsOperationParams.builder()
+ .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ // Set of Expedia Property IDs.
+ .propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201")))
+ .build();
+
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the AvailabilityCalendarsResponse
+ AvailabilityCalendarResponse availabilityCalendarResponse =
+ xapClient.execute(new GetLodgingAvailabilityCalendarsOperation(
+ availabilityCalendarsOperationParams)).getData();
+
+ // If you want to use the async method, you can use the following code:
+ // ---------------------------------------------------------------
+ // CompletableFuture> completableFuture =
+ // xapClient.executeAsync(
+ // new GetLodgingAvailabilityCalendarsOperation(availabilityCalendarsOperationParams));
+ // completableFuture.thenAccept(availCalendarResponse -> {
+ // // Your code here
+ // });
+ // ---------------------------------------------------------------
+
+ LOGGER.info(
+ "================== GetLodgingAvailabilityCalendarsOperation Executed =================");
+
+ if (availabilityCalendarResponse == null
+ || availabilityCalendarResponse.getAvailabilityCalendars() == null
+ || availabilityCalendarResponse.getAvailabilityCalendars().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
+ }
+
+ // The AvailabilityCalendarsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", availabilityCalendarResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of properties
+ availabilityCalendarResponse.getAvailabilityCalendars().forEach(availCalendar -> {
+ LOGGER.info("========== Property:{} Start ==========", availCalendar.getPropertyId());
+
+ // Availability of property: A string of codes that shows property availability, one for every
+ // day in the specified date range.
+ // Valid values include Y (available) and N (unavailable).
+ LOGGER.info("Availability: {}", availCalendar.getAvailability());
+
+ LOGGER.info(
+ "==================================== Property End ===================================");
+
+ LOGGER.info(
+ "===================== End AvailabilityCalendarsQuickStartScenario ====================");
+ });
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java
index c83875a16..20c1cdb62 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/HotelIdsSearchEndToEndScenario.java
@@ -16,7 +16,8 @@
package com.expediagroup.sdk.xap.examples.scenarios.lodging;
-import com.expediagroup.sdk.core.model.Response;
+
+import com.expediagroup.sdk.rest.model.Response;
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
import com.expediagroup.sdk.xap.models.Hotel;
@@ -37,10 +38,8 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.lang3.StringUtils;
@@ -56,149 +55,241 @@
*/
public class HotelIdsSearchEndToEndScenario implements XapScenario {
- private final XapClient client = createClient();
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(HotelIdsSearchEndToEndScenario.class);
+ /**
+ * This field limits the number of line to read from the SDP DownloadURL API Listings file to
+ * reduce time to run the example.
+ * If the first 20 properties from the file are not accessible OR available when you run this
+ * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
+ * you can adjust the property count to get more properties.
+ */
+ private static final int SAMPLE_ITEMS_RESTRICTION = 20;
+ private final XapClient client = createClient();
- private static final Logger LOGGER =
- LoggerFactory.getLogger(HotelIdsSearchEndToEndScenario.class);
+ public static void main(String[] args) {
+ new HotelIdsSearchEndToEndScenario().run();
+ System.exit(0);
+ }
- /**
- * This field limits the number of line to read from the SDP DownloadURL API Listings file to
- * reduce time to run the example.
- * If the first 20 properties from the file are not accessible OR available when you run this
- * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
- * you can adjust the property count to get more properties.
- */
- private static final int SAMPLE_ITEMS_RESTRICTION = 20;
+ /**
+ * Display the result of the operations.
+ *
+ * @param hotelListingsResponse The response of the Lodging Listings API.
+ */
+ private static void displayResult(HotelListingsResponse hotelListingsResponse) {
+ LOGGER.info("====================== Executing Step III: DisplayResult =======================");
+ if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
+ || hotelListingsResponse.getHotels().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
+ }
- public static void main(String[] args) {
- new HotelIdsSearchEndToEndScenario().run();
- System.exit(0);
- }
+ // The HotelListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
- @Override
- public void run() {
- LOGGER.info(
- "======================== Running HotelIdsSearchEndToEndScenario =======================");
+ // To access the properties, iterate through the list of hotel properties
+ hotelListingsResponse.getHotels().forEach(hotel -> {
+ // Check if the property is available
+ if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
+ LOGGER.info("Property {} is not available.", hotel.getId());
+ return;
+ }
+ LOGGER.info(
+ "=================================== Property Start ===================================");
+ // To get the property name
+ if (StringUtils.isNotEmpty(hotel.getName())) {
+ LOGGER.info("Property Name: {}", hotel.getName());
+ }
+ // To get the property address
+ if (hotel.getLocation() != null) {
+ LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
+ }
+ // To get the property thumbnail URL
+ if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
+ LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
+ }
+ // To get the star rating of the property. The value is between 1.0 and 5.0
+ // in a 0.5 increment.
+ if (hotel.getStarRating() != null) {
+ LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
+ }
+ // To get the guest rating of the property. The value is between 1.0 and 5.0
+ // in a 0.1 increment.
+ if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
+ LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
+ }
+ // To get the total number of reviews for the property
+ if (hotel.getGuestReviewCount() != null) {
+ LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
+ }
+ if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ RoomType roomType = hotel.getRoomTypes().get(0);
+ if (StringUtils.isNotEmpty(roomType.getDescription())) {
+ LOGGER.info("Room Type: {}", roomType.getDescription());
+ }
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}",
+ roomType.getPrice().getTotalPrice().getValue(),
+ roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}",
+ roomType.getPrice().getAvgNightlyRate().getValue(),
+ roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
+ && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}",
+ roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the Expedia Web Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}",
+ roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the Expedia Web Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info(
+ "==================================== Property End ====================================");
+ });
+ LOGGER.info("====================== Step III: DisplayResult Executed ========================");
+ }
- List propertyIds = getPropertyIdsFromDownloadUrl();
- HotelListingsResponse hotelListingsResponse = getPropertiesFromLodgingListings(propertyIds);
- displayResult(hotelListingsResponse);
+ @Override
+ public void run() {
+ LOGGER.info(
+ "======================== Running HotelIdsSearchEndToEndScenario =======================");
- LOGGER.info(
- "========================== End HotelIdsSearchEndToEndScenario =========================");
- }
+ List propertyIds = getPropertyIdsFromDownloadUrl();
+ HotelListingsResponse hotelListingsResponse = getPropertiesFromLodgingListings(propertyIds);
+ displayResult(hotelListingsResponse);
- /**
- * Retrieve accessible property ids from SDP DownloadURL API.
- *
- * @return property ids
- */
- private List getPropertyIdsFromDownloadUrl() {
- LOGGER.info(
- "==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
+ LOGGER.info(
+ "========================== End HotelIdsSearchEndToEndScenario =========================");
+ }
- GetFeedDownloadUrlOperationParams getPropertyIdListParams =
- GetFeedDownloadUrlOperationParams.builder()
- // Use the type LISTINGS to get the list of accessible property ids.
- .type(GetFeedDownloadUrlOperationParams.Type.LISTINGS)
- // Without any filters, this operation will return the information of all lodging
- // properties in en_US by default.
- .build();
+ /**
+ * Retrieve accessible property ids from SDP DownloadURL API.
+ *
+ * @return property ids
+ */
+ private List getPropertyIdsFromDownloadUrl() {
+ LOGGER.info(
+ "==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
- Response downloadUrlListingsResponse =
- client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
+ GetFeedDownloadUrlOperationParams getPropertyIdListParams =
+ GetFeedDownloadUrlOperationParams.builder()
+ // Use the type LISTINGS to get the list of accessible property ids.
+ .type(GetFeedDownloadUrlOperationParams.Type.LISTINGS)
+ // Without any filters, this operation will return the information of all lodging
+ // properties in en_US by default.
+ .build();
- if (downloadUrlListingsResponse.getData() == null
- || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
- throw new IllegalStateException("No listings file found");
- }
+ Response downloadUrlListingsResponse =
+ client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
- // The download URL points to a zip file containing various jsonl files.
- // Each line in the jsonl files contains a json object representing a property.
- // For demonstration purposes, we will only read a few properties from the file without
- // downloading the entire file.
- String listingsDownloadUrl = downloadUrlListingsResponse.getData()
- .getBestMatchedFile()
- .getDownloadUrl();
- LOGGER.info("Listings Download URL: {}", listingsDownloadUrl);
+ if (downloadUrlListingsResponse.getData() == null
+ || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
+ throw new IllegalStateException("No listings file found");
+ }
- // Read property ids from the file.
- List propertyIds = getPropertyIdsFromListingsFile(listingsDownloadUrl);
+ // The download URL points to a zip file containing various jsonl files.
+ // Each line in the jsonl files contains a json object representing a property.
+ // For demonstration purposes, we will only read a few properties from the file without
+ // downloading the entire file.
+ String listingsDownloadUrl = downloadUrlListingsResponse.getData()
+ .getBestMatchedFile()
+ .getDownloadUrl();
+ LOGGER.info("Listings Download URL: {}", listingsDownloadUrl);
- if (propertyIds.isEmpty()) {
- throw new IllegalStateException("No accessible property ids found.");
- }
- LOGGER.info("Accessible Property Ids: {}", propertyIds);
+ // Read property ids from the file.
+ List propertyIds = getPropertyIdsFromListingsFile(listingsDownloadUrl);
- LOGGER.info(
- "==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
- return propertyIds;
- }
+ if (propertyIds.isEmpty()) {
+ throw new IllegalStateException("No accessible property ids found.");
+ }
+ LOGGER.info("Accessible Property Ids: {}", propertyIds);
- /**
- * Get prices of the properties using the Lodging Listings API.
- *
- * @param propertyIds The property ids to get the prices.
- * @return The response of the Lodging Listings API.
- */
- private HotelListingsResponse getPropertiesFromLodgingListings(List propertyIds) {
- LOGGER.info(
- "================ Step II: Executing getPropertiesFromLodgingListings ===============");
+ LOGGER.info(
+ "==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
+ return propertyIds;
+ }
- GetLodgingListingsOperationParams getLodgingListingsOperationParams =
- GetLodgingListingsOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
- // Use the property ids read from the file
- .ecomHotelIds(new HashSet<>(propertyIds))
- // The links to return, WEB includes WS (Web Search Result Page)
- // and WD (Web Details Page)
- .links(Collections.singletonList(GetLodgingListingsOperationParams.Links.WEB))
- // Check-in 5 days from now
- .checkIn(LocalDate.now().plusDays(5))
- // Check-out 10 days from now
- .checkOut(LocalDate.now().plusDays(10))
- // Filter the properties that are available only
- .availOnly(true)
- // Use the default occupancy: 2 adults in one room
- .build();
+ /**
+ * Get prices of the properties using the Lodging Listings API.
+ *
+ * @param propertyIds The property ids to get the prices.
+ * @return The response of the Lodging Listings API.
+ */
+ private HotelListingsResponse getPropertiesFromLodgingListings(List propertyIds) {
+ LOGGER.info(
+ "================ Step II: Executing getPropertiesFromLodgingListings ===============");
- HotelListingsResponse hotelListingsResponse =
- client.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams))
- .getData();
+ GetLodgingListingsOperationParams getLodgingListingsOperationParams =
+ GetLodgingListingsOperationParams.builder()
+ .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ // Use the property ids read from the file
+ .ecomHotelIds(new HashSet<>(propertyIds))
+ // The links to return, WEB includes WS (Web Search Result Page)
+ // and WD (Web Details Page)
+ .links(Collections.singletonList(GetLodgingListingsOperationParams.Links.WEB))
+ // Check-in 5 days from now
+ .checkIn(LocalDate.now().plusDays(5))
+ // Check-out 10 days from now
+ .checkOut(LocalDate.now().plusDays(10))
+ // Filter the properties that are available only
+ .availOnly(true)
+ // Use the default occupancy: 2 adults in one room
+ .build();
- LOGGER.info(
- "================ Step II: getPropertiesFromLodgingListings Executed ================");
- return hotelListingsResponse;
- }
+ HotelListingsResponse hotelListingsResponse =
+ client.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams))
+ .getData();
- /**
- * Reads given number of property ids from the file pointed by the download URL.
- *
- * @param downloadUrl The download URL of the zip file containing the property information.
- * @return A list of property ids read from the file.
- */
- private List getPropertyIdsFromListingsFile(String downloadUrl) {
- List propertyIds = new ArrayList<>();
- HttpURLConnection connection = null;
- try {
- // Open a connection to the URL
- URL url = new URL(downloadUrl);
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.setDoInput(true);
+ LOGGER.info(
+ "================ Step II: getPropertiesFromLodgingListings Executed ================");
+ return hotelListingsResponse;
+ }
- try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- if (entry.getName().endsWith(".jsonl")) {
- LOGGER.info("Reading property ids from file: {}", entry.getName());
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
- String line;
- ObjectMapper objectMapper = new ObjectMapper();
- while ((line = reader.readLine()) != null
- && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
- // Parse the property id from the json object
- // An example json line from the jsonl file:
+ /**
+ * Reads given number of property ids from the file pointed by the download URL.
+ *
+ * @param downloadUrl The download URL of the zip file containing the property information.
+ * @return A list of property ids read from the file.
+ */
+ private List getPropertyIdsFromListingsFile(String downloadUrl) {
+ List propertyIds = new ArrayList<>();
+ HttpURLConnection connection = null;
+ try {
+ // Open a connection to the URL
+ URL url = new URL(downloadUrl);
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setDoInput(true);
+
+ try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ if (entry.getName().endsWith(".jsonl")) {
+ LOGGER.info("Reading property ids from file: {}", entry.getName());
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
+ String line;
+ ObjectMapper objectMapper = new ObjectMapper();
+ while ((line = reader.readLine()) != null
+ && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
+ // Parse the property id from the json object
+ // An example json line from the jsonl file:
/*
{
"propertyId": {
@@ -227,126 +318,32 @@ private List getPropertyIdsFromListingsFile(String downloadUrl) {
}
}
*/
- JsonNode jsonNode = objectMapper.readTree(line);
- // Check if the property is accessible from Lodging Listings API
- // (Vrbo properties that are not instantBookable are not accessible for now)
- if (!jsonNode.get("propertyId").get("vrbo").asText().isEmpty()
- && jsonNode.has("vrboPropertyType")
- && !jsonNode.get("vrboPropertyType").get("instantBook").asBoolean()
- ) {
- // Skip the property if it is not an instant bookable Vrbo property
- continue;
- } else {
- // Get the Expedia property id for the Lodging Listings API
- propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
+ JsonNode jsonNode = objectMapper.readTree(line);
+ // Check if the property is accessible from Lodging Listings API
+ // (Vrbo properties that are not instantBookable are not accessible for now)
+ if (!jsonNode.get("propertyId").get("vrbo").asText().isEmpty()
+ && jsonNode.has("vrboPropertyType")
+ && !jsonNode.get("vrboPropertyType").get("instantBook").asBoolean()
+ ) {
+ // Skip the property if it is not an instant bookable Vrbo property
+ continue;
+ } else {
+ // Get the Expedia property id for the Lodging Listings API
+ propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
+ }
+ }
+ }
+ }
}
- }
}
- }
- }
- }
-
- } catch (IOException e) {
- LOGGER.error("Error reading property ids from download URL", e);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- return propertyIds;
- }
- /**
- * Display the result of the operations.
- *
- * @param hotelListingsResponse The response of the Lodging Listings API.
- */
- private static void displayResult(HotelListingsResponse hotelListingsResponse) {
- LOGGER.info("====================== Executing Step III: DisplayResult =======================");
- if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
- || hotelListingsResponse.getHotels().isEmpty()) {
- throw new IllegalStateException("No properties found.");
- }
-
- // The HotelListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
-
- // To access the properties, iterate through the list of hotel properties
- hotelListingsResponse.getHotels().forEach(hotel -> {
- // Check if the property is available
- if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
- LOGGER.info("Property {} is not available.", hotel.getId());
- return;
- }
- LOGGER.info(
- "=================================== Property Start ===================================");
- // To get the property name
- if (StringUtils.isNotEmpty(hotel.getName())) {
- LOGGER.info("Property Name: {}", hotel.getName());
- }
- // To get the property address
- if (hotel.getLocation() != null) {
- LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
- }
- // To get the property thumbnail URL
- if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
- LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
- }
- // To get the star rating of the property. The value is between 1.0 and 5.0
- // in a 0.5 increment.
- if (hotel.getStarRating() != null) {
- LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
- }
- // To get the guest rating of the property. The value is between 1.0 and 5.0
- // in a 0.1 increment.
- if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
- LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
- }
- // To get the total number of reviews for the property
- if (hotel.getGuestReviewCount() != null) {
- LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
- }
- if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
- // To get the first room type information
- RoomType roomType = hotel.getRoomTypes().get(0);
- if (StringUtils.isNotEmpty(roomType.getDescription())) {
- LOGGER.info("Room Type: {}", roomType.getDescription());
- }
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
- }
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
- }
- if (roomType.getLinks() != null) {
- // To get the deeplink to the Expedia Web Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the Expedia Web Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
+ } catch (IOException e) {
+ LOGGER.error("Error reading property ids from download URL", e);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
}
- }
- LOGGER.info(
- "==================================== Property End ====================================");
- });
- LOGGER.info("====================== Step III: DisplayResult Executed ========================");
- }
+ return propertyIds;
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java
index 4d1cb73fe..0d453bc27 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java
@@ -16,6 +16,7 @@
package com.expediagroup.sdk.xap.examples.scenarios.lodging;
+
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
import com.expediagroup.sdk.xap.models.Hotel;
@@ -37,173 +38,173 @@
*/
public class ListingsQuickStartScenario implements XapScenario {
- private static final Logger LOGGER = LoggerFactory.getLogger(ListingsQuickStartScenario.class);
-
- public static void main(String[] args) {
- new ListingsQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example will search for properties with the following criteria:
- // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
- // in the second room;
- // 2. Properties located within 10 km of the Space Needle in Seattle;
- // 3. Check-in date 5 days from now, check-out date 10 days from now;
- // 4. Return web links to Expedia website;
- // 5. Limit the results to 5 properties;
- // 6. Order the results by price in ascending order.
-
- LOGGER.info(
- "========================== Running ListingsQuickStartScenario =========================");
-
- LOGGER.info(
- "======================== Executing GetLodgingListingsOperation =======================");
-
- // Build the occupancy
- ArrayList rooms = new ArrayList<>();
- // The first room, with 1 adult
- rooms.add(Room.builder().adults(1L).build());
- // The second room, with 2 adults and 2 children
- ArrayList childrenAges = new ArrayList<>();
- childrenAges.add(10L);
- childrenAges.add(12L);
- rooms.add(Room.builder().adults(2L).childAges(childrenAges).build());
-
- // Build the query parameters with GetLodgingListingsOperationParams
- GetLodgingListingsOperationParams getLodgingListingsOperationParams =
- GetLodgingListingsOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
- // The location keyword can be a city, address, airport or a landmark.
- .locationKeyword("Space Needle, Seattle")
- // The radius specifies the size of search area around the location keyword.
- // The default value is 25.
- .radius(10)
- // The unit specifies the unit of the radius. The default value is KM.
- .unit(GetLodgingListingsOperationParams.Unit.KM)
- // Check-in 5 days from now
- .checkIn(LocalDate.now().plusDays(5))
- // Check-out 10 days from now
- .checkOut(LocalDate.now().plusDays(10))
- // The occupancy
- .rooms(rooms)
- // The links to return, WEB includes WS (Web Search Result Page)
- // and WD (Web Details Page)
- .links(Collections.singletonList(GetLodgingListingsOperationParams.Links.WEB))
- // Limit the results to 5 properties
- .limit(5)
- // Order the results by price in ascending order
- .sortType(GetLodgingListingsOperationParams.SortType.PRICE)
- .sortOrder(GetLodgingListingsOperationParams.SortOrder.ASC)
- .build();
-
- XapClient xapClient = createClient();
-
- // Execute the operation and get the HotelListingsResponse
- HotelListingsResponse hotelListingsResponse =
- xapClient.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams))
- .getData();
-
- // If you want to use the async method, you can use the following code:
- // ---------------------------------------------------------------
- // CompletableFuture> completableFuture =
- // xapClient.executeAsync(
- // new GetLodgingListingsOperation(getLodgingListingsOperationParams));
- // completableFuture.thenAccept(hotelListingsResponse -> {
- // // Your code here
- // });
- // ---------------------------------------------------------------
-
- LOGGER.info(
- "======================== GetLodgingListingsOperation Executed ========================");
-
- if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
- || hotelListingsResponse.getHotels().isEmpty()) {
- throw new IllegalStateException("No properties found.");
+ private static final Logger LOGGER = LoggerFactory.getLogger(ListingsQuickStartScenario.class);
+
+ public static void main(String[] args) {
+ new ListingsQuickStartScenario().run();
+ System.exit(0);
}
- // The HotelListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
-
- // To access the properties, iterate through the list of hotel properties
- hotelListingsResponse.getHotels().forEach(hotel -> {
- // Check if the property is available
- if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
- LOGGER.info("Property {} is not available.", hotel.getId());
- return;
- }
- LOGGER.info(
- "=================================== Property Start ===================================");
- // To get the property name
- if (StringUtils.isNotEmpty(hotel.getName())) {
- LOGGER.info("Property Name: {}", hotel.getName());
- }
- // To get the property address
- if (hotel.getLocation() != null) {
- LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
- }
- // To get the property thumbnail URL
- if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
- LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
- }
- // To get the star rating of the property. The value is between 1.0 and 5.0
- // in a 0.5 increment.
- if (hotel.getStarRating() != null) {
- LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
- }
- // To get the guest rating of the property. The value is between 1.0 and 5.0
- // in a 0.1 increment.
- if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
- LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
- }
- // To get the total number of reviews for the property
- if (hotel.getGuestReviewCount() != null) {
- LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
- }
- if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
- // To get the first room type information
- RoomType roomType = hotel.getRoomTypes().get(0);
- if (StringUtils.isNotEmpty(roomType.getDescription())) {
- LOGGER.info("Room Type: {}", roomType.getDescription());
- }
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
- }
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ @Override
+ public void run() {
+ // This example will search for properties with the following criteria:
+ // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
+ // in the second room;
+ // 2. Properties located within 10 km of the Space Needle in Seattle;
+ // 3. Check-in date 5 days from now, check-out date 10 days from now;
+ // 4. Return web links to Expedia website;
+ // 5. Limit the results to 5 properties;
+ // 6. Order the results by price in ascending order.
+
+ LOGGER.info(
+ "========================== Running ListingsQuickStartScenario =========================");
+
+ LOGGER.info(
+ "======================== Executing GetLodgingListingsOperation =======================");
+
+ // Build the occupancy
+ ArrayList rooms = new ArrayList<>();
+ // The first room, with 1 adult
+ rooms.add(Room.builder().adults(1L).build());
+ // The second room, with 2 adults and 2 children
+ ArrayList childrenAges = new ArrayList<>();
+ childrenAges.add(10L);
+ childrenAges.add(12L);
+ rooms.add(Room.builder().adults(2L).childAges(childrenAges).build());
+
+ // Build the query parameters with GetLodgingListingsOperationParams
+ GetLodgingListingsOperationParams getLodgingListingsOperationParams =
+ GetLodgingListingsOperationParams.builder()
+ .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ // The location keyword can be a city, address, airport or a landmark.
+ .locationKeyword("Space Needle, Seattle")
+ // The radius specifies the size of search area around the location keyword.
+ // The default value is 25.
+ .radius(10)
+ // The unit specifies the unit of the radius. The default value is KM.
+ .unit(GetLodgingListingsOperationParams.Unit.KM)
+ // Check-in 5 days from now
+ .checkIn(LocalDate.now().plusDays(5))
+ // Check-out 10 days from now
+ .checkOut(LocalDate.now().plusDays(10))
+ // The occupancy
+ .rooms(rooms)
+ // The links to return, WEB includes WS (Web Search Result Page)
+ // and WD (Web Details Page)
+ .links(Collections.singletonList(GetLodgingListingsOperationParams.Links.WEB))
+ // Limit the results to 5 properties
+ .limit(5)
+ // Order the results by price in ascending order
+ .sortType(GetLodgingListingsOperationParams.SortType.PRICE)
+ .sortOrder(GetLodgingListingsOperationParams.SortOrder.ASC)
+ .build();
+
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the HotelListingsResponse
+ HotelListingsResponse hotelListingsResponse =
+ xapClient.execute(new GetLodgingListingsOperation(getLodgingListingsOperationParams))
+ .getData();
+
+ // If you want to use the async method, you can use the following code:
+ // ---------------------------------------------------------------
+ // CompletableFuture> completableFuture =
+ // xapClient.executeAsync(
+ // new GetLodgingListingsOperation(getLodgingListingsOperationParams));
+ // completableFuture.thenAccept(hotelListingsResponse -> {
+ // // Your code here
+ // });
+ // ---------------------------------------------------------------
+
+ LOGGER.info(
+ "======================== GetLodgingListingsOperation Executed ========================");
+
+ if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
+ || hotelListingsResponse.getHotels().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
}
- if (roomType.getLinks() != null) {
- // To get the deeplink to the Expedia Web Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the Expedia Web Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
- }
- }
- LOGGER.info(
- "==================================== Property End ====================================");
- });
-
- LOGGER.info(
- "============================ End ListingsQuickStartScenario ===========================");
- }
+
+ // The HotelListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", hotelListingsResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of hotel properties
+ hotelListingsResponse.getHotels().forEach(hotel -> {
+ // Check if the property is available
+ if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
+ LOGGER.info("Property {} is not available.", hotel.getId());
+ return;
+ }
+ LOGGER.info(
+ "=================================== Property Start ===================================");
+ // To get the property name
+ if (StringUtils.isNotEmpty(hotel.getName())) {
+ LOGGER.info("Property Name: {}", hotel.getName());
+ }
+ // To get the property address
+ if (hotel.getLocation() != null) {
+ LOGGER.info("Property Address: {}", hotel.getLocation().getAddress());
+ }
+ // To get the property thumbnail URL
+ if (StringUtils.isNotEmpty(hotel.getThumbnailUrl())) {
+ LOGGER.info("Thumbnail URL: {}", hotel.getThumbnailUrl());
+ }
+ // To get the star rating of the property. The value is between 1.0 and 5.0
+ // in a 0.5 increment.
+ if (hotel.getStarRating() != null) {
+ LOGGER.info("Star Rating: {}", hotel.getStarRating().getValue());
+ }
+ // To get the guest rating of the property. The value is between 1.0 and 5.0
+ // in a 0.1 increment.
+ if (StringUtils.isNotEmpty(hotel.getGuestRating())) {
+ LOGGER.info("Guest Rating: {}", hotel.getGuestRating());
+ }
+ // To get the total number of reviews for the property
+ if (hotel.getGuestReviewCount() != null) {
+ LOGGER.info("Review Count: {}", hotel.getGuestReviewCount());
+ }
+ if (hotel.getRoomTypes() != null && !hotel.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ RoomType roomType = hotel.getRoomTypes().get(0);
+ if (StringUtils.isNotEmpty(roomType.getDescription())) {
+ LOGGER.info("Room Type: {}", roomType.getDescription());
+ }
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}",
+ roomType.getPrice().getTotalPrice().getValue(),
+ roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}",
+ roomType.getPrice().getAvgNightlyRate().getValue(),
+ roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
+ && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}",
+ roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the Expedia Web Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}",
+ roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the Expedia Web Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info(
+ "==================================== Property End ====================================");
+ });
+
+ LOGGER.info(
+ "============================ End ListingsQuickStartScenario ===========================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java
index a4fa86f8b..1702066c2 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java
@@ -38,124 +38,124 @@
*/
public class QuotesQuickStartScenario implements VrboScenario {
- private static final Logger LOGGER = LoggerFactory.getLogger(QuotesQuickStartScenario.class);
-
- public static void main(String[] args) {
- new QuotesQuickStartScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- // This example will get quotes response for mentioned Expedia properties with the following
- // criteria:
- // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
- // in the second room;
- // 3. Check-in date 5 days from now, check-out date 10 days from now;
- // 4. Return web links to Expedia website;
-
- LOGGER.info(
- "============================ Running QuotesQuickStartScenario ==========================");
-
- LOGGER.info(
- "========================= Executing GetLodgingQuotesOperation =========================");
-
- // Build the occupancy
- ArrayList rooms = new ArrayList<>();
- // The first room, with 2 adult
- rooms.add(Room.builder().adults(2L).childAges(null).build());
-
- // Build the query parameters with GetLodgingQuotesOperationParams
- GetLodgingQuotesOperationParams quotesOperationParams =
- GetLodgingQuotesOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
- // Check-in 5 days from now
- .checkIn(LocalDate.now().plusDays(5))
- // Check-out 10 days from now
- .checkOut(LocalDate.now().plusDays(10))
- // Set of Expedia Property IDs.
- .propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201")))
- // The links to return, WEB includes WS (Web Search Result Page) and
- // WD (Web Details Page)
- .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB))
- .rooms(rooms)
- .build();
-
- XapClient xapClient = createClient();
-
- // Execute the operation and get the QuotesResponse
- LodgingQuotesResponse quotesResponse =
- xapClient.execute(new GetLodgingQuotesOperation(quotesOperationParams)).getData();
-
- // If you want to use the async method, you can use the following code:
- // ---------------------------------------------------------------
- // CompletableFuture> completableFuture =
- // xapClient.executeAsync(
- // new GetLodgingQuotesOperation(quotesOperationParams));
- // completableFuture.thenAccept(quotesResponse -> {
- // // Your code here
- // });
- // ---------------------------------------------------------------
-
- LOGGER.info(
- "========================== GetLodgingQuotesOperation Executed =========================");
-
- if (quotesResponse == null || quotesResponse.getProperties() == null
- || quotesResponse.getProperties().isEmpty()) {
- throw new IllegalStateException("No properties found.");
+ private static final Logger LOGGER = LoggerFactory.getLogger(QuotesQuickStartScenario.class);
+
+ public static void main(String[] args) {
+ new QuotesQuickStartScenario().run();
+ System.exit(0);
}
- // The LodgingQuotesResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", quotesResponse.getTransactionId());
-
- // To access the properties, iterate through the list of properties
- quotesResponse.getProperties().forEach(quote -> {
- LOGGER.info("========== Property:{} Start ==========", quote.getId());
- if (Property.Status.AVAILABLE != quote.getStatus()) {
- LOGGER.info("Property is not available.");
- return;
- }
- if (quote.getRoomTypes() != null && !quote.getRoomTypes().isEmpty()) {
- // To get the first room type information
- LodgingRoomType roomType = quote.getRoomTypes().get(0);
-
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
- }
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
- }
- if (roomType.getLinks() != null) {
- // To get the deeplink to the Expedia Web Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the Expedia Web Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
+ @Override
+ public void run() {
+ // This example will get quotes response for mentioned Expedia properties with the following
+ // criteria:
+ // 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
+ // in the second room;
+ // 3. Check-in date 5 days from now, check-out date 10 days from now;
+ // 4. Return web links to Expedia website;
+
+ LOGGER.info(
+ "============================ Running QuotesQuickStartScenario ==========================");
+
+ LOGGER.info(
+ "========================= Executing GetLodgingQuotesOperation =========================");
+
+ // Build the occupancy
+ ArrayList rooms = new ArrayList<>();
+ // The first room, with 2 adult
+ rooms.add(Room.builder().adults(2L).childAges(null).build());
+
+ // Build the query parameters with GetLodgingQuotesOperationParams
+ GetLodgingQuotesOperationParams quotesOperationParams =
+ GetLodgingQuotesOperationParams.builder()
+ .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ // Check-in 5 days from now
+ .checkIn(LocalDate.now().plusDays(5))
+ // Check-out 10 days from now
+ .checkOut(LocalDate.now().plusDays(10))
+ // Set of Expedia Property IDs.
+ .propertyIds(new HashSet<>(Arrays.asList("87704892", "36960201")))
+ // The links to return, WEB includes WS (Web Search Result Page) and
+ // WD (Web Details Page)
+ .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB))
+ .rooms(rooms)
+ .build();
+
+ XapClient xapClient = createClient();
+
+ // Execute the operation and get the QuotesResponse
+ LodgingQuotesResponse quotesResponse =
+ xapClient.execute(new GetLodgingQuotesOperation(quotesOperationParams)).getData();
+
+ // If you want to use the async method, you can use the following code:
+ // ---------------------------------------------------------------
+ // CompletableFuture> completableFuture =
+ // xapClient.executeAsync(
+ // new GetLodgingQuotesOperation(quotesOperationParams));
+ // completableFuture.thenAccept(quotesResponse -> {
+ // // Your code here
+ // });
+ // ---------------------------------------------------------------
+
+ LOGGER.info(
+ "========================== GetLodgingQuotesOperation Executed =========================");
+
+ if (quotesResponse == null || quotesResponse.getProperties() == null
+ || quotesResponse.getProperties().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
}
- }
- LOGGER.info(
- "=================================== Property End ===================================");
- });
-
- LOGGER.info(
- "============================= End QuotesQuickStartScenario ============================");
- }
+
+ // The LodgingQuotesResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", quotesResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of properties
+ quotesResponse.getProperties().forEach(quote -> {
+ LOGGER.info("========== Property:{} Start ==========", quote.getId());
+ if (Property.Status.AVAILABLE != quote.getStatus()) {
+ LOGGER.info("Property is not available.");
+ return;
+ }
+ if (quote.getRoomTypes() != null && !quote.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ LodgingRoomType roomType = quote.getRoomTypes().get(0);
+
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}",
+ roomType.getPrice().getTotalPrice().getValue(),
+ roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}",
+ roomType.getPrice().getAvgNightlyRate().getValue(),
+ roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
+ && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}",
+ roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the Expedia Web Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}",
+ roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the Expedia Web Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info(
+ "=================================== Property End ===================================");
+ });
+
+ LOGGER.info(
+ "============================= End QuotesQuickStartScenario ============================");
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java
index 0d5ff3731..8c8e57c44 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboPropertySearchEndToEndScenario.java
@@ -16,7 +16,7 @@
package com.expediagroup.sdk.xap.examples.scenarios.lodging;
-import com.expediagroup.sdk.core.model.Response;
+import com.expediagroup.sdk.rest.model.Response;
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.models.LodgingQuotesResponse;
import com.expediagroup.sdk.xap.models.LodgingRoomType;
@@ -59,192 +59,262 @@
*/
public class VrboPropertySearchEndToEndScenario implements VrboScenario {
- private final XapClient client = createClient();
-
- private static final Logger LOGGER =
- LoggerFactory.getLogger(VrboPropertySearchEndToEndScenario.class);
-
- /**
- * This field limits the number of line to read from the SDP DownloadURL API Listings file to
- * reduce time to run the example.
- * If the first 20 properties from the file are not accessible OR available when you run this
- * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
- * you can adjust the property count to get more properties.
- */
- private static final int SAMPLE_ITEMS_RESTRICTION = 20;
-
- /**
- * A property id to location map. This mocks a cache in this example to store the static content
- * of the properties.
- */
- private static final Map PROPERTY_ID_AND_LOCATION_CACHE = new HashMap<>();
-
- public static void main(String[] args) {
- new VrboPropertySearchEndToEndScenario().run();
- System.exit(0);
- }
-
- @Override
- public void run() {
- LOGGER.info(
- "====================== Running VrboPropertySearchEndToEndScenario ======================");
-
- List propertyIds = getPropertyIdsFromDownloadUrl();
- cachePropertyLocationFromDownloadUrl(propertyIds);
- LodgingQuotesResponse lodgingQuotesResponse = getPropertyPriceFromLodgingQuotes(propertyIds);
- displayResult(lodgingQuotesResponse);
-
- LOGGER.info(
- "======================= End VrboPropertySearchEndToEndScenario =========================");
- }
-
- private List getPropertyIdsFromDownloadUrl() {
- LOGGER.info(
- "==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
-
- GetFeedDownloadUrlOperationParams getPropertyIdListParams =
- GetFeedDownloadUrlOperationParams.builder()
- // Use the type VACATION_RENTAL to get the list of accessible Vrbo property ids.
- .type(GetFeedDownloadUrlOperationParams.Type.VACATION_RENTAL)
- // Without any filters, this operation will return the information of all Vrbo
- // properties in en_US by default.
- .build();
-
- Response downloadUrlListingsResponse =
- client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
-
- if (downloadUrlListingsResponse.getData() == null
- || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
- throw new IllegalStateException("No vacation rental file found");
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(VrboPropertySearchEndToEndScenario.class);
+ /**
+ * This field limits the number of line to read from the SDP DownloadURL API Listings file to
+ * reduce time to run the example.
+ * If the first 20 properties from the file are not accessible OR available when you run this
+ * example, it may end with "No accessible property ids found." OR NO_RESULT_FOUND. In that case,
+ * you can adjust the property count to get more properties.
+ */
+ private static final int SAMPLE_ITEMS_RESTRICTION = 20;
+ /**
+ * A property id to location map. This mocks a cache in this example to store the static content
+ * of the properties.
+ */
+ private static final Map PROPERTY_ID_AND_LOCATION_CACHE = new HashMap<>();
+ private final XapClient client = createClient();
+
+ public static void main(String[] args) {
+ new VrboPropertySearchEndToEndScenario().run();
+ System.exit(0);
}
- // The download URL points to a zip file containing various jsonl files.
- // Each line in the jsonl files contains a json object representing a Vrbo property.
- // For demonstration purposes, we will only read a few properties from the file without
- // downloading the entire file.
- String vacationRentalDownloadUrl = downloadUrlListingsResponse.getData()
- .getBestMatchedFile()
- .getDownloadUrl();
- LOGGER.info("Vacation Rental Download URL: {}", vacationRentalDownloadUrl);
-
- // Read property ids from the file.
- List propertyIds = getPropertyIdsFromVacationRentalFile(vacationRentalDownloadUrl
- );
-
- if (propertyIds.isEmpty()) {
- throw new IllegalStateException("No accessible Vrbo property ids found.");
+ /**
+ * Display the result of the operations.
+ *
+ * @param lodgingQuotesResponse The response of the Lodging Quotes API.
+ */
+ private static void displayResult(LodgingQuotesResponse lodgingQuotesResponse) {
+ LOGGER.info("======================= Executing Step IV: DisplayResult =======================");
+ if (lodgingQuotesResponse == null || lodgingQuotesResponse.getProperties() == null
+ || lodgingQuotesResponse.getProperties().isEmpty()) {
+ throw new IllegalStateException("No properties found.");
+ }
+
+ // The HotelListingsResponse contains a transaction ID for troubleshooting
+ LOGGER.info("Transaction ID: {}", lodgingQuotesResponse.getTransactionId());
+
+ // To access the properties, iterate through the list of hotel properties
+ lodgingQuotesResponse.getProperties().forEach(property -> {
+ // Check if the property is available
+ if (Property.Status.AVAILABLE != property.getStatus()) {
+ LOGGER.info("Property {} is not available.", property.getId());
+ return;
+ }
+ LOGGER.info(
+ "=================================== Property Start ===================================");
+ String propertyId = property.getId();
+
+ // Get the location content of the property from the cache
+ LOGGER.info("Property Id: {}", propertyId);
+ LOGGER.info("Cached Property Location: {}", PROPERTY_ID_AND_LOCATION_CACHE.get(propertyId));
+
+ // Get the price of the property from the room type
+ if (property.getRoomTypes() != null && !property.getRoomTypes().isEmpty()) {
+ // To get the first room type information
+ LodgingRoomType roomType = property.getRoomTypes().get(0);
+
+ if (roomType.getPrice() != null) {
+ // To get the total price of the room type
+ if (roomType.getPrice().getTotalPrice() != null) {
+ LOGGER.info("Price: {}, Currency: {}",
+ roomType.getPrice().getTotalPrice().getValue(),
+ roomType.getPrice().getTotalPrice().getCurrency());
+ }
+ // To get the average nightly rate of the room type
+ if (roomType.getPrice().getAvgNightlyRate() != null) {
+ LOGGER.info("Average Nightly Rate: {}, Currency: {}",
+ roomType.getPrice().getAvgNightlyRate().getValue(),
+ roomType.getPrice().getAvgNightlyRate().getCurrency());
+ }
+ }
+ // To get the free cancellation flag of the selected room
+ if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
+ && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
+ LOGGER.info("Free Cancellation: {}",
+ roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
+ }
+ if (roomType.getLinks() != null) {
+ // To get the deeplink to the website Search Result Page
+ if (roomType.getLinks().getWebSearchResult() != null) {
+ LOGGER.info("WebSearchResult Link: {}",
+ roomType.getLinks().getWebSearchResult().getHref());
+ }
+ // To get the deeplink to the website Details Page
+ if (roomType.getLinks().getWebDetails() != null) {
+ LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
+ }
+ }
+ }
+ LOGGER.info(
+ "==================================== Property End ====================================");
+ });
+ LOGGER.info("======================= Step IV: DisplayResult Executed ========================");
}
- LOGGER.info("Accessible Vrbo Property Ids: {}", propertyIds);
-
- LOGGER.info(
- "==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
- return propertyIds;
- }
-
- /**
- * Cache the location content from SDP DownloadURL API.
- *
- * @param propertyIds The property ids that need the location content.
- */
- private void cachePropertyLocationFromDownloadUrl(List propertyIds) {
- LOGGER.info(
- "================ Executing Step II: CachePropertyLocationFromDownloadUrl ===============");
- GetFeedDownloadUrlOperationParams getPropertyLocationParams =
- GetFeedDownloadUrlOperationParams.builder()
- // Use the type LOCATIONS to get the address of accessible properties.
- .type(GetFeedDownloadUrlOperationParams.Type.LOCATIONS)
- // Filter the properties by brand.
- .brand(GetFeedDownloadUrlOperationParams.Brand.VRBO)
- .build();
-
- Response downloadUrlLocationsResponse =
- client.execute(new GetFeedDownloadUrlOperation(getPropertyLocationParams));
-
- if (downloadUrlLocationsResponse.getData() == null
- || downloadUrlLocationsResponse.getData().getBestMatchedFile() == null) {
- throw new IllegalStateException("No location file found");
+
+ @Override
+ public void run() {
+ LOGGER.info(
+ "====================== Running VrboPropertySearchEndToEndScenario ======================");
+
+ List propertyIds = getPropertyIdsFromDownloadUrl();
+ cachePropertyLocationFromDownloadUrl(propertyIds);
+ LodgingQuotesResponse lodgingQuotesResponse = getPropertyPriceFromLodgingQuotes(propertyIds);
+ displayResult(lodgingQuotesResponse);
+
+ LOGGER.info(
+ "======================= End VrboPropertySearchEndToEndScenario =========================");
}
- String locationsDownloadUrl = downloadUrlLocationsResponse.getData()
- .getBestMatchedFile()
- .getDownloadUrl();
- LOGGER.info("Locations Download URL: {}", locationsDownloadUrl);
-
- // Read and cache property locations from the file.
- cachePropertyLocationFromLocationsFile(locationsDownloadUrl, propertyIds);
-
- LOGGER.info(
- "================= Step II: CachePropertyLocationFromDownloadUrl Executed ===============");
- }
-
- /**
- * Get prices of the properties using the Lodging Quotes API.
- *
- * @param propertyIds The property ids to get the prices.
- * @return The response of the Lodging Quotes API.
- */
- private LodgingQuotesResponse getPropertyPriceFromLodgingQuotes(List propertyIds) {
- LOGGER.info(
- "================= Executing Step III: GetPropertyPriceFromLodgingQuotes ================");
-
- // Build the occupancy
- ArrayList rooms = new ArrayList<>();
- // The first room, with 2 adult
- rooms.add(Room.builder().adults(2L).childAges(null).build());
-
- // Build the query parameters with GetLodgingQuotesOperationParams
- GetLodgingQuotesOperationParams quotesOperationParams =
- GetLodgingQuotesOperationParams.builder()
- .partnerTransactionId(PARTNER_TRANSACTION_ID)
- // Check-in 5 days from now
- .checkIn(LocalDate.now().plusDays(5))
- // Check-out 10 days from now
- .checkOut(LocalDate.now().plusDays(10))
- // Set of Expedia Property IDs.
- .propertyIds(new HashSet<>(propertyIds))
- // The links to return, WEB includes WS (Web Search Result Page) and
- // WD (Web Details Page)
- .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB))
- .rooms(rooms)
- .build();
-
- LodgingQuotesResponse lodgingQuotesResponse =
- client.execute(new GetLodgingQuotesOperation(quotesOperationParams))
- .getData();
-
- LOGGER.info(
- "================= Step III: GetPropertyPriceFromLodgingQuotes Executed =================");
- return lodgingQuotesResponse;
- }
-
- /**
- * Reads given number of property ids from the file pointed by the download URL.
- *
- * @param downloadUrl The download URL of the zip file containing the property information.
- * @return A list of property ids read from the file.
- */
- private List getPropertyIdsFromVacationRentalFile(String downloadUrl) {
- List propertyIds = new ArrayList<>();
- HttpURLConnection connection = null;
- try {
- // Open a connection to the URL
- URL url = new URL(downloadUrl);
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.setDoInput(true);
-
- try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- if (entry.getName().endsWith(".jsonl")) {
- LOGGER.info("Reading property ids from file: {}", entry.getName());
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
- String line;
- ObjectMapper objectMapper = new ObjectMapper();
- while ((line = reader.readLine()) != null
- && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
- // Parse the property id from the json object
- // An example json line from the jsonl file:
+ private List getPropertyIdsFromDownloadUrl() {
+ LOGGER.info(
+ "==================== Executing Step I: getPropertyIdsFromDownloadUrl ===================");
+
+ GetFeedDownloadUrlOperationParams getPropertyIdListParams =
+ GetFeedDownloadUrlOperationParams.builder()
+ // Use the type VACATION_RENTAL to get the list of accessible Vrbo property ids.
+ .type(GetFeedDownloadUrlOperationParams.Type.VACATION_RENTAL)
+ // Without any filters, this operation will return the information of all Vrbo
+ // properties in en_US by default.
+ .build();
+
+ Response downloadUrlListingsResponse =
+ client.execute(new GetFeedDownloadUrlOperation(getPropertyIdListParams));
+
+ if (downloadUrlListingsResponse.getData() == null
+ || downloadUrlListingsResponse.getData().getBestMatchedFile() == null) {
+ throw new IllegalStateException("No vacation rental file found");
+ }
+
+ // The download URL points to a zip file containing various jsonl files.
+ // Each line in the jsonl files contains a json object representing a Vrbo property.
+ // For demonstration purposes, we will only read a few properties from the file without
+ // downloading the entire file.
+ String vacationRentalDownloadUrl = downloadUrlListingsResponse.getData()
+ .getBestMatchedFile()
+ .getDownloadUrl();
+ LOGGER.info("Vacation Rental Download URL: {}", vacationRentalDownloadUrl);
+
+ // Read property ids from the file.
+ List propertyIds = getPropertyIdsFromVacationRentalFile(vacationRentalDownloadUrl
+ );
+
+ if (propertyIds.isEmpty()) {
+ throw new IllegalStateException("No accessible Vrbo property ids found.");
+ }
+ LOGGER.info("Accessible Vrbo Property Ids: {}", propertyIds);
+
+ LOGGER.info(
+ "==================== Step I: getPropertyIdsFromDownloadUrl Executed ====================");
+ return propertyIds;
+ }
+
+ /**
+ * Cache the location content from SDP DownloadURL API.
+ *
+ * @param propertyIds The property ids that need the location content.
+ */
+ private void cachePropertyLocationFromDownloadUrl(List propertyIds) {
+ LOGGER.info(
+ "================ Executing Step II: CachePropertyLocationFromDownloadUrl ===============");
+ GetFeedDownloadUrlOperationParams getPropertyLocationParams =
+ GetFeedDownloadUrlOperationParams.builder()
+ // Use the type LOCATIONS to get the address of accessible properties.
+ .type(GetFeedDownloadUrlOperationParams.Type.LOCATIONS)
+ // Filter the properties by brand.
+ .brand(GetFeedDownloadUrlOperationParams.Brand.VRBO)
+ .build();
+
+ Response downloadUrlLocationsResponse =
+ client.execute(new GetFeedDownloadUrlOperation(getPropertyLocationParams));
+
+ if (downloadUrlLocationsResponse.getData() == null
+ || downloadUrlLocationsResponse.getData().getBestMatchedFile() == null) {
+ throw new IllegalStateException("No location file found");
+ }
+
+ String locationsDownloadUrl = downloadUrlLocationsResponse.getData()
+ .getBestMatchedFile()
+ .getDownloadUrl();
+ LOGGER.info("Locations Download URL: {}", locationsDownloadUrl);
+
+ // Read and cache property locations from the file.
+ cachePropertyLocationFromLocationsFile(locationsDownloadUrl, propertyIds);
+
+ LOGGER.info(
+ "================= Step II: CachePropertyLocationFromDownloadUrl Executed ===============");
+ }
+
+ /**
+ * Get prices of the properties using the Lodging Quotes API.
+ *
+ * @param propertyIds The property ids to get the prices.
+ * @return The response of the Lodging Quotes API.
+ */
+ private LodgingQuotesResponse getPropertyPriceFromLodgingQuotes(List propertyIds) {
+ LOGGER.info(
+ "================= Executing Step III: GetPropertyPriceFromLodgingQuotes ================");
+
+ // Build the occupancy
+ ArrayList rooms = new ArrayList<>();
+ // The first room, with 2 adult
+ rooms.add(Room.builder().adults(2L).childAges(null).build());
+
+ // Build the query parameters with GetLodgingQuotesOperationParams
+ GetLodgingQuotesOperationParams quotesOperationParams =
+ GetLodgingQuotesOperationParams.builder()
+ .partnerTransactionId(PARTNER_TRANSACTION_ID)
+ // Check-in 5 days from now
+ .checkIn(LocalDate.now().plusDays(5))
+ // Check-out 10 days from now
+ .checkOut(LocalDate.now().plusDays(10))
+ // Set of Expedia Property IDs.
+ .propertyIds(new HashSet<>(propertyIds))
+ // The links to return, WEB includes WS (Web Search Result Page) and
+ // WD (Web Details Page)
+ .links(Collections.singletonList(GetLodgingQuotesOperationParams.Links.WEB))
+ .rooms(rooms)
+ .build();
+
+ LodgingQuotesResponse lodgingQuotesResponse =
+ client.execute(new GetLodgingQuotesOperation(quotesOperationParams))
+ .getData();
+
+ LOGGER.info(
+ "================= Step III: GetPropertyPriceFromLodgingQuotes Executed =================");
+ return lodgingQuotesResponse;
+ }
+
+ /**
+ * Reads given number of property ids from the file pointed by the download URL.
+ *
+ * @param downloadUrl The download URL of the zip file containing the property information.
+ * @return A list of property ids read from the file.
+ */
+ private List getPropertyIdsFromVacationRentalFile(String downloadUrl) {
+ List propertyIds = new ArrayList<>();
+ HttpURLConnection connection = null;
+ try {
+ // Open a connection to the URL
+ URL url = new URL(downloadUrl);
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setDoInput(true);
+
+ try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ if (entry.getName().endsWith(".jsonl")) {
+ LOGGER.info("Reading property ids from file: {}", entry.getName());
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
+ String line;
+ ObjectMapper objectMapper = new ObjectMapper();
+ while ((line = reader.readLine()) != null
+ && propertyIds.size() < SAMPLE_ITEMS_RESTRICTION) {
+ // Parse the property id from the json object
+ // An example json line from the jsonl file:
/*
{
"propertyId": {
@@ -290,52 +360,52 @@ private List getPropertyIdsFromVacationRentalFile(String downloadUrl) {
"propertyLiveDate": "2022-05-31"
}
*/
- JsonNode jsonNode = objectMapper.readTree(line);
- propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
- }
+ JsonNode jsonNode = objectMapper.readTree(line);
+ propertyIds.add(jsonNode.get("propertyId").get("expedia").asText());
+ }
+ }
+ }
+ }
+ }
+
+ } catch (IOException e) {
+ LOGGER.error("Error reading property ids from download URL", e);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
}
- }
}
- }
-
- } catch (IOException e) {
- LOGGER.error("Error reading property ids from download URL", e);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
+ return propertyIds;
}
- return propertyIds;
- }
-
- /**
- * Caches the location content of the properties from the file pointed by the download URL.
- *
- * @param locationsDownloadUrl The download URL of the zip file containing the property locations.
- * @param propertyIds The property ids to get the location content.
- */
- private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
- List propertyIds) {
- HttpURLConnection connection = null;
- try {
- // Open a connection to the URL
- URL url = new URL(locationsDownloadUrl);
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.setDoInput(true);
-
- try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- if (entry.getName().endsWith(".jsonl")) {
- LOGGER.info("Reading property locations from file: {}", entry.getName());
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
- String line;
- ObjectMapper objectMapper = new ObjectMapper();
- while ((line = reader.readLine()) != null
- && PROPERTY_ID_AND_LOCATION_CACHE.size() < propertyIds.size()) {
- // Parse the property location from the json object
- // An example json line from the jsonl file:
+
+ /**
+ * Caches the location content of the properties from the file pointed by the download URL.
+ *
+ * @param locationsDownloadUrl The download URL of the zip file containing the property locations.
+ * @param propertyIds The property ids to get the location content.
+ */
+ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
+ List propertyIds) {
+ HttpURLConnection connection = null;
+ try {
+ // Open a connection to the URL
+ URL url = new URL(locationsDownloadUrl);
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setDoInput(true);
+
+ try (ZipInputStream zipStream = new ZipInputStream(connection.getInputStream())) {
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ if (entry.getName().endsWith(".jsonl")) {
+ LOGGER.info("Reading property locations from file: {}", entry.getName());
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream))) {
+ String line;
+ ObjectMapper objectMapper = new ObjectMapper();
+ while ((line = reader.readLine()) != null
+ && PROPERTY_ID_AND_LOCATION_CACHE.size() < propertyIds.size()) {
+ // Parse the property location from the json object
+ // An example json line from the jsonl file:
/*
{
"propertyId": {
@@ -386,106 +456,33 @@ private void cachePropertyLocationFromLocationsFile(String locationsDownloadUrl,
}
}
*/
- JsonNode jsonNode = objectMapper.readTree(line);
- // Check if the property id is in the list
- if (propertyIds.contains(jsonNode.get("propertyId").get("expedia").asText())) {
- // Get the location content of the property
- String location = jsonNode.get("propertyName").asText() + ", "
- + jsonNode.get("city").asText() + ", "
- + jsonNode.get("province").asText() + ", "
- + jsonNode.get("country").asText();
- // Store the location content in the cache
- PROPERTY_ID_AND_LOCATION_CACHE.put(
- jsonNode.get("propertyId")
- .get("expedia")
- .asText(),
- location);
+ JsonNode jsonNode = objectMapper.readTree(line);
+ // Check if the property id is in the list
+ if (propertyIds.contains(jsonNode.get("propertyId").get("expedia").asText())) {
+ // Get the location content of the property
+ String location = jsonNode.get("propertyName").asText() + ", "
+ + jsonNode.get("city").asText() + ", "
+ + jsonNode.get("province").asText() + ", "
+ + jsonNode.get("country").asText();
+ // Store the location content in the cache
+ PROPERTY_ID_AND_LOCATION_CACHE.put(
+ jsonNode.get("propertyId")
+ .get("expedia")
+ .asText(),
+ location);
+ }
+ }
+ }
+ }
}
- }
}
- }
- }
- }
-
- } catch (IOException e) {
- LOGGER.error("Error reading property locations from download URL", e);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * Display the result of the operations.
- *
- * @param lodgingQuotesResponse The response of the Lodging Quotes API.
- */
- private static void displayResult(LodgingQuotesResponse lodgingQuotesResponse) {
- LOGGER.info("======================= Executing Step IV: DisplayResult =======================");
- if (lodgingQuotesResponse == null || lodgingQuotesResponse.getProperties() == null
- || lodgingQuotesResponse.getProperties().isEmpty()) {
- throw new IllegalStateException("No properties found.");
- }
- // The HotelListingsResponse contains a transaction ID for troubleshooting
- LOGGER.info("Transaction ID: {}", lodgingQuotesResponse.getTransactionId());
-
- // To access the properties, iterate through the list of hotel properties
- lodgingQuotesResponse.getProperties().forEach(property -> {
- // Check if the property is available
- if (Property.Status.AVAILABLE != property.getStatus()) {
- LOGGER.info("Property {} is not available.", property.getId());
- return;
- }
- LOGGER.info(
- "=================================== Property Start ===================================");
- String propertyId = property.getId();
-
- // Get the location content of the property from the cache
- LOGGER.info("Property Id: {}", propertyId);
- LOGGER.info("Cached Property Location: {}", PROPERTY_ID_AND_LOCATION_CACHE.get(propertyId));
-
- // Get the price of the property from the room type
- if (property.getRoomTypes() != null && !property.getRoomTypes().isEmpty()) {
- // To get the first room type information
- LodgingRoomType roomType = property.getRoomTypes().get(0);
-
- if (roomType.getPrice() != null) {
- // To get the total price of the room type
- if (roomType.getPrice().getTotalPrice() != null) {
- LOGGER.info("Price: {}, Currency: {}",
- roomType.getPrice().getTotalPrice().getValue(),
- roomType.getPrice().getTotalPrice().getCurrency());
- }
- // To get the average nightly rate of the room type
- if (roomType.getPrice().getAvgNightlyRate() != null) {
- LOGGER.info("Average Nightly Rate: {}, Currency: {}",
- roomType.getPrice().getAvgNightlyRate().getValue(),
- roomType.getPrice().getAvgNightlyRate().getCurrency());
- }
- }
- // To get the free cancellation flag of the selected room
- if (roomType.getRatePlans() != null && !roomType.getRatePlans().isEmpty()
- && roomType.getRatePlans().get(0).getCancellationPolicy() != null) {
- LOGGER.info("Free Cancellation: {}",
- roomType.getRatePlans().get(0).getCancellationPolicy().getFreeCancellation());
- }
- if (roomType.getLinks() != null) {
- // To get the deeplink to the website Search Result Page
- if (roomType.getLinks().getWebSearchResult() != null) {
- LOGGER.info("WebSearchResult Link: {}",
- roomType.getLinks().getWebSearchResult().getHref());
- }
- // To get the deeplink to the website Details Page
- if (roomType.getLinks().getWebDetails() != null) {
- LOGGER.info("WebDetails Link: {}", roomType.getLinks().getWebDetails().getHref());
- }
+ } catch (IOException e) {
+ LOGGER.error("Error reading property locations from download URL", e);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
}
- }
- LOGGER.info(
- "==================================== Property End ====================================");
- });
- LOGGER.info("======================= Step IV: DisplayResult Executed ========================");
- }
+ }
}
diff --git a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java
index 6a523f5aa..136ce9536 100644
--- a/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java
+++ b/examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/VrboScenario.java
@@ -16,6 +16,7 @@
package com.expediagroup.sdk.xap.examples.scenarios.lodging;
+import com.expediagroup.sdk.core.auth.basic.BasicAuthCredentials;
import com.expediagroup.sdk.xap.client.XapClient;
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
@@ -25,20 +26,25 @@
*/
public interface VrboScenario extends XapScenario {
- /**
- * Create a client with Vrbo key and secret.
- *
- * @return XapClient
- */
- @Override
- default XapClient createClient() {
- String key = System.getProperty("com.expediagroup.xapjavasdk.vrbokey");
- String secret = System.getProperty("com.expediagroup.xapjavasdk.vrbosecret");
- return XapClient
- .builder()
- .key(key)
- .secret(secret)
- .build();
- }
+ /**
+ * Create a client with Vrbo key and secret.
+ *
+ * @return XapClient
+ */
+ @Override
+ default XapClient createClient() {
+ String key = System.getProperty("com.expediagroup.xapjavasdk.vrbokey");
+ String secret = System.getProperty("com.expediagroup.xapjavasdk.vrbosecret");
+
+ BasicAuthCredentials credentials = new BasicAuthCredentials(key, secret);
+
+ // Or enable OAuth by passing OAuthCredentials instead:
+ // OAuthCredentials credentials = new OAuthCredentials("api-key", "api-secret");
+
+ return XapClient
+ .builder()
+ .credentials(credentials)
+ .build();
+ }
}
diff --git a/settings.gradle.kts b/settings.gradle.kts
index c651721ca..8f2875932 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -16,3 +16,4 @@ plugins {
rootProject.name = "xap-java-sdk"
include("xap-sdk")
include("generator")
+include("examples")
diff --git a/xap-sdk/src/main/kotlin/com/expediagroup/sdk/xap/infrastructure/ApiAbstractions.kt b/xap-sdk/src/main/kotlin/com/expediagroup/sdk/xap/infrastructure/ApiAbstractions.kt
index ae25a7478..35dffb93d 100644
--- a/xap-sdk/src/main/kotlin/com/expediagroup/sdk/xap/infrastructure/ApiAbstractions.kt
+++ b/xap-sdk/src/main/kotlin/com/expediagroup/sdk/xap/infrastructure/ApiAbstractions.kt
@@ -31,13 +31,13 @@ val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
fun toMultiValue(
items: Array,
collectionFormat: String,
- map: (item: T) -> String = defaultMultiValueConverter
+ map: (item: T) -> String = defaultMultiValueConverter,
) = toMultiValue(items.asIterable(), collectionFormat, map)
fun toMultiValue(
items: Iterable,
collectionFormat: String,
- map: (item: T) -> String = defaultMultiValueConverter
+ map: (item: T) -> String = defaultMultiValueConverter,
): List =
when (collectionFormat) {
"multi" -> items.map(map)