aboutsummaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/build.gradle.kts15
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt41
-rw-r--r--shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt4
-rw-r--r--shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/NSDataByteArray.kt2
4 files changed, 29 insertions, 33 deletions
diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts
index 94b8f09..67acdb8 100644
--- a/shared/build.gradle.kts
+++ b/shared/build.gradle.kts
@@ -5,17 +5,17 @@ plugins {
}
kotlin {
- val ktor_version = "1.6.6"
+ val ktor_version = "2.3.4"
val settings_version = "0.8.1"
- androidTarget()
+ android()
jvmToolchain(17)
listOf(
iosX64(),
iosArm64(),
- //iosSimulatorArm64() sure all ios dependencies support this target
+ iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
@@ -27,7 +27,8 @@ kotlin {
dependencies {
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")
- implementation("io.ktor:ktor-client-serialization:$ktor_version")
+ implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
+ implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.insert-koin:koin-core:3.1.4")
implementation("ch.qos.logback:logback-classic:1.2.6")
@@ -44,14 +45,14 @@ kotlin {
}
val iosX64Main by getting
val iosArm64Main by getting
- //val iosSimulatorArm64Main by getting
+ val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
- //iosSimulatorArm64Main.dependsOn(this)
+ iosSimulatorArm64Main.dependsOn(this)
dependencies {
- implementation("io.ktor:ktor-client-ios:$ktor_version")
+ implementation("io.ktor:ktor-client-darwin:$ktor_version")
}
}
}
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
index e9865e8..937b2dd 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
@@ -19,17 +19,14 @@ package mx.trackermap.TrackerMap.client.infrastructure
import io.ktor.client.*
import io.ktor.client.call.*
-import io.ktor.client.features.*
-import io.ktor.client.features.json.*
-import io.ktor.client.features.json.serializer.KotlinxSerializer
-import io.ktor.client.features.logging.DEFAULT
-import io.ktor.client.features.logging.LogLevel
-import io.ktor.client.features.logging.Logger
-import io.ktor.client.features.logging.Logging
+import io.ktor.client.plugins.*
+import io.ktor.client.plugins.contentnegotiation.*
+import io.ktor.client.plugins.logging.*
import io.ktor.client.request.*
-import io.ktor.client.request.forms.FormDataContent
+import io.ktor.client.request.forms.*
import io.ktor.client.statement.*
import io.ktor.http.*
+import io.ktor.serialization.kotlinx.json.*
import io.ktor.util.*
import kotlinx.serialization.json.Json as KotlinJson
@@ -49,13 +46,11 @@ open class ApiClient(
connectTimeoutMillis = 20_000
requestTimeoutMillis = 20_000
}
- install(JsonFeature) {
- serializer = KotlinxSerializer(
- KotlinJson {
- ignoreUnknownKeys = true
- useAlternativeNames = false
- }
- )
+ install(ContentNegotiation) {
+ json(KotlinJson {
+ ignoreUnknownKeys = true
+ useAlternativeNames = false
+ })
}
install(Logging) {
logger = Logger.DEFAULT
@@ -85,12 +80,12 @@ open class ApiClient(
}
parametersBuilder.build()
requestBuilder.contentType(ContentType.MultiPart.FormData)
- requestBuilder.body = parametersBuilder
+ requestBuilder.setBody(parametersBuilder)
}
mediaType == ApiJsonMediaType -> {
requestBuilder.contentType(ContentType.Application.Json)
if (content != null) {
- requestBuilder.body = content
+ requestBuilder.setBody(content)
}
}
mediaType == ApiFormURLType && content is Map<*, *> -> {
@@ -98,7 +93,7 @@ open class ApiClient(
content.forEach { item ->
parametersBuilder[item.key as String] = item.value as String
}
- requestBuilder.body = FormDataContent(parametersBuilder.build())
+ requestBuilder.setBody(FormDataContent(parametersBuilder.build()))
}
mediaType == ApiXmlMediaType -> TODO("xml not currently supported.")
@@ -119,7 +114,7 @@ open class ApiClient(
}
val urlBuilder = URLBuilder(httpUrl)
- .path("${httpUrl.encodedPath.trimStart('/')}${requestConfig.path}")
+ urlBuilder.path("${httpUrl.encodedPath.trimStart('/')}${requestConfig.path}")
requestConfig.query.forEach { query ->
query.value.forEach { queryValue ->
@@ -190,21 +185,21 @@ open class ApiClient(
response.headers.toMap()
)
in 200..299 -> return Success(
- response.receive(),
+ response.body(),
response.status.value,
response.headers.toMap()
)
in 400..499 -> return ClientError(
- response.receive(),
+ response.body(),
response.status.value,
response.headers.toMap()
)
else -> return ServerError(
null,
- response.receive(),
+ response.body(),
response.status.value,
response.headers.toMap()
)
}
}
-} \ No newline at end of file
+}
diff --git a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
index e95e964..7f72392 100644
--- a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
+++ b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
@@ -18,11 +18,11 @@
package mx.trackermap.TrackerMap.client.infrastructure
import io.ktor.client.*
-import io.ktor.client.engine.ios.*
+import io.ktor.client.engine.darwin.*
actual class HttpClientProvider {
actual fun getHttpClient(): HttpClient {
- return HttpClient(Ios) {
+ return HttpClient(Darwin) {
engine {
configureSession {
HTTPCookieStorage = null
diff --git a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/NSDataByteArray.kt b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/NSDataByteArray.kt
index 807c63f..9d23296 100644
--- a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/NSDataByteArray.kt
+++ b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/NSDataByteArray.kt
@@ -37,4 +37,4 @@ fun NSData.toByteArray(): ByteArray = ByteArray(this@toByteArray.length.toInt())
usePinned {
memcpy(it.addressOf(0), this@toByteArray.bytes, this@toByteArray.length)
}
-} \ No newline at end of file
+}