Skip to content

Commit fa4c170

Browse files
committed
code cleanup
1 parent a6d34d3 commit fa4c170

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/main/kotlin/com/ctrlhub/core/Api.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ import io.ktor.client.*
99
object Api {
1010
private var sessionToken: String? = null
1111
var httpClient: HttpClient = KtorClientFactory.create()
12-
private set
12+
private set
1313

1414
fun withHttpClientConfig(config: HttpClientConfig<*>.() -> Unit) {
15-
httpClient = KtorClientFactory.create(
16-
configBlock = config
17-
)
15+
httpClient = KtorClientFactory.create(configBlock = config)
1816
}
1917

2018
fun applySessionToken(newSessionToken: String) {
2119
sessionToken = newSessionToken
22-
httpClient = KtorClientFactory.createWithExistingConfig(httpClient, sessionToken)
20+
httpClient = KtorClientFactory.createWithExistingConfig(httpClient, newSessionToken)
2321
}
2422
}

src/main/kotlin/com/ctrlhub/core/http/KtorClientFactory.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import java.util.concurrent.atomic.AtomicReference
1919
* in that an existing Ktor client can be passed, and config is applied to that.
2020
*/
2121
object KtorClientFactory {
22-
// Function to create an HttpClient with configuration and optional session token
2322
fun create(
2423
httpClient: HttpClient = HttpClient(CIO),
2524
sessionToken: String? = null,
@@ -28,15 +27,13 @@ object KtorClientFactory {
2827
return configureHttpClient(httpClient, sessionToken, configBlock)
2928
}
3029

31-
// Function to create a new HttpClient based on an existing HttpClient configuration
3230
fun createWithExistingConfig(
3331
existingClient: HttpClient,
3432
sessionToken: String? = null
3533
): HttpClient {
36-
return configureHttpClient(existingClient, sessionToken) // Reapply session token while retaining existing config
34+
return configureHttpClient(existingClient, sessionToken)
3735
}
3836

39-
// Function to configure the HttpClient
4037
private fun configureHttpClient(
4138
baseClient: HttpClient,
4239
sessionToken: String? = null,
@@ -45,7 +42,7 @@ object KtorClientFactory {
4542
return baseClient.config {
4643
defaultRequest {
4744
url(Config.apiBaseUrl)
48-
sessionToken?.let { headers.append("X-Session-Token", it) } // Apply session token if present
45+
sessionToken?.let { headers.append("X-Session-Token", it) }
4946
headers.appendIfNameAbsent(HttpHeaders.ContentType, "application/json")
5047
}
5148
expectSuccess = true
@@ -58,7 +55,7 @@ object KtorClientFactory {
5855
install(UserAgent) {
5956
agent = Config.userAgent
6057
}
61-
configBlock() // Apply additional user-defined config
58+
configBlock()
6259
}
6360
}
6461
}

0 commit comments

Comments
 (0)