Giter Club home page Giter Club logo

trakt-kotlin's Introduction

Website | Support | Documentation

Trakt

Track and discover your TV shows and movies with Trakt.

Maven Central Github Actions Issues Kotlin Gradle GitHub License GitHub Account


Trakt Kotlin

Trakt Kotlin is a Kotlin Multiplatform library for tracking your series and movies.

  • Written in Kotlin native with ktor from the ground up.
  • Support for Android, iOS, desktop, and web applications.
  • High customizable HttpClient configuration

Sample projects:

Setup

The library is available on Maven Central.

Gradle

Add the Maven Central repository if it is not already there.

repositories {
    mavenCentral()
}

To use the library in a single-platform project, add a dependency.

dependencies {
    implementation("app.moviebase:trakt-api:0.6.0")
}

In Kotlin Multiplatform projects, add the dependency to your commonMain source-set dependencies.

commonMain {
    dependencies {
        implementation("app.moviebase:trakt-api:0.6.0")
    }
}

Usage

Most of the library follows the possibilities and naming at the official Trakt documentation.

Configuration

Build up your Trakt instance to access the APIs. You can configure the entire HttpClient of ktor.

val trakt = Trakt {
    traktApiKey = "clientId"

    expectSuccess = false // if you want to disable exceptions
    useCache = true
    useTimeout = true
    maxRetriesOnException = 3 // retries when network calls throw an exception

    // add your own client
    httpClient(OkHttp) {
        engine {

        }
    }

    httpClient {
        // for custom HttpClient configuration
    }
}

Get information

For getting basic information about a shows or other media content.

val trakt = Trakt("clientId")
val traktShow = trakt.shows.getSummary(traktSlug = "vikings")

Search

Search for TV shows by a query.

val trakt = Trakt("clientId")
val showPageResult = trakt.search.search(
    searchType = TraktSearchType.TMDB,
    id = "63639",
    mediaType = TraktMediaType.SHOW
)

Contributing 🀝

Please feel free to open an issue if you have any questions or suggestions. Or participate in the discussion. If you want to contribute, please read the contribution guidelines for more information.



This library uses the Trakt but is not endorsed or certified by Trakt.

trakt-kotlin's People

Contributors

chrisbanes avatar chriskruegerdev avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trakt-kotlin's Issues

Not handling HTTP 429 responses

I got the following exception logged in Crashlytics:

Exception: Uj: Client request(POST https://api.trakt.tv/sync/history) invalid: 429 . Text: "AUTHED_API_POST_LIMIT rate limit exceeded. Please wait 1 seconds then retry your request."
       at io.ktor.client.plugins.DefaultResponseValidationKt$addDefaultResponseValidation$1$1.invokeSuspend(DefaultResponseValidation.kt:54)
       at io.ktor.client.plugins.DefaultResponseValidationKt$addDefaultResponseValidation$1$1.invoke(DefaultResponseValidation.kt:13)
       at io.ktor.client.plugins.DefaultResponseValidationKt$addDefaultResponseValidation$1$1.invoke(DefaultResponseValidation.kt:13)
       at io.ktor.client.plugins.HttpCallValidator.validateResponse(HttpCallValidator.kt:51)
       at io.ktor.client.plugins.HttpCallValidator.access$validateResponse(HttpCallValidator.kt:43)
       at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invokeSuspend(HttpCallValidator.kt:152)

We should add retry backoff.

IllegalStateException: Fail to prepare request body for sending when posting TraktSyncItems

Looks like we need to hook up the polymorphic serializers for posting.

Error:

java.lang.IllegalStateException: Fail to prepare request body for sending. 
The body type is: class app.moviebase.trakt.model.TraktSyncItems (Kotlin reflection is not available), with Content-Type: null.
   
If you expect serialized body, please check that you have installed the corresponding plugin(like `ContentNegotiation`) and set `Content-Type` header.
    at io.ktor.client.plugins.HttpSend$Plugin$install$1.invokeSuspend(HttpSend.kt:88)
    at io.ktor.client.plugins.HttpSend$Plugin$install$1.invoke(Unknown Source:15)
    at io.ktor.client.plugins.HttpSend$Plugin$install$1.invoke(Unknown Source:4)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceedWith(SuspendFunctionGun.kt:88)
    at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invokeSuspend(HttpCallValidator.kt:130)
    at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(Unknown Source:13)
    at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(Unknown Source:4)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
    at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invokeSuspend(HttpRequestLifecycle.kt:38)
    at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(Unknown Source:11)
    at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(Unknown Source:4)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
    at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
    at io.ktor.client.HttpClient.execute$ktor_client_core(HttpClient.kt:191)
    at io.ktor.client.statement.HttpStatement.executeUnsafe(HttpStatement.kt:108)
    at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:47)
    at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:62)
    at app.moviebase.trakt.api.TraktSyncApi.removeWatchedHistory(TraktSyncApi.kt:94)

Complete Takt API

  • Refactor HttpClient building and lazy initialization
  • Add HttpClient configuration
  • Use defaultRequests
  • User Coroutines tests
  • Add missing endpoints (pending)

Facelift the project

Adopt the same facelift as in the project MoviebaseApp/tmdb-api.

  • Reorganize tags & folders
  • Add Github Action
  • Integrate dependabot
  • Automatically snapshot publishing
  • Add Gradle catalog & update all libraries
  • Add spotless / klint
  • Update README

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.