From ab3df6b0019c932ec38c073daa1a77740382425d Mon Sep 17 00:00:00 2001 From: Bruno Wieczorek Date: Sun, 1 Sep 2024 10:21:20 +0200 Subject: [PATCH] Refactor example --- example/src/main/kotlin/SimpleExample.kt | 19 +++++++++++++++++-- .../src/main/kotlin/model/FakeProfileLite.kt | 16 ---------------- .../src/main/kotlin/model/GithubProfile.kt | 1 + 3 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 example/src/main/kotlin/model/FakeProfileLite.kt diff --git a/example/src/main/kotlin/SimpleExample.kt b/example/src/main/kotlin/SimpleExample.kt index f8eeea3..577ffba 100644 --- a/example/src/main/kotlin/SimpleExample.kt +++ b/example/src/main/kotlin/SimpleExample.kt @@ -1,5 +1,8 @@ + import dev.burnoo.ksoup.Kspoon -import model.FakeProfileLite +import dev.burnoo.ksoup.annotation.Selector +import kotlinx.serialization.Serializable +import model.GithubProfile private const val HTML_CONTENT = """

burnoo - GitHub

@@ -10,13 +13,25 @@ private const val HTML_CONTENT = """ """ +@Serializable +data class FakeGitHubProfile( + @Selector("h1", regex = "(.*) - GitHub") + val username: String, + @Selector("img[id=avatar]", attr = "abs:src") + val avatarUrl: String, + @Selector("li") + val interests: List, + @Selector(".pinned-repositories") + val pinnedRepositories: List = emptyList(), +) + fun simpleExample() { val ksoup = Kspoon { parse = { html -> parse(html, baseUri = "https://github.com/") } coerceInputValues = true } - val profile = ksoup.parse(HTML_CONTENT) + val profile = ksoup.parse(HTML_CONTENT) println("Display name: ${profile.username}") println("Avatar url: ${profile.avatarUrl}") diff --git a/example/src/main/kotlin/model/FakeProfileLite.kt b/example/src/main/kotlin/model/FakeProfileLite.kt deleted file mode 100644 index 8a89ed0..0000000 --- a/example/src/main/kotlin/model/FakeProfileLite.kt +++ /dev/null @@ -1,16 +0,0 @@ -package model - -import dev.burnoo.ksoup.annotation.Selector -import kotlinx.serialization.Serializable - -@Serializable -data class FakeProfileLite( - @Selector("h1", regex = "(.*) - GitHub") - val username: String, - @Selector("img[id=avatar]", attr = "abs:src") - val avatarUrl: String, - @Selector("li") - val interests : List, - @Selector(".pinned-repositories") - val pinnedRepositories: List = emptyList(), -) diff --git a/example/src/main/kotlin/model/GithubProfile.kt b/example/src/main/kotlin/model/GithubProfile.kt index 40575fe..87ab1cd 100644 --- a/example/src/main/kotlin/model/GithubProfile.kt +++ b/example/src/main/kotlin/model/GithubProfile.kt @@ -16,6 +16,7 @@ data class GithubProfile( data class PinnedRepository( @Selector("span.repo") val name: String, + @Selector("a.pinned-item-meta", regex = "[0-9]+") val starNumbers: Int, )