Skip to content

Commit 08d1a89

Browse files
authored
feat: initialize xap sdk module (#127)
PR: #127
1 parent 2e25488 commit 08d1a89

File tree

8 files changed

+559
-340
lines changed

8 files changed

+559
-340
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2025 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.client
18+
19+
import com.expediagroup.sdk.rest.AsyncRestClient
20+
import com.expediagroup.sdk.rest.AsyncRestExecutor
21+
import com.expediagroup.sdk.rest.model.Response
22+
import com.expediagroup.sdk.rest.trait.operation.JacksonModelOperationResponseBodyTrait
23+
import com.expediagroup.sdk.rest.trait.operation.OperationNoResponseBodyTrait
24+
import com.expediagroup.sdk.xap.configuration.AsyncClientBuilder
25+
import com.expediagroup.sdk.xap.configuration.AsyncXapClientConfiguration
26+
import com.expediagroup.sdk.xap.configuration.Constant.ENDPOINT
27+
import com.expediagroup.sdk.xap.configuration.OBJECT_MAPPER
28+
import com.expediagroup.sdk.xap.core.AsyncRequestExecutor
29+
import java.util.concurrent.CompletableFuture
30+
31+
/**
32+
* Asynchronous client for XAP API.
33+
*
34+
* @property restExecutor The executor for handling REST operations.
35+
*/
36+
class AsyncXapClient private constructor(
37+
config: AsyncXapClientConfiguration,
38+
) : AsyncRestClient() {
39+
override val restExecutor: AsyncRestExecutor =
40+
AsyncRestExecutor(
41+
mapper = OBJECT_MAPPER,
42+
serverUrl = ENDPOINT,
43+
requestExecutor = AsyncRequestExecutor(configuration = config),
44+
)
45+
46+
/**
47+
* Executes an operation that does not expect a response body.
48+
*
49+
* @param operation The operation to execute.
50+
* @return A CompletableFuture containing the response.
51+
*/
52+
fun execute(operation: OperationNoResponseBodyTrait): CompletableFuture<Response<Nothing?>> = restExecutor.execute(operation)
53+
54+
/**
55+
* Executes an operation that expects a response body.
56+
*
57+
* @param T The type of the response body.
58+
* @param operation The operation to execute.
59+
* @return A CompletableFuture containing the response.
60+
*/
61+
fun <T : Any> execute(operation: JacksonModelOperationResponseBodyTrait<T>): CompletableFuture<Response<T>> = restExecutor.execute(operation)
62+
63+
companion object {
64+
/**
65+
* Builder for creating an instance of [AsyncXapClient].
66+
*/
67+
class Builder : AsyncClientBuilder<AsyncXapClient>() {
68+
override fun build(): AsyncXapClient = AsyncXapClient(buildConfig())
69+
}
70+
71+
/**
72+
* Creates a new builder for [AsyncXapClient].
73+
*
74+
* @return A new [Builder] instance.
75+
*/
76+
@JvmStatic
77+
fun builder() = Builder()
78+
}
79+
}

0 commit comments

Comments
 (0)