Skip to content

Commit dddf4e7

Browse files
committed
Convert SDK to a KMP structure
1 parent bdc505d commit dddf4e7

File tree

116 files changed

+157
-135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+157
-135
lines changed

.idea/artifacts/ctrlhub_sdk_jvm_1_0_SNAPSHOT.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/material_theme_project_new.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
kotlin("jvm") version "2.0.21"
2+
kotlin("multiplatform") version "2.1.0"
33
kotlin("plugin.serialization") version "2.1.0"
44
`maven-publish`
55
}
@@ -15,27 +15,43 @@ repositories {
1515
}
1616
}
1717

18-
dependencies {
19-
implementation(libs.kotlin.reflect)
20-
implementation(libs.ktor.client.core)
21-
implementation(libs.ktor.client.cio)
22-
implementation(libs.ktor.serialization.kotlinx.json)
23-
implementation(libs.ktor.client.content.negotiation)
24-
implementation(libs.ktor.logging.plugin)
25-
implementation(libs.jetbrains.kotlinx.serialization.json)
26-
implementation(libs.jsonapi.converter)
27-
implementation(libs.jackson.datatype.jsr)
28-
implementation(libs.jackson.kotlin)
29-
30-
testImplementation(kotlin("test"))
31-
testImplementation(libs.mockk)
32-
testImplementation(libs.ktor.client.mock)
18+
kotlin {
19+
jvm()
20+
21+
sourceSets {
22+
jvmMain {
23+
dependencies {
24+
implementation(libs.ktor.client.cio)
25+
}
26+
}
27+
28+
commonMain {
29+
dependencies {
30+
implementation(libs.kotlin.reflect)
31+
implementation(libs.ktor.client.core)
32+
implementation(libs.ktor.serialization.kotlinx.json)
33+
implementation(libs.ktor.client.content.negotiation)
34+
implementation(libs.ktor.logging.plugin)
35+
implementation(libs.jetbrains.kotlinx.serialization.json)
36+
implementation(libs.jsonapi.converter)
37+
implementation(libs.jackson.datatype.jsr)
38+
implementation(libs.jackson.kotlin)
39+
}
40+
}
41+
42+
commonTest {
43+
dependencies {
44+
implementation(kotlin("test"))
45+
implementation(libs.mockk)
46+
implementation(libs.ktor.client.mock)
47+
}
48+
}
49+
}
3350
}
3451

3552
val generateBuildConfig by tasks.registering {
3653
val outputDir = layout.buildDirectory.dir("generated/source/buildConfig/com/ctrlhub")
3754
val packageName = "com.ctrlhub"
38-
val versionName = project.getGitTag()
3955

4056
outputs.dir(outputDir)
4157

@@ -48,14 +64,14 @@ val generateBuildConfig by tasks.registering {
4864
package $packageName
4965
5066
object BuildConfig {
51-
const val VERSION_NAME = "$versionName"
67+
const val VERSION_NAME = "$version"
5268
}
5369
""".trimIndent()
5470
)
5571
}
5672
}
5773

58-
kotlin.sourceSets["main"].kotlin.srcDir(layout.buildDirectory.dir("generated/source/buildConfig"))
74+
kotlin.sourceSets["commonMain"].kotlin.srcDir(layout.buildDirectory.dir("generated/source/buildConfig"))
5975

6076
fun Project.getGitTag(): String {
6177
return try {
@@ -93,10 +109,10 @@ publishing {
93109
}
94110
}
95111

96-
tasks.test {
97-
useJUnitPlatform()
98-
}
112+
//tasks.test {
113+
// useJUnitPlatform()
114+
//}
99115

100-
tasks.named("compileKotlin") {
101-
dependsOn(generateBuildConfig)
102-
}
116+
//tasks.named("compileKotlin") {
117+
// dependsOn(generateBuildConfig)
118+
//}

src/main/kotlin/com/ctrlhub/core/Api.kt renamed to src/commonMain/kotlin/com/ctrlhub/core/Api.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ import io.ktor.client.plugins.defaultRequest
88
* The facade object through which interaction with the API occurs.
99
*/
1010
class Api(
11-
var httpClient: HttpClient = KtorClientFactory.create()
11+
var httpClient: HttpClient
1212
) {
1313
fun withHttpClientConfig(config: HttpClientConfig<*>.() -> Unit) {
1414
httpClient = KtorClientFactory.create(configBlock = config)
1515
}
1616

1717
fun applySessionToken(sessionToken: String) {
18-
httpClient = KtorClientFactory.create(httpClient) {
18+
httpClient = httpClient.config {
1919
defaultRequest {
2020
headers["X-Session-Token"] = sessionToken
2121
}
2222
}
2323
}
2424

2525
fun clearSessionToken() {
26-
httpClient = KtorClientFactory.create(httpClient) {
26+
httpClient = httpClient.config {
2727
defaultRequest {
2828
headers.remove("X-Session-Token")
2929
}

0 commit comments

Comments
 (0)