Skip to content

Commit 8577b28

Browse files
Simon-Wong-hjzSimon Jingzhe Huang
andauthored
chore: restructure examples (#22)
Co-authored-by: Simon Jingzhe Huang <[email protected]>
1 parent 7817490 commit 8577b28

File tree

13 files changed

+379
-397
lines changed

13 files changed

+379
-397
lines changed

.github/workflows/run-examples.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ jobs:
5757
working-directory: sdk-repo/examples
5858
run: |
5959
mvn install exec:java \
60+
-Dexec.mainClass="com.expediagroup.sdk.xap.examples.XapSdkDemoTestRun" \
6061
-Dcom.expediagroup.xapjavasdk.apikey="${{ secrets.API_KEY }}" \
6162
-Dcom.expediagroup.xapjavasdk.apisecret="${{ secrets.API_SECRET }}" \
6263
-Dcom.expediagroup.xapjavasdk.vrbokey="${{ secrets.VRBO_KEY }}" \

examples/README.md

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ Currently, the following scenarios are included:
1212

1313
### Lodging
1414

15-
#### Shopping
15+
- [`ListingsQuickStartScenario.java`](src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/ListingsQuickStartScenario.java):
1616

17-
##### Listings
17+
This example demonstrates how to search for properties with a location keyword with filters
18+
applied in Lodging Listings API.
19+
20+
- [`QuotesQuickStartScenario.java`](src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/QuotesQuickStartScenario.java):
21+
22+
This example demonstrates how to search for property quotes with property IDs in Lodging Quotes API.
1823

1924
- [
20-
`QuickStartExample.java`](src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/shopping/listings/QuickStartExample.java):
21-
This example demonstrates how to search for properties with a location keyword with filters
22-
applied.
25+
`AvailabilityCalendarsQuickStartScenario.java`](src/main/java/com/expediagroup/sdk/xap/examples/scenarios/lodging/AvailabilityCalendarsQuickStartScenario.java):
26+
27+
This example demonstrates how to search for availability calendars with property IDs in Lodging Availability Calendar API.
2328

2429
We are continuously adding more scenarios to demonstrate the usage of other XAP APIs.
2530

@@ -35,16 +40,44 @@ We are continuously adding more scenarios to demonstrate the usage of other XAP
3540

3641
1. Clone the repository.
3742
2. Navigate to the project directory `examples`.
38-
3. Set your API key and secret in the environment variables `XAP_API_KEY` and `XAP_API_PASSWORD`.
39-
> **Note:** You can also replace the value of `xapApiKey` and `xapApiPassword` in the
40-
> [`Constants.java`](src/main/java/com/expediagroup/sdk/xap/examples/Constants.java) file, but we
41-
> recommend using environment variables out of security concerns.
42-
4. Run `mvn clean install` to build the project and install the dependencies including the XAP SDK.
43+
3. Run `mvn clean install` to build the project and install the dependencies including the XAP SDK.
4344

4445
## Running the Examples
4546

46-
To run the examples, simply navigate to the example class you want to run and execute the `main`
47-
method.
47+
### Run with IntelliJ IDEA
48+
1. Navigate to the example class you want to run
49+
2. Right-click on the class name and select `More Run/Debug` -> `Modify Run Configuration`
50+
3. Check the `Modify options` -> `Add VM options` and add the following VM options:
51+
```
52+
-Dcom.expediagroup.xapjavasdk.apikey="{API_KEY}"
53+
-Dcom.expediagroup.xapjavasdk.apisecret="{API_SECRET}"
54+
```
55+
Replace `{API_KEY}` and `{API_SECRET}` with your actual API key and secret.
56+
> **Note:** If you are running the examples for Vrbo, you would need the following VM options instead:
57+
> ```
58+
> -Dcom.expediagroup.xapjavasdk.vrbokey="{VRBO_KEY}"
59+
> -Dcom.expediagroup.xapjavasdk.vrbosecret="{VRBO_SECRET}"
60+
> ```
61+
> The key you use must be enabled for Vrbo brand. If you are not sure, please reach out to your account manager.
62+
4. Click `OK` and then run the `main` method of the example class.
63+
64+
### Run with Command Line
65+
Run the following command to run the example class you want to run:
66+
```
67+
mvn exec:java -Dexec.mainClass="path.to.example.ExampleClassName" \
68+
-Dcom.expediagroup.xapjavasdk.apikey="{API_KEY}" \
69+
-Dcom.expediagroup.xapjavasdk.apisecret="{API_SECRET}"
70+
```
71+
Replace `path.to.example.ExampleClassName` with the full path to the example class you want to run,
72+
and `{API_KEY}` and `{API_SECRET}` with your actual API key and secret.
73+
74+
> **Note:** If you are running the examples for Vrbo, you should use the following command instead:
75+
> ```
76+
> mvn exec:java -Dexec.mainClass="path.to.example.ExampleClassName" \
77+
> -Dcom.expediagroup.xapjavasdk.vrbokey="{VRBO_KEY}" \
78+
> -Dcom.expediagroup.xapjavasdk.vrbosecret="{VRBO_SECRET}"
79+
> ```
80+
> The key you use must be enabled for Vrbo brand. If you are not sure, please reach out to your account manager.
4881
4982
## License
5083

examples/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<maven.compiler.source>1.8</maven.compiler.source>
3232
<maven.compiler.target>1.8</maven.compiler.target>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34-
<xap-java-sdk.sdk.version>0.0.8-SNAPSHOT</xap-java-sdk.sdk.version>
34+
<xap-java-sdk.sdk.version>0.0.15-SNAPSHOT</xap-java-sdk.sdk.version>
3535
</properties>
3636

3737
<repositories>
@@ -86,14 +86,6 @@
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>
9789
</plugins>
9890
</build>
9991
</project>

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

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.AvailabilityCalendarsQuickStartScenario;
20+
import com.expediagroup.sdk.xap.examples.scenarios.lodging.ListingsQuickStartScenario;
21+
import com.expediagroup.sdk.xap.examples.scenarios.lodging.QuotesQuickStartScenario;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
/**
26+
* This is an aggregation runner for all the scenarios for test purposes.
27+
* For reference, see the individual scenarios in the scenarios package.
28+
*/
29+
public class XapSdkDemoTestRun {
30+
private static final Logger logger = LoggerFactory.getLogger(XapSdkDemoTestRun.class);
31+
32+
/**
33+
* Main method.
34+
*/
35+
public static void main(String[] args) {
36+
37+
logger.info(
38+
"============================== Running Lodging Scenarios =============================");
39+
40+
AvailabilityCalendarsQuickStartScenario availabilityCalendarsQuickStartScenario =
41+
new AvailabilityCalendarsQuickStartScenario();
42+
availabilityCalendarsQuickStartScenario.run();
43+
44+
ListingsQuickStartScenario listingsQuickStartScenario = new ListingsQuickStartScenario();
45+
listingsQuickStartScenario.run();
46+
47+
QuotesQuickStartScenario quotesQuickStartScenario = new QuotesQuickStartScenario();
48+
quotesQuickStartScenario.run();
49+
50+
logger.info(
51+
"=============================== End of Lodging Scenarios ==============================");
52+
53+
System.exit(0);
54+
}
55+
}

examples/src/main/java/com/expediagroup/sdk/xap/examples/scenarios/XapScenario.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,29 @@
1616

1717
package com.expediagroup.sdk.xap.examples.scenarios;
1818

19+
import com.expediagroup.sdk.xap.client.XapClient;
20+
1921
/**
2022
* Interface for scenarios.
2123
*/
2224
public interface XapScenario {
25+
26+
String PARTNER_TRANSACTION_ID = "xap-java-sdk-examples";
27+
2328
void run();
29+
30+
/**
31+
* Create a client.
32+
*
33+
* @return XapClient
34+
*/
35+
default XapClient createClient() {
36+
String key = System.getProperty("com.expediagroup.xapjavasdk.apikey");
37+
String secret = System.getProperty("com.expediagroup.xapjavasdk.apisecret");
38+
return XapClient
39+
.builder()
40+
.key(key)
41+
.secret(secret)
42+
.build();
43+
}
2444
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.client.XapClient;
20+
import com.expediagroup.sdk.xap.models.AvailabilityCalendarResponse;
21+
import com.expediagroup.sdk.xap.operations.GetLodgingAvailabilityCalendarsOperation;
22+
import com.expediagroup.sdk.xap.operations.GetLodgingAvailabilityCalendarsOperationParams;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
import java.util.Arrays;
26+
import java.util.HashSet;
27+
28+
/**
29+
* This example demonstrates how to use Availability Calendar api with simple search.
30+
* Note: this is a Vrbo scenario. You need a key that is enabled for Vrbo brand to run this.
31+
*/
32+
public class AvailabilityCalendarsQuickStartScenario implements VrboScenario {
33+
34+
private static final Logger LOGGER =
35+
LoggerFactory.getLogger(AvailabilityCalendarsQuickStartScenario.class);
36+
37+
public static void main(String[] args) {
38+
new AvailabilityCalendarsQuickStartScenario().run();
39+
System.exit(0);
40+
}
41+
42+
@Override
43+
public void run() {
44+
// This example returns the availability of each day for a range of dates for given Expedia
45+
// lodging properties.
46+
47+
LOGGER.info(
48+
"=================== Running AvailabilityCalendarsQuickStartScenario ===================");
49+
50+
LOGGER.info(
51+
"================= Executing GetLodgingAvailabilityCalendars Operation ================");
52+
53+
54+
// Build the query parameters with GetLodgingAvailabilityCalendarsOperationParams
55+
GetLodgingAvailabilityCalendarsOperationParams availabilityCalendarsOperationParams =
56+
GetLodgingAvailabilityCalendarsOperationParams.builder()
57+
.partnerTransactionId(PARTNER_TRANSACTION_ID)
58+
// Set of Expedia Property IDs.
59+
.propertyIds(new HashSet<>(Arrays.asList("87704892", "12410858")))
60+
.build();
61+
62+
XapClient xapClient = createClient();
63+
64+
// Execute the operation and get the AvailabilityCalendarsResponse
65+
AvailabilityCalendarResponse availabilityCalendarResponse =
66+
xapClient.execute(new GetLodgingAvailabilityCalendarsOperation(
67+
availabilityCalendarsOperationParams)).getData();
68+
69+
// If you want to use the async method, you can use the following code:
70+
// ---------------------------------------------------------------
71+
// CompletableFuture<Response<AvailabilityCalendarResponse>> completableFuture =
72+
// xapClient.executeAsync(
73+
// new GetLodgingAvailabilityCalendarsOperation(availabilityCalendarsOperationParams));
74+
// completableFuture.thenAccept(availCalendarResponse -> {
75+
// // Your code here
76+
// });
77+
// ---------------------------------------------------------------
78+
79+
LOGGER.info(
80+
"================== GetLodgingAvailabilityCalendarsOperation Executed =================");
81+
82+
if (availabilityCalendarResponse == null
83+
|| availabilityCalendarResponse.getAvailabilityCalendars() == null
84+
|| availabilityCalendarResponse.getAvailabilityCalendars().isEmpty()) {
85+
throw new IllegalStateException("No properties found.");
86+
}
87+
88+
// The AvailabilityCalendarsResponse contains a transaction ID for troubleshooting
89+
LOGGER.info("Transaction ID: {}", availabilityCalendarResponse.getTransactionId());
90+
91+
// To access the properties, iterate through the list of properties
92+
availabilityCalendarResponse.getAvailabilityCalendars().forEach(availCalendar -> {
93+
LOGGER.info("========== Property:{} Start ==========", availCalendar.getPropertyId());
94+
95+
// Availability of property: A string of codes that shows property availability, one for every
96+
// day in the specified date range.
97+
// Valid values include Y (available) and N (unavailable).
98+
LOGGER.info("Availability: {}", availCalendar.getAvailability());
99+
100+
LOGGER.info(
101+
"==================================== Property End ===================================");
102+
103+
LOGGER.info(
104+
"===================== End AvailabilityCalendarsQuickStartScenario ====================");
105+
});
106+
}
107+
}

0 commit comments

Comments
 (0)