Skip to content

Commit cdaedea

Browse files
authored
chore: update examples (#11)
1 parent 88a183a commit cdaedea

File tree

10 files changed

+433
-238
lines changed

10 files changed

+433
-238
lines changed

examples/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@
8686
</execution>
8787
</executions>
8888
</plugin>
89+
<plugin>
90+
<groupId>org.codehaus.mojo</groupId>
91+
<artifactId>exec-maven-plugin</artifactId>
92+
<version>3.3.0</version>
93+
<configuration>
94+
<mainClass>com.expediagroup.sdk.xap.examples.XapSdkDemoApplication</mainClass>
95+
</configuration>
96+
</plugin>
8997
</plugins>
9098
</build>
91-
</project>
99+
</project>

examples/src/main/java/com/expediagroup/sdk/xap/examples/Constants.java

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) 2024 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.sdk.xap.examples;
18+
19+
import com.expediagroup.sdk.xap.examples.scenarios.lodging.GetAvailabilityCalendarsScenario;
20+
import com.expediagroup.sdk.xap.examples.scenarios.lodging.GetListingsScenario;
21+
import com.expediagroup.sdk.xap.examples.scenarios.lodging.GetQuotesScenario;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
/**
26+
* XAP SDK demo application.
27+
*/
28+
public class XapSdkDemoApplication {
29+
private static final Logger logger = LoggerFactory.getLogger(XapSdkDemoApplication.class);
30+
31+
/**
32+
* Main method.
33+
*/
34+
public static void main(String[] args) {
35+
logger.info(
36+
"======================================================================================");
37+
logger.info(
38+
"======================================================================================");
39+
logger.info(
40+
"== ==");
41+
logger.info(
42+
"== Howdy! This is a demonstration of Expedia Group XAP SDK. Enjoy! ==");
43+
logger.info(
44+
"== ==");
45+
logger.info(
46+
"======================================================================================");
47+
logger.info(
48+
"======================================================================================");
49+
50+
logger.info(
51+
"============================== Running Lodging Scenarios =============================");
52+
53+
GetAvailabilityCalendarsScenario getAvailabilityCalendarsScenario =
54+
new GetAvailabilityCalendarsScenario();
55+
getAvailabilityCalendarsScenario.run();
56+
57+
GetListingsScenario getListingsScenario = new GetListingsScenario();
58+
getListingsScenario.run();
59+
60+
GetQuotesScenario getQuotesScenario = new GetQuotesScenario();
61+
getQuotesScenario.run();
62+
63+
logger.info(
64+
"=============================== End of Lodging Scenarios ==============================");
65+
66+
System.exit(0);
67+
}
68+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2024 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.sdk.xap.examples.scenarios;
18+
19+
/**
20+
* Interface for scenarios.
21+
*/
22+
public interface XapScenario {
23+
void run();
24+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2024 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.sdk.xap.examples.scenarios.lodging;
18+
19+
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
20+
import com.expediagroup.sdk.xap.examples.services.LodgingService;
21+
import com.expediagroup.sdk.xap.models.AvailabilityCalendarResponse;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
/**
26+
* This example demonstrates how to use Availability Calendar api with simple search.
27+
*/
28+
public class GetAvailabilityCalendarsScenario implements XapScenario {
29+
30+
private static final Logger LOGGER =
31+
LoggerFactory.getLogger(GetAvailabilityCalendarsScenario.class);
32+
33+
private final LodgingService lodgingService =
34+
new LodgingService();
35+
36+
@Override
37+
public void run() {
38+
// This example returns the availability of each day for a range of dates for given Expedia
39+
// lodging properties.
40+
41+
LOGGER.info(
42+
"====================== Running GetAvailabilityCalendarsScenario ======================");
43+
44+
LOGGER.info(
45+
"================= Executing GetLodgingAvailabilityCalendars Operation ================");
46+
47+
// Execute the operation and get the AvailabilityCalendarsResponse
48+
AvailabilityCalendarResponse availabilityCalendars =
49+
lodgingService.getAvailabilityCalendars();
50+
51+
LOGGER.info(
52+
"================== GetLodgingAvailabilityCalendarsOperation Executed =================");
53+
54+
if (availabilityCalendars == null || availabilityCalendars.getAvailabilityCalendars() == null
55+
|| availabilityCalendars.getAvailabilityCalendars().isEmpty()) {
56+
throw new IllegalStateException("No properties found.");
57+
}
58+
59+
// The AvailabilityCalendarsResponse contains a transaction ID for troubleshooting
60+
LOGGER.info("Transaction ID: {}", availabilityCalendars.getTransactionId());
61+
62+
// To access the properties, iterate through the list of properties
63+
availabilityCalendars.getAvailabilityCalendars().forEach(availCalendar -> {
64+
LOGGER.info("========== Property:{} Start ==========", availCalendar.getPropertyId());
65+
66+
// Availability of property: A string of codes that shows property availability, one for every
67+
// day in the specified date range.
68+
// Valid values include Y (available) and N (unavailable).
69+
LOGGER.info("Availability: {}", availCalendar.getAvailability());
70+
71+
LOGGER.info(
72+
"==================================== Property End ===================================");
73+
74+
LOGGER.info(
75+
"======================== End GetAvailabilityCalendarsScenario =======================");
76+
});
77+
}
78+
}

examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/shopping/listings/ListingsQuickStartExample.java renamed to examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/GetListingsScenario.java

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.expediagroup.sdk.xap.examples.scenarios.lodging.shopping.listings;
17+
package com.expediagroup.sdk.xap.examples.scenarios.lodging;
1818

19-
import com.expediagroup.sdk.xap.examples.Constants;
19+
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
20+
import com.expediagroup.sdk.xap.examples.services.LodgingService;
2021
import com.expediagroup.sdk.xap.models.Hotel;
2122
import com.expediagroup.sdk.xap.models.HotelListingsResponse;
22-
import com.expediagroup.sdk.xap.models.Room;
2323
import com.expediagroup.sdk.xap.models.RoomType;
24-
import com.expediagroup.sdk.xap.operations.GetLodgingListingsOperation;
25-
import com.expediagroup.sdk.xap.operations.GetLodgingListingsOperationParams;
26-
import java.time.LocalDate;
27-
import java.util.ArrayList;
28-
import java.util.Collections;
2924
import org.apache.commons.lang3.StringUtils;
3025
import org.slf4j.Logger;
3126
import org.slf4j.LoggerFactory;
@@ -34,16 +29,14 @@
3429
* This example demonstrates how to search for properties with a location keyword with filters
3530
* applied.
3631
*/
37-
public class ListingsQuickStartExample {
32+
public class GetListingsScenario implements XapScenario {
3833

39-
private static final Logger LOGGER = LoggerFactory.getLogger(ListingsQuickStartExample.class);
34+
private static final Logger LOGGER = LoggerFactory.getLogger(GetListingsScenario.class);
4035

41-
/**
42-
* Summary: main function.
43-
*/
44-
public static void main(String[] args) {
45-
LOGGER.info("========== Start QuickStartExample ==========");
36+
private final LodgingService lodgingService = new LodgingService();
4637

38+
@Override
39+
public void run() {
4740
// This example will search for properties with the following criteria:
4841
// 1. Occupancy of 1 adult in the first room and 2 adults and 2 children (10 and 12 years old)
4942
// in the second room;
@@ -53,58 +46,16 @@ public static void main(String[] args) {
5346
// 5. Limit the results to 5 properties;
5447
// 6. Order the results by price in ascending order.
5548

56-
// Build the occupancy
57-
ArrayList<Room> rooms = new ArrayList<>();
58-
// The first room, with 1 adult
59-
rooms.add(Room.builder().adults(1L).build());
60-
// The second room, with 2 adults and 2 children
61-
ArrayList<Long> childrenAges = new ArrayList<>();
62-
childrenAges.add(10L);
63-
childrenAges.add(12L);
64-
rooms.add(Room.builder().adults(2L).childAges(childrenAges).build());
49+
LOGGER.info(
50+
"============================= Running GetListingsScenario ============================");
6551

66-
// Build the query parameters with GetLodgingListingsOperationParams
67-
GetLodgingListingsOperationParams getLodgingListingsOperationParams =
68-
GetLodgingListingsOperationParams.builder()
69-
.partnerTransactionId(Constants.PARTNER_TRANSACTION_ID)
70-
// The location keyword can be a city, address, airport or a landmark.
71-
.locationKeyword("Space Needle, Seattle")
72-
// The radius specifies the size of search area around the location keyword.
73-
// The default value is 25.
74-
.radius(10)
75-
// The unit specifies the unit of the radius. The default value is KM.
76-
.unit(GetLodgingListingsOperationParams.Unit.KM)
77-
// Check-in 5 days from now
78-
.checkIn(LocalDate.now().plusDays(5))
79-
// Check-out 10 days from now
80-
.checkOut(LocalDate.now().plusDays(10))
81-
// The occupancy
82-
.rooms(rooms)
83-
// The links to return, WEB includes WS (Web Search Result Page)
84-
// and WD (Web Details Page)
85-
.links(Collections.singletonList(GetLodgingListingsOperationParams.Links.WEB))
86-
// Limit the results to 5 properties
87-
.limit(5)
88-
// Order the results by price in ascending order
89-
.sortType(GetLodgingListingsOperationParams.SortType.PRICE)
90-
.sortOrder(GetLodgingListingsOperationParams.SortOrder.ASC)
91-
.build();
52+
LOGGER.info(
53+
"======================== Executing GetLodgingListingsOperation =======================");
9254

93-
// Execute the operation and get the HotelListingsResponse
94-
LOGGER.info("========== Executing GetLodgingListingsOperation ==========");
95-
HotelListingsResponse hotelListingsResponse = Constants.XAP_CLIENT.execute(
96-
new GetLodgingListingsOperation(getLodgingListingsOperationParams)).getData();
97-
// If you want to use the async method, you can use the following code:
98-
// ---------------------------------------------------------------
99-
// CompletableFuture<Response<HotelListingsResponse>> completableFuture =
100-
// Constants.XAP_CLIENT.executeAsync(
101-
// new GetLodgingListingsOperation(getLodgingListingsOperationParams));
102-
// completableFuture.thenAccept(hotelListingsResponse -> {
103-
// // Your code here
104-
// });
105-
// ---------------------------------------------------------------
55+
HotelListingsResponse hotelListingsResponse = lodgingService.getListings();
10656

107-
LOGGER.info("========== GetLodgingListingsOperation Executed ==========");
57+
LOGGER.info(
58+
"======================== GetLodgingListingsOperation Executed ========================");
10859

10960
if (hotelListingsResponse == null || hotelListingsResponse.getHotels() == null
11061
|| hotelListingsResponse.getHotels().isEmpty()) {
@@ -116,7 +67,8 @@ public static void main(String[] args) {
11667

11768
// To access the properties, iterate through the list of hotel properties
11869
hotelListingsResponse.getHotels().forEach(hotel -> {
119-
LOGGER.info("========== Property Start ==========");
70+
LOGGER.info(
71+
"=================================== Property Start ===================================");
12072
// Check if the property is available
12173
if (Hotel.Status.AVAILABLE != hotel.getStatus()) {
12274
LOGGER.info("Property is not available.");
@@ -186,10 +138,11 @@ public static void main(String[] args) {
186138
}
187139
}
188140
}
189-
LOGGER.info("========== Property End ==========");
141+
LOGGER.info(
142+
"==================================== Property End ====================================");
190143
});
191144

192-
LOGGER.info("========== End QuickStartExample ==========");
193-
System.exit(0);
145+
LOGGER.info(
146+
"=============================== End GetListingsScenario ==============================");
194147
}
195148
}

0 commit comments

Comments
 (0)