Misar IO Docs

Kotlin SDK

Install and use the MisarBlog Kotlin SDK

Installation

Add to build.gradle.kts:

dependencies {
    implementation("io.misar:misarblog-kotlin:1.0.0")
}

Quick Start

import io.misar.blog.MisarBlogClient
import io.misar.blog.models.*

suspend fun main() {
    val client = MisarBlogClient(apiKey = System.getenv("MISARBLOG_API_KEY"))

    val posts = client.posts.list("johndoe")
    posts.data.forEach { println("${it.title} — ${it.slug}") }

    client.close()
}

Generate an Embed URL

val url = client.embed.url("johndoe", theme = "dark")
println(url)

// Single post
val postUrl = client.embed.url("johndoe", slug = "my-first-post", theme = "light")

Available Methods

| Method | Description | |--------|-------------| | client.posts.list(username, params) | List posts for a user | | client.posts.get(username, slug) | Get a single post by slug | | client.embed.url(username, slug, theme) | Generate an embed URL | | client.auth.refreshToken(token) | Refresh a session token | | client.webhooks.list() | List webhook endpoints | | client.webhooks.create(request) | Register a webhook | | client.webhooks.delete(id) | Delete a webhook | | client.close() | Close the HTTP client |

Error Handling

import io.misar.blog.exceptions.*

try {
    val posts = client.posts.list("johndoe")
} catch (e: MisarBlogApiException) {
    println("API error ${e.statusCode}: ${e.message}")
} catch (e: MisarBlogNetworkException) {
    println("Network error: ${e.message}")
}