yamibo-api
1.1.16indexedPurely functional, highly asynchronous forum client handling network requests, session management and HTML parsing into strongly-typed DTOs, with async-first API and safe sealed-result handling.
Purely functional, highly asynchronous forum client handling network requests, session management and HTML parsing into strongly-typed DTOs, with async-first API and safe sealed-result handling.
| Dependency | Supported Version |
|---|---|
| Kotlin | 2.3.10+ |
| Gradle | 8.14.3+ |
Add the dependency to your build.gradle.kts:
dependencies {
implementation("io.github.littlesurvival:yamibo-api:$version")
}
Include the following in your pom.xml:
<dependency>
<groupId>io.github.littlesurvival</groupId>
<artifactId>yamibo-api</artifactId>
<version>$version</version>
</dependency>
The entry point of the library is the YamiboClient. Most Yamibo routes require authentication, so you must supply the user's cookie.
import io.github.littlesurvival.YamiboClient
import io.github.littlesurvival.fetch.FetchFactory
// 1. Create a client instance
val client = YamiboClient(
device = FetchFactory.Companion.Device.MOBILE, // Simulates mobile requests
timeoutMillis = 30_000L // 30 seconds timeout
)
// 2. Set the user authentication cookie
client.setCookie("your_user_cookie_here")
All methods return a YamiboResult<T>, ensuring you handle all edge cases elegantly.
import io.github.littlesurvival.core.YamiboResult
suspend fun fetchYamiboHome() {
when (val result = client.fetchHomePage()) {
YamiboResult.Success -> {
homePage = result.value
println()
}
YamiboResult.NotLoggedIn -> {
println()
}
YamiboResult.Maintenance -> {
println()
}
YamiboResult.Failure -> {
println()
}
}
}
Fetching a Forum Page:
import io.github.littlesurvival.dto.value.ForumId
suspend fun loadForum() {
// Fetch forum layout and threads on page 1
val forumResult = client.fetchForumById(ForumId(5), page = 1)
}
Fetching a Thread Context:
import io.github.littlesurvival.dto.value.ThreadId
suspend fun loadThread() {
// Fetch posts and details within a specific thread
val threadResult = client.fetchThreadById(ThreadId(12345), page = 1)
}
Fetching User Profile:
suspend fun loadProfile() {
// Requires a valid cookie to parse current user details
val profileResult = client.fetchProfileInfo()
}
Searching the Forum:
import io.github.littlesurvival.dto.value.FormHash
suspend fun doSearch() {
val searchResult = client.fetchSearch(
query = "Yuri",
forumId = null, // Optional: Search within a specific forum
formHash = FormHash("your_form_hash") // Security token
)
}
Interactions (Replying, Rating, Favorites):
import io.github.littlesurvival.dto.value.PostId
suspend fun interact() {
// Add thread to favorites
client.fetchAddFavorite(ThreadId(12345), FormHash("your_form_hash"))
client.fetchReplyPost(ThreadId(), PostId(), , FormHash())
client.fetchRatePost(ThreadId(), PostId(), score = , reason = , FormHash())
}
| 依賴項目 | 支援版本 |
|---|---|
| Kotlin | 2.3.10+ |
| Gradle | 8.14.3+ |
| Java JVM 目標 |
請在模組內的 build.gradle.kts 新增依賴:
dependencies {
implementation("io.github.littlesurvival:yamibo-api:$version")
}
如果你的專案使用 Maven 建置環境,請在 pom.xml 加入配置:
<dependency>
<groupId>io.github.littlesurvival</groupId>
<artifactId>yamibo-api</artifactId>
<version>$version</version>
</dependency>
操作本函式庫最核心的點位就是 YamiboClient。由於大多數的 Yamibo 網站路由都需要論壇使用者權限,你必須利用方法設定有效的使用者 Cookie。
import io.github.littlesurvival.YamiboClient
import io.github.littlesurvival.fetch.FetchFactory
// 1. 建立 Client 實體物件
val client = YamiboClient(
device = FetchFactory.Companion.Device.MOBILE, // 模擬手機端請求 (此為預設值)
timeoutMillis = 30_000L // 設定超時時間為 30 秒鐘
)
// 2. 寫入使用者的認證 Cookie
client.setCookie("請輸入你的_user_cookie")
所有牽涉到網路的 API 方法都會回傳 YamiboResult<T>,這項類別會幫助你應對各種網路和未知的解析情況。
import io.github.littlesurvival.core.YamiboResult
suspend fun fetchYamiboHome() {
when (val result = client.fetchHomePage()) {
is YamiboResult.Success -> {
homePage = result.value
println()
}
YamiboResult.NotLoggedIn -> {
println()
}
YamiboResult.Maintenance -> {
println()
}
YamiboResult.Failure -> {
println()
}
}
}
讀取特定看板 (Forum):
import io.github.littlesurvival.dto.value.ForumId
suspend fun loadForum() {
// 取得版塊編號為 5 的第一頁主題與貼文列表
val forumResult = client.fetchForumById(ForumId(5), page = 1)
}
讀取討論串內容 (Thread):
import io.github.littlesurvival.dto.value.ThreadId
suspend fun loadThread() {
// 取得特定討論串的內容與它的各樓層回覆列表
val threadResult = client.fetchThreadById(ThreadId(12345), page = 1)
}
取得當前使用者資訊 (Profile):
suspend fun loadProfile() {
// 發出請求,解析並獲得當前登入使用者的個人資訊、頭像與相關統計數據
val profileResult = client.fetchProfileInfo()
}
全站或特定看板內搜尋 (Search):
import io.github.littlesurvival.dto.value.FormHash
suspend fun doSearch() {
val searchResult = client.fetchSearch(
query = "百合",
forumId = null, // 選填項目:可指定要搜尋的看板 ID
formHash = FormHash("請填入你的_form_hash") // 必要的安全驗證碼
)
}
各類使用者網頁操作 (發出回覆、給予評分、收藏文章):
import io.github.littlesurvival.dto.value.PostId
suspend fun interact() {
// 將文章加入至我的使用者收藏內
client.fetchAddFavorite(ThreadId(12345), FormHash("你的_form_hash"))
client.fetchReplyPost(ThreadId(), PostId(), , FormHash())
client.fetchRatePost(ThreadId(), PostId(), score = , reason = , FormHash())
}
ProfilePage, ThreadPage, and ForumPage data immediately.YamiboResult sealed class wrapping Success, Failure, Maintenance, and NotLoggedIn states.| 11+ |
ProfilePage、ThreadPage 與 ForumPage 等豐富的結構化資料表。YamiboResult 封裝,妥善且優雅地處理 Success (成功)、Failure (失敗)、Maintenance (維護中) 以及 NotLoggedIn (未登入) 等各種極端狀態。| 11+ |
Surfaced from shared tags and platforms — no rankings paid for.