torbox-kmp-client

Interact with Torbox API via a typed client offering request/response models, ApiResult wrappers, category-based endpoints, torrent management helpers and bearer-token authentication.

Android JVMJVMKotlin/NativeJS
GitHub stars13
Dependents0
LicenseGNU General Public License v3.0
Creation dateabout 2 months ago

Last activityabout 17 hours ago
Latest release0.1.2 (about 17 hours ago)

torbox-kmp-client

This is a Kotlin multi platform library, created to easily interact with Torbox. It's still in beta; until 1.0.0 breaking changes and/or bugs may occur.

!! The library is currently working only for Kotlin/JVM targets, other targets are either broken or untested !!

This is my first library, please provide feedback if possible. AI has been used in small amounts to quickly refactor code after changes.

Importing the library

https://central.sonatype.com/artifact/io.github.livingwithhippos/torbox-kmp-client

build.gradle.kts

dependencies {
    implementation("io.github.livingwithhippos:torbox-kmp-client:0.1.2")
}

Usage

suspend fun main() {
    val client = TorboxClient.create(RestClientConfig(bearerToken = "YOUR-API-TOKEN"))

    // retrieve the torrent list
    val response = client.torrent.list()
    if (response is ApiResult.Success) {
        println(response.value)
    } else {
        println("Error: $response")
    }
}

Structure

The syntax is similar to the official APIs, the categories are the same, so General -> Get Up Status becomes client.general.upStatus(), usually if no verb is specified it's a request to get the resource.

The response objects are mostly modeled like this:

// class modeling the http call result

sealed interface ApiResult<out T> {
    data class Success<T>(
        val value: T,
    ) : ApiResult<T>

    sealed interface Failure : ApiResult<Nothing> {
        ...
        // failure classes
    }
}

interface ApiSuccessResponse {
    val success: Boolean
}

// class modeling the basic response, practically always returned by the service
@Serializable
data class ApiResponseDto<T>(
    override val success: Boolean,
    val error: String?,
    val detail: String,
    val data: T? = null,
) : ApiSuccessResponse

and val data: T has the requested data, depending on the requested API

A successful response to the torrent.get() function returns ApiResult<ApiResponseDto<TorrentDto>>, and the magnet field inside TorrentDto can be accessed like this:

if (response is ApiResult.Success) {
    println(response.value.data.magnet)
}

Notes

You can generate/retrieve the API token here

A test file, without the @Test keyword since it's using the real API, is available under jvmTest

Donate

ko-fi

Subscribe to Torbox with my referral link

... more will follow

Android JVMJVMKotlin/NativeJS
GitHub stars13
Dependents0
LicenseGNU General Public License v3.0
Creation dateabout 2 months ago

Last activityabout 17 hours ago
Latest release0.1.2 (about 17 hours ago)

torbox-kmp-client

This is a Kotlin multi platform library, created to easily interact with Torbox. It's still in beta; until 1.0.0 breaking changes and/or bugs may occur.

!! The library is currently working only for Kotlin/JVM targets, other targets are either broken or untested !!

This is my first library, please provide feedback if possible. AI has been used in small amounts to quickly refactor code after changes.

Importing the library

https://central.sonatype.com/artifact/io.github.livingwithhippos/torbox-kmp-client

build.gradle.kts

dependencies {
    implementation("io.github.livingwithhippos:torbox-kmp-client:0.1.2")
}

Usage

suspend fun main() {
    val client = TorboxClient.create(RestClientConfig(bearerToken = "YOUR-API-TOKEN"))

    // retrieve the torrent list
    val response = client.torrent.list()
    if (response is ApiResult.Success) {
        println(response.value)
    } else {
        println("Error: $response")
    }
}

Structure

The syntax is similar to the official APIs, the categories are the same, so General -> Get Up Status becomes client.general.upStatus(), usually if no verb is specified it's a request to get the resource.

The response objects are mostly modeled like this:

// class modeling the http call result

sealed interface ApiResult<out T> {
    data class Success<T>(
        val value: T,
    ) : ApiResult<T>

    sealed interface Failure : ApiResult<Nothing> {
        ...
        // failure classes
    }
}

interface ApiSuccessResponse {
    val success: Boolean
}

// class modeling the basic response, practically always returned by the service
@Serializable
data class ApiResponseDto<T>(
    override val success: Boolean,
    val error: String?,
    val detail: String,
    val data: T? = null,
) : ApiSuccessResponse

and val data: T has the requested data, depending on the requested API

A successful response to the torrent.get() function returns ApiResult<ApiResponseDto<TorrentDto>>, and the magnet field inside TorrentDto can be accessed like this:

if (response is ApiResult.Success) {
    println(response.value.data.magnet)
}

Notes

You can generate/retrieve the API token here

A test file, without the @Test keyword since it's using the real API, is available under jvmTest

Donate

ko-fi

Subscribe to Torbox with my referral link

... more will follow