Replaced kmp-web-client with directly configuring Ktor
This commit is contained in:
parent
e96f184934
commit
0ce74a0688
|
@ -71,20 +71,23 @@ kotlin {
|
||||||
|
|
||||||
implementation "co.touchlab:stately-concurrency:1.2.0"
|
implementation "co.touchlab:stately-concurrency:1.2.0"
|
||||||
|
|
||||||
implementation "io.ktor:ktor-client-core:$ktorVersion" // only left here cause kmp-web-client doesn't expose ktor as api
|
implementation("io.ktor:ktor-client-core:$ktorVersion")
|
||||||
implementation("net.dankito.web.client:kmp-web-client:1.0.0-SNAPSHOT")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commonTest {
|
commonTest {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin("test")
|
implementation kotlin("test")
|
||||||
|
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
jvmMain {
|
jvmMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// or use client-java or client-okhttp?
|
||||||
|
implementation("io.ktor:ktor-client-cio:$ktorVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +107,7 @@ kotlin {
|
||||||
|
|
||||||
jsMain {
|
jsMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation("io.ktor:ktor-client-js:$ktorVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,5 +121,23 @@ kotlin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linuxMain {
|
||||||
|
dependencies {
|
||||||
|
implementation("io.ktor:ktor-client-curl:$ktorVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mingwMain {
|
||||||
|
dependencies {
|
||||||
|
implementation("io.ktor:ktor-client-winhttp:$ktorVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
appleMain {
|
||||||
|
dependencies {
|
||||||
|
implementation("io.ktor:ktor-client-darwin:$ktorVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,7 @@ package net.dankito.banking.fints.webclient
|
||||||
|
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.plugins.*
|
import io.ktor.client.plugins.*
|
||||||
import io.ktor.client.request.post
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.request.setBody
|
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
import io.ktor.http.contentType
|
import io.ktor.http.contentType
|
||||||
|
@ -38,6 +37,14 @@ open class KtorWebClient(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun get(url: String): WebClientResponse {
|
||||||
|
val clientResponse = client.get(url)
|
||||||
|
|
||||||
|
val responseBody = clientResponse.bodyAsText()
|
||||||
|
|
||||||
|
return WebClientResponse(clientResponse.status.value == 200, clientResponse.status.value, body = responseBody)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun post(url: String, body: String, contentType: String, userAgent: String): WebClientResponse {
|
override suspend fun post(url: String, body: String, contentType: String, userAgent: String): WebClientResponse {
|
||||||
return postInCoroutine(url, body, contentType, userAgent)
|
return postInCoroutine(url, body, contentType, userAgent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package net.dankito.banking.fints.webclient
|
||||||
|
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
class KtorWebClientTest {
|
||||||
|
|
||||||
|
private val underTest = KtorWebClient()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun get() = runTest {
|
||||||
|
val result = underTest.get("https://staging.dankito.net/bankfinder?maxItems=1&query=720")
|
||||||
|
|
||||||
|
assertTrue(result.successful)
|
||||||
|
assertEquals(200, result.responseCode)
|
||||||
|
assertNotNull(result.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue