Skip to content

The Builtbybit API Wrapper for Kotlin with the support of coroutines

Notifications You must be signed in to change notification settings

LeeGodSRC/builtbybit-kotlin-api-wrapper

Repository files navigation

builtbybit-kotlin-api-wrapper


A Kotlin wrapper for the BuiltByBit Ultimate API built with Kotlin and KotlinX in combination with the Ktor HTTP Client and KotlinX Coroutines.

Most of the data structures are copied from the BuiltByBit Java API Wrapper by swanis, You will find a lot of similarities in the code.

Send a request


val client = BBBClient(Token("TOKEN STRING", Type.PRIVATE))

runBlocking {
    val response = client.healthReport()
    println(response)

    val member = client.retrieveYourself()
    println(member)
}

Every request action are suspend functions, so you can use them in a coroutine scope.

You can find every request action in the extension functions class BBBClientRequestExtensions.kt.

Exception Handling


When a request failed, It will throw a RequestException. There are 3 types of exceptions:

  • RequestErrorException - When the request failed and send from server side. (Maybe a server side error, or a bad request)
  • RequestThrowsException - When the request failed because it throws an exception during processing. (Deserialization error, timeout, etc.)
  • RequestRateLimitedException - When the request failed because the request is rate limited. (You can get the retry after value from the exception)
    • You wouldn't need to handle this exception when you have wait parameter as true.

Sorting


Sorting is done by passing a SortOptions object into the request action parameters.

val client = BBBClient(Token("TOKEN STRING", Type.PRIVATE))

runBlocking {
    val resourceArray = client.listPublicResources(SortOptions(
        "purchase_count",
        Order.DESCENDING,
        1
    ))

    println(resourceArray)
}

JitPack Installation


Gradle Groovy

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.LeeGodSRC:builtbybit-kotlin-api-wrapper:Tag'
}

Gradle Kotlin

repositories {
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.github.LeeGodSRC:builtbybit-kotlin-api-wrapper:Tag")
}

About

The Builtbybit API Wrapper for Kotlin with the support of coroutines

Resources

Stars

Watchers

Forks

Packages

No packages published