All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.app.moviebase.tmdb.api.TmdbDiscoverApi.kt Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version
package app.moviebase.tmdb.api

import app.moviebase.tmdb.discover.DiscoverCategory
import app.moviebase.tmdb.discover.DiscoverFactory
import app.moviebase.tmdb.model.*
import app.moviebase.tmdb.remote.*
import io.ktor.client.*
import io.ktor.client.request.*

class TmdbDiscoverApi(private val client: HttpClient) {

    suspend fun discoverByCategory(
        page: Int,
        language: String? = null,
        region: String? = null,
        category: DiscoverCategory
    ): TmdbPageResult {
        return when (val discover = DiscoverFactory.createByCategory(category)) {
            is TmdbDiscover.Movie -> discoverMovie(
                page = page,
                language = language,
                region = region,
                discover = discover
            )
            is TmdbDiscover.Show -> discoverShow(
                page = page,
                language = language,
                region = region,
                discover = discover
            )
        }
    }

    suspend fun discoverMovie(
        page: Int,
        language: String? = null,
        region: String? = null,
        discover: TmdbDiscover.Movie
    ): TmdbMoviePageResult = discoverMovie(
        page = page,
        language = language,
        region = region,
        parameters = discover.buildParameters()
    )

    suspend fun discoverMovie(
        page: Int,
        language: String? = null,
        region: String? = null,
        parameters: Map
    ): TmdbMoviePageResult = client.get {
        endPointV3("discover", "movie")
        parameterPage(page)
        parameterLanguage(language)
        parameterRegion(region)
        parameters(parameters)
    }

    suspend fun discoverShow(
        page: Int,
        language: String? = null,
        region: String? = null,
        discover: TmdbDiscover.Show
    ): TmdbShowPageResult = discoverShow(
        page = page,
        language = language,
        region = region,
        parameters = discover.buildParameters()
    )

    suspend fun discoverShow(
        page: Int,
        language: String? = null,
        region: String? = null,
        parameters: Map
    ): TmdbShowPageResult = client.get {
        endPointV3("discover", "tv")
        parameterPage(page)
        parameterLanguage(language)
        parameterRegion(region)
        parameters(parameters)
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy