aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-09-16 16:13:33 -0600
committerIván Ávalos <avalos@disroot.org>2023-09-16 16:13:33 -0600
commitbe1aa14b94e435488864aa77d895ad8d93865d7c (patch)
tree713cf49fb6e8516788a437a91730d7d56540a384 /shared/src/commonMain/kotlin/mx
parent6c69520fc2a968cb27d1f751f34a123205936567 (diff)
downloadetbsa-trackermap-mobile-be1aa14b94e435488864aa77d895ad8d93865d7c.tar.gz
etbsa-trackermap-mobile-be1aa14b94e435488864aa77d895ad8d93865d7c.tar.bz2
etbsa-trackermap-mobile-be1aa14b94e435488864aa77d895ad8d93865d7c.zip
- [shared] Downgrade Kotlin to 1.8.22 due to Native issues
- [shared] Upgrade Ktor to 2.3.4 and migrate code - [ios] Update view models to use @MainActor and Kotlin migrations
Diffstat (limited to 'shared/src/commonMain/kotlin/mx')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt41
1 files changed, 18 insertions, 23 deletions
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
+}