diff options
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap')
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt | 41 |
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 +} |