Skip to content

Commit b7dd172

Browse files
committed
Add integration with ktor-client
1 parent 52306e0 commit b7dd172

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

dataframe-jupyter/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ group = "org.jetbrains.kotlinx"
88

99
repositories {
1010
mavenCentral()
11+
maven("https://packages.jetbrains.team/maven/p/kds/kotlin-ds-maven")
1112
}
1213

1314
dependencies {
1415
compileOnly(project(":core"))
16+
compileOnly(libs.jupyter.ktor.client)
1517
testImplementation(libs.junit)
1618
testImplementation(libs.serialization.json)
1719
testImplementation(project(":core"))
20+
testImplementation(libs.jupyter.ktor.client)
1821
testImplementation(libs.kotestAssertions) {
1922
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
2023
}

dataframe-jupyter/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/Integration.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ internal class Integration(
267267
import("org.jetbrains.kotlinx.dataframe.jupyter.ImportDataSchema")
268268
import("org.jetbrains.kotlinx.dataframe.jupyter.importDataSchema")
269269
import("org.jetbrains.kotlinx.dataframe.jupyter.KotlinNotebookPluginUtils")
270+
import("org.jetbrains.kotlinx.dataframe.jupyter.bodyAsDataFrame")
270271
import("java.net.URL")
271272
import("java.io.File")
272273
import("kotlinx.datetime.Instant")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jetbrains.kotlinx.dataframe.jupyter
2+
3+
import org.jetbrains.kotlinx.dataframe.DataFrame
4+
import org.jetbrains.kotlinx.dataframe.io.readJsonStr
5+
import org.jetbrains.kotlinx.jupyter.ktor.client.core.NotebookHttpResponse
6+
7+
public fun NotebookHttpResponse.bodyAsDataFrame(): DataFrame<*> {
8+
return DataFrame.readJsonStr(bodyAsText())
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.jetbrains.kotlinx.dataframe.jupyter
2+
3+
import org.jetbrains.kotlinx.jupyter.testkit.JupyterReplTestCase
4+
import org.jetbrains.kotlinx.jupyter.testkit.ReplProvider
5+
import org.junit.Test
6+
7+
class KtorClientIntegrationTest : JupyterReplTestCase(ReplProvider.forLibrariesTesting(listOf("dataframe", "ktor-client"))) {
8+
@Test
9+
fun `extension function for NotebookHttpResponse is available`() {
10+
execRaw("""%use dataframe""")
11+
execRaw("""%use ktor-client""")
12+
val test = """
13+
fun test() {
14+
http.get("https://raw.githubusercontent.com/Kotlin/dataframe/master/data/jetbrains.json").bodyAsDataFrame()
15+
}""".trimIndent()
16+
execRaw(test)
17+
}
18+
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ kotlinDatetime = "0.6.0"
4040
openapi = "2.1.20"
4141
kotlinLogging = "6.0.3"
4242
sl4j = "2.0.12"
43+
ktorClient = "0.2.0-dev-11"
4344

4445
junit = "4.13.2"
4546
junit-jupiter = "5.10.2"
@@ -64,6 +65,7 @@ duckdb = "0.10.0"
6465
ksp-gradle = { group = "com.google.devtools.ksp", name = "symbol-processing-gradle-plugin", version.ref = "ksp" }
6566
ksp-api = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" }
6667
jupyter-api = { group = "org.jetbrains.kotlinx", name = "kotlin-jupyter-kernel", version.ref = "kotlinJupyter" }
68+
jupyter-ktor-client = { group = "org.jetbrains.kotlinx", name = "kotlin-jupyter-ktor-client", version.ref = "ktorClient"}
6769

6870
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
6971
kotlin-stdlib-jdk8 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" }

0 commit comments

Comments
 (0)