diff --git a/fints4k/build.gradle b/fints4k/build.gradle index 4c2ce26b..bb1b34ec 100644 --- a/fints4k/build.gradle +++ b/fints4k/build.gradle @@ -71,20 +71,23 @@ kotlin { 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("net.dankito.web.client:kmp-web-client:1.0.0-SNAPSHOT") + implementation("io.ktor:ktor-client-core:$ktorVersion") } } commonTest { dependencies { implementation kotlin("test") + + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion") } } jvmMain { dependencies { + // or use client-java or client-okhttp? + implementation("io.ktor:ktor-client-cio:$ktorVersion") } } @@ -104,7 +107,7 @@ kotlin { jsMain { 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") + } + } + } } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/webclient/KtorWebClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/webclient/KtorWebClient.kt index 2c72b580..b748f629 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/webclient/KtorWebClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/webclient/KtorWebClient.kt @@ -2,8 +2,7 @@ package net.dankito.banking.fints.webclient import io.ktor.client.HttpClient import io.ktor.client.plugins.* -import io.ktor.client.request.post -import io.ktor.client.request.setBody +import io.ktor.client.request.* import io.ktor.client.statement.bodyAsText 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 { return postInCoroutine(url, body, contentType, userAgent) } diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/webclient/KtorWebClientTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/webclient/KtorWebClientTest.kt new file mode 100644 index 00000000..90dee804 --- /dev/null +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/webclient/KtorWebClientTest.kt @@ -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) + } + +} \ No newline at end of file