Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/outadoc/mastodonk
Kotlin/Multiplatform library for Mastodon
https://github.com/outadoc/mastodonk
hacktoberfest kotlin kotlin-library kotlin-multiplatform mastodon mastodon-api
Last synced: about 2 months ago
JSON representation
Kotlin/Multiplatform library for Mastodon
- Host: GitHub
- URL: https://github.com/outadoc/mastodonk
- Owner: outadoc
- License: apache-2.0
- Created: 2021-04-24T18:28:56.000Z (over 3 years ago)
- Default Branch: develop
- Last Pushed: 2023-07-11T18:46:57.000Z (over 1 year ago)
- Last Synced: 2024-04-16T11:31:51.215Z (9 months ago)
- Topics: hacktoberfest, kotlin, kotlin-library, kotlin-multiplatform, mastodon, mastodon-api
- Language: Kotlin
- Homepage: https://outadoc.github.io/mastodonk
- Size: 2.93 MB
- Stars: 24
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mastodonk — A Kotlin/Multiplatform Mastodon API client
[![JVM Build](https://github.com/outadoc/mastodonk/actions/workflows/jvm-build.yml/badge.svg)](https://github.com/outadoc/mastodonk/actions/workflows/jvm-build.yml)
[![JS Build](https://github.com/outadoc/mastodonk/actions/workflows/js-build.yml/badge.svg)](https://github.com/outadoc/mastodonk/actions/workflows/js-build.yml)
[![Native Build](https://github.com/outadoc/mastodonk/actions/workflows/native-build.yml/badge.svg)](https://github.com/outadoc/mastodonk/actions/workflows/native-build.yml)
[![GitHub license](https://img.shields.io/github/license/outadoc/mastodonk)](https://github.com/outadoc/mastodonk/blob/develop/LICENSE)
![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/outadoc/mastodonk?include_prereleases)## Documentation
[API Reference](https://outadoc.github.io/mastodonk/)
## Setup
```kt
repositories {
maven { url = uri("https://nexus.outadoc.fr/repository/public") }
}kotlin {
sourceSets {
val commonMain by getting {
dependencies {
// Core library
implementation("fr.outadoc.mastodonk:mastodonk-core:+")// Paging library, use with androidx.paging v3 on JVM
implementation("fr.outadoc.mastodonk:mastodonk-paging:+")
}
}
}
}
```## Usage
Mastodonk provides a Kotlin-first API based on coroutines and Flows.
```kt
fun main() = runBlocking {val client = MastodonClient {
domain = "mastodon.social"
authTokenProvider = AuthTokenProvider {
// Provide an authentication token
AuthToken(accessToken = "your-access-token-here")
}
}GlobalScope.launch {
// Get some information about the configured instance
val instance = client.instance.getInstanceInfo()
println("connected to instance ${instance.title} at ${instance.uri}!")// Get a list of public toots
val toots = client.timelines.getPublicTimeline()// Get some #cats in your life
val catToots = client.timelines.getHashtagTimeline("cats")// Easy pagination
val moreCatToots = client.timelines.getHashtagTimeline(
"cats",
pageInfo = catToots.nextPage
)// Subscribe to streaming APIs and get a Flow
client.streaming.getPublicStream().collect { event ->
when (event) {
is UpdateEvent -> println("new status from ${event.payload.account.displayName}!")
else -> Unit
}
}}.join()
}
```