Skip to content

Commit 0af7439

Browse files
author
johnli
committed
add car code examples.
1 parent 47e4848 commit 0af7439

File tree

5 files changed

+408
-2
lines changed

5 files changed

+408
-2
lines changed

examples/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ Currently, the following scenarios are included:
2626

2727
This example demonstrates how to search for availability calendars with property IDs in Lodging Availability Calendar API.
2828

29+
### Car
30+
31+
- [`CarDetailsQuickStartScenario.java`](src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarListingsQuickStartScenario.java):
32+
33+
This example demonstrates how to search for cars using an airport keyword with filters applied in the Car Listings API.
34+
35+
- [`CarDetailsQuickStartScenario.java`](src/main/java/com/expediagroup/sdk/xap/examples/scenarios/car/CarDetailsQuickStartScenario.java):
36+
37+
This example demonstrates how to search for car details using the offerToken obtained from the car listing in the Car Details API.
38+
2939
We are continuously adding more scenarios to demonstrate the usage of other XAP APIs.
3040

3141
## Requirements

examples/pom.xml

Lines changed: 2 additions & 2 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.15-SNAPSHOT</xap-java-sdk.sdk.version>
34+
<xap-java-sdk.sdk.version>0.0.17-SNAPSHOT</xap-java-sdk.sdk.version>
3535
</properties>
3636

3737
<repositories>
@@ -88,4 +88,4 @@
8888
</plugin>
8989
</plugins>
9090
</build>
91-
</project>
91+
</project>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

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

19+
import com.expediagroup.sdk.xap.examples.scenarios.car.CarDetailsQuickStartScenario;
20+
import com.expediagroup.sdk.xap.examples.scenarios.car.CarListingsQuickStartScenario;
1921
import com.expediagroup.sdk.xap.examples.scenarios.lodging.AvailabilityCalendarsQuickStartScenario;
2022
import com.expediagroup.sdk.xap.examples.scenarios.lodging.ListingsQuickStartScenario;
2123
import com.expediagroup.sdk.xap.examples.scenarios.lodging.QuotesQuickStartScenario;
@@ -50,6 +52,16 @@ public static void main(String[] args) {
5052
logger.info(
5153
"=============================== End of Lodging Scenarios ==============================");
5254

55+
logger.info(
56+
"============================== Running Car Scenarios =============================");
57+
CarListingsQuickStartScenario carListingsQuickStartScenario = new CarListingsQuickStartScenario();
58+
carListingsQuickStartScenario.run();
59+
60+
CarDetailsQuickStartScenario carDetailsQuickStartScenario = new CarDetailsQuickStartScenario();
61+
carDetailsQuickStartScenario.run();
62+
logger.info(
63+
"=============================== End of Car Scenarios ==============================");
64+
5365
System.exit(0);
5466
}
5567
}
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
package com.expediagroup.sdk.xap.examples.scenarios.car;
2+
3+
import com.expediagroup.sdk.core.model.Response;
4+
import com.expediagroup.sdk.xap.client.XapClient;
5+
import com.expediagroup.sdk.xap.examples.scenarios.XapScenario;
6+
import com.expediagroup.sdk.xap.models.CarDetails;
7+
import com.expediagroup.sdk.xap.models.CarDetailsResponse;
8+
import com.expediagroup.sdk.xap.models.CarListingsResponse;
9+
import com.expediagroup.sdk.xap.models.VehicleDetails;
10+
import com.expediagroup.sdk.xap.operations.GetCarDetailsOperation;
11+
import com.expediagroup.sdk.xap.operations.GetCarDetailsOperationParams;
12+
import com.expediagroup.sdk.xap.operations.GetCarsListingsOperation;
13+
import com.expediagroup.sdk.xap.operations.GetCarsListingsOperationParams;
14+
import java.time.LocalDateTime;
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
import java.util.Objects;
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
/**
22+
* This example demonstrates how to retrieve CarDetails information using the Car Details DeepLink obtained from the car listing.
23+
*/
24+
public class CarDetailsQuickStartScenario implements XapScenario {
25+
26+
private static final Logger LOGGER = LoggerFactory.getLogger(CarDetailsQuickStartScenario.class);
27+
28+
/**
29+
* Summary: main function.
30+
*/
31+
public static void main(String[] args) {
32+
new CarListingsQuickStartScenario().run();
33+
new CarDetailsQuickStartScenario().run();
34+
System.exit(0);
35+
}
36+
37+
@Override
38+
public void run() {
39+
LOGGER.info("========== Start QuickStartScenario ==========");
40+
41+
LOGGER.info("========== Car Listing Start ==========");
42+
43+
// This example demonstrates how to obtain the Car Details Deep Link from the CarListing.
44+
// For information on using car search, refer to car/shopping/listings/ListingsQuickStartExample.
45+
List<GetCarsListingsOperationParams.Links> linksList = new ArrayList<>();
46+
linksList.add(GetCarsListingsOperationParams.Links.AD);
47+
linksList.add(GetCarsListingsOperationParams.Links.WS);
48+
linksList.add(GetCarsListingsOperationParams.Links.WD);
49+
GetCarsListingsOperationParams getCarsListingsOperationParams = GetCarsListingsOperationParams.builder()
50+
.partnerTransactionId("EWSCar_Automation")
51+
.dropOffAirport("MCO")
52+
.pickupAirport("MCO")
53+
.pickupTime(LocalDateTime.now().plusDays(5))
54+
.dropOffTime(LocalDateTime.now().plusDays(8))
55+
.limit(1)
56+
.links(linksList)
57+
.build();
58+
59+
XapClient xapClient = createClient();
60+
GetCarsListingsOperation getCarsListingsOperation = new GetCarsListingsOperation(getCarsListingsOperationParams);
61+
Response<CarListingsResponse> carListingsResponse = xapClient.execute(getCarsListingsOperation);
62+
63+
LOGGER.info("========== Car Listing Property End ==========");
64+
65+
// Iterate through the car listings and retrieve the Car Details Deep Link.
66+
LOGGER.info("========== Car Details Start ==========");
67+
Objects.requireNonNull(carListingsResponse.getData().getCars()).forEach(car -> {
68+
if (!car.getLinks().get("ApiDetails").getHref().isEmpty()) {
69+
// Retrieve the Car Details Deep Link from the car listing.
70+
LOGGER.info("Car Details Deep Link: " + car.getLinks().get("ApiDetails").getHref());
71+
String[] strings = splitUrl(car.getLinks().get("ApiDetails").getHref());
72+
73+
// Retrieve the Car Details information using the Car Details Deep Link,which include(offerToken, price, currency)
74+
GetCarDetailsOperationParams getCarDetailsOperationParams = GetCarDetailsOperationParams.builder().partnerTransactionId("EWSCar_Automation")
75+
.offerToken(strings[0]).price(strings[1]).currency(strings[2]).build();
76+
77+
// Execute the operation and get the CarDetailsResponse
78+
LOGGER.info("========== Executing GetCarDetailsOperation ==========");
79+
CarDetailsResponse carDetailsResponse = xapClient.execute(
80+
new GetCarDetailsOperation(getCarDetailsOperationParams)).getData();
81+
LOGGER.info("========== GetCarDetailsOperation Executed ==========");
82+
83+
if (carDetailsResponse == null || carDetailsResponse.getLinks() == null) {
84+
throw new IllegalStateException("No car found.");
85+
}
86+
87+
LOGGER.info("========== Car Properties Start ==========");
88+
89+
// The CarDetailsResponse contains a transaction ID for troubleshooting
90+
LOGGER.info("Transaction ID: {}", carDetailsResponse.getTransactionId());
91+
92+
// List Container for warning messages
93+
if (carDetailsResponse.getWarnings() != null) {
94+
LOGGER.info("Warnings: {}", carDetailsResponse.getWarnings());
95+
}
96+
97+
// Details of requested car.
98+
// Details refer to the CarDetails Section table below.
99+
if (carDetailsResponse.getValidFormsOfPayment() != null) {
100+
LOGGER.info("Valid Forms Of Payment: {}", carDetailsResponse.getValidFormsOfPayment());
101+
}
102+
103+
// A map of links to other Car APIs.
104+
if (carDetailsResponse.getLinks() != null) {
105+
LOGGER.info("Links: {}", carDetailsResponse.getLinks());
106+
}
107+
108+
// Specific information for a car.
109+
CarDetails carDetails = carDetailsResponse.getCarDetails();
110+
VehicleDetails vehicleDetails = carDetails.getVehicleDetails();
111+
if (vehicleDetails.getMake() != null ) {
112+
//Car manufacturer and model.
113+
LOGGER.info("Make: {}", vehicleDetails.getMake());
114+
}
115+
116+
// Car category and type.
117+
LOGGER.info("Car Class: {}", vehicleDetails.getCarClass());
118+
119+
// Minimal car door count.
120+
if (vehicleDetails.getMinDoors() != null) {
121+
LOGGER.info("Min Doors: {}", vehicleDetails.getMinDoors());
122+
}
123+
124+
// Maximum car door count.
125+
if (vehicleDetails.getMaxDoors() != null) {
126+
LOGGER.info("Max Doors: {}", vehicleDetails.getMaxDoors());
127+
}
128+
129+
// Car fuel information.
130+
if (vehicleDetails.getFuelLevel() != null) {
131+
// Fuel level of the car.
132+
LOGGER.info("Fuel Level: {}", vehicleDetails.getFuelLevel());
133+
}
134+
135+
// Car category.
136+
LOGGER.info("Car Category: {}", vehicleDetails.getCarCategory());
137+
138+
// Car type.
139+
LOGGER.info("Car Type: {}", vehicleDetails.getCarType());
140+
141+
// Car transmission and drive.
142+
LOGGER.info("Transmission Drive: {}", vehicleDetails.getTransmissionDrive());
143+
144+
// Car fuel type and whether Air Conditioning is included.
145+
LOGGER.info("Fuel AC: {}", vehicleDetails.getFuelAC());
146+
147+
// Capacity for car's properties, which include AdultCount, ChildCount, SmallLuggageCount and LargeLuggageCount.
148+
if (vehicleDetails.getCapacity() != null) {
149+
LOGGER.info("Capacity: {}", vehicleDetails.getCapacity());
150+
}
151+
152+
// Car rental supplier.
153+
LOGGER.info(" : {}", carDetails.getSupplier());
154+
155+
// Pickup information
156+
LOGGER.info("Pickup Details: {}", carDetails.getPickupDetails());
157+
158+
// Drop off information, include drop off date time and drop off location information.
159+
LOGGER.info("Drop Off Details: {}", carDetails.getDropOffDetails());
160+
161+
// The rate information for a car product.
162+
LOGGER.info("Rate Details: {}", carDetails.getRateDetails());
163+
164+
// Base price per rate period.
165+
LOGGER.info("Price: {}", carDetails.getPrice());
166+
167+
// List of TaxesAndFees Details.
168+
if (carDetails.getTaxesAndFeesDetails() != null) {
169+
LOGGER.info("Taxes And Fees Details: {}", carDetails.getTaxesAndFeesDetails());
170+
}
171+
172+
// List of ExtraFeesDetails
173+
if (carDetails.getExtraFeesDetails() != null) {
174+
LOGGER.info("Extra Fees Details: {}", carDetails.getExtraFeesDetails());
175+
}
176+
177+
// ReferencePrice is the totalPrice for the comparable standalone car, when there is a discounted car or need to show strike through pricing.
178+
if (carDetails.getReferencePrice() != null) {
179+
LOGGER.info("Reference Price: {}", carDetails.getReferencePrice());
180+
}
181+
182+
// List of additional fees including both mandatory and optional fees such as young driver fee/drop off fee /CollisionDamageWaiver.
183+
if (carDetails.getAdditionalFees() != null) {
184+
LOGGER.info("Additional Fees: {}", carDetails.getAdditionalFees());
185+
}
186+
187+
// Description and costs of any optional special equipment that may be rented with the car.
188+
if (carDetails.getSpecialEquipments() != null) {
189+
LOGGER.info("Special Equipments: {}", carDetails.getSpecialEquipments());
190+
}
191+
192+
// Limitations that are part of this rental agreement.
193+
if (carDetails.getRentalLimits() != null) {
194+
LOGGER.info("Rental Limits: {}", carDetails.getRentalLimits());
195+
}
196+
197+
// Cancellation Policy Container.
198+
LOGGER.info("Cancellation Policy: {}", carDetails.getCancellationPolicy());
199+
200+
// Container for no show penalty
201+
if (carDetails.getNoShowPenalty() != null) {
202+
LOGGER.info("No Show Penalty: {}", carDetails.getNoShowPenalty());
203+
}
204+
205+
// A list of policies that apply to this car rental.
206+
if (carDetails.getCarPolicies() != null) {
207+
LOGGER.info("Policies: {}", carDetails.getCarPolicies());
208+
}
209+
210+
// List of image resources of the car product.
211+
if (carDetails.getImages() != null) {
212+
LOGGER.info("Images: {}", carDetails.getImages());
213+
}
214+
215+
LOGGER.info("========== Property End ==========");
216+
}
217+
218+
});
219+
220+
LOGGER.info("========== End QuickStartExample ==========");
221+
}
222+
223+
public static String[] splitUrl(String url) {
224+
String[] parts = url.split("\\?");
225+
String base = parts[0];
226+
String query = parts[1];
227+
228+
String offerToken = base.substring(base.lastIndexOf("/") + 1);
229+
String[] queryParams = query.split("&");
230+
String price = queryParams[0].split("=")[1];
231+
String currency = queryParams[1].split("=")[1];
232+
233+
return new String[]{offerToken, price, currency};
234+
}
235+
236+
}

0 commit comments

Comments
 (0)