mirror of
https://github.com/owenlejeune/TVTime.git
synced 2025-11-10 05:42:43 -05:00
foundation for api v4
This commit is contained in:
@@ -22,6 +22,7 @@ android {
|
||||
}
|
||||
|
||||
buildConfigField("String", "TMDB_ApiKey", TMDB_ApiKey)
|
||||
buildConfigField("String", "TMDB_Api_v4Key", TMDB_Api_v4Key)
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
package com.owenlejeune.tvtime.api
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonDeserializer
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class GsonConverter: Converter, KoinComponent {
|
||||
|
||||
private val deserializers: Map<Class<*>, JsonDeserializer<*>> by inject()
|
||||
|
||||
class GsonConverter: Converter {
|
||||
override fun get(): retrofit2.Converter.Factory {
|
||||
val gson = GsonBuilder()
|
||||
.create()
|
||||
// val gson = GsonBuilder()
|
||||
// .registerTypeAdapter()
|
||||
// .create()
|
||||
val builder = GsonBuilder()
|
||||
|
||||
deserializers.forEach { deserializer ->
|
||||
builder.registerTypeAdapter(deserializer.key, deserializer.value)
|
||||
}
|
||||
|
||||
val gson = builder.create()
|
||||
|
||||
return GsonConverterFactory.create(gson)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import androidx.compose.ui.text.intl.Locale
|
||||
import com.owenlejeune.tvtime.BuildConfig
|
||||
import com.owenlejeune.tvtime.api.Client
|
||||
import com.owenlejeune.tvtime.api.QueryParam
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v4.AuthenticationV4Api
|
||||
import com.owenlejeune.tvtime.extensions.addQueryParams
|
||||
import com.owenlejeune.tvtime.preferences.AppPreferences
|
||||
import com.owenlejeune.tvtime.utils.SessionManager
|
||||
@@ -16,14 +18,17 @@ import org.koin.core.parameter.parametersOf
|
||||
class TmdbClient: KoinComponent {
|
||||
|
||||
companion object {
|
||||
const val BASE_URL = "https://api.themoviedb.org/3/"
|
||||
const val V_3_BASE_URL = "https://api.themoviedb.org/3/"
|
||||
const val V_4_BASE_URL = "https://api.themoviedb.org/4/"
|
||||
}
|
||||
|
||||
private val client: Client by inject { parametersOf(BASE_URL) }
|
||||
private val client: Client by inject { parametersOf(V_3_BASE_URL) }
|
||||
private val clientV4: Client by inject { parametersOf(V_4_BASE_URL) }
|
||||
private val preferences: AppPreferences by inject()
|
||||
|
||||
init {
|
||||
client.addInterceptor(TmdbInterceptor())
|
||||
clientV4.addInterceptor(V4Interceptor())
|
||||
}
|
||||
|
||||
fun createMovieService(): MoviesApi {
|
||||
@@ -42,6 +47,10 @@ class TmdbClient: KoinComponent {
|
||||
return client.create(AuthenticationApi::class.java)
|
||||
}
|
||||
|
||||
fun createV4AuthenticationService(): AuthenticationV4Api {
|
||||
return clientV4.create(AuthenticationV4Api::class.java)
|
||||
}
|
||||
|
||||
fun createGuestSessionService(): GuestSessionApi {
|
||||
return client.create(GuestSessionApi::class.java)
|
||||
}
|
||||
@@ -61,22 +70,41 @@ class TmdbClient: KoinComponent {
|
||||
val segments = chain.request().url.encodedPathSegments
|
||||
val sessionIdParam: QueryParam? = sessionIdParam(segments)
|
||||
|
||||
val request = chain.addQueryParams(apiParam, languageParam, sessionIdParam)
|
||||
val builder = chain.request().url.newBuilder()
|
||||
builder.addQueryParams(apiParam, languageParam, sessionIdParam)
|
||||
val requestBuilder = chain.request().newBuilder().url(builder.build())
|
||||
|
||||
val request = requestBuilder.build()
|
||||
return chain.proceed(request)
|
||||
}
|
||||
|
||||
private fun sessionIdParam(urlSegments: List<String>): QueryParam? {
|
||||
var sessionIdParam: QueryParam? = null
|
||||
if (urlSegments.size > 1 && urlSegments[1] == "account") {
|
||||
if (SessionManager.currentSession?.isAuthorized == true) {
|
||||
sessionIdParam = QueryParam("session_id", SessionManager.currentSession!!.sessionId)
|
||||
} else if (preferences.authorizedSessionId.isNotEmpty()) {
|
||||
sessionIdParam = QueryParam("session_id", preferences.authorizedSessionId)
|
||||
}
|
||||
}
|
||||
return sessionIdParam
|
||||
}
|
||||
}
|
||||
|
||||
private fun sessionIdParam(urlSegments: List<String>): QueryParam? {
|
||||
var sessionIdParam: QueryParam? = null
|
||||
if (urlSegments.size > 1 && urlSegments[1] == "account") {
|
||||
if (SessionManager.currentSession?.isAuthorized == true) {
|
||||
sessionIdParam = QueryParam("session_id", SessionManager.currentSession!!.sessionId)
|
||||
} else if (preferences.authorizedSessionId.isNotEmpty()) {
|
||||
sessionIdParam = QueryParam("session_id", preferences.authorizedSessionId)
|
||||
}
|
||||
private inner class V4Interceptor: Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val builder = chain.request().newBuilder()
|
||||
builder.header("Authorization", "Bearer ${BuildConfig.TMDB_Api_v4Key}")
|
||||
|
||||
val locale = Locale.current
|
||||
val languageCode = "${locale.language}-${locale.region}"
|
||||
val languageParam = QueryParam("language", languageCode)
|
||||
|
||||
val url = chain.request().url.newBuilder().addQueryParams(languageParam).build()
|
||||
builder.url(url)
|
||||
|
||||
return chain.proceed(builder.build())
|
||||
}
|
||||
return sessionIdParam
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import retrofit2.Response
|
||||
|
||||
class AccountService {
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import retrofit2.Response
|
||||
|
||||
class AuthenticationService {
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import retrofit2.Response
|
||||
|
||||
interface DetailService {
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedEpisode
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedMediaResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedMovie
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedTv
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedEpisode
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedMediaResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedMovie
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedTv
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedEpisode
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedMediaResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedMovie
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.RatedTv
|
||||
import retrofit2.Response
|
||||
|
||||
class GuestSessionService {
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.HomePageResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.HomePageResponse
|
||||
import retrofit2.Response
|
||||
|
||||
interface HomePageService {
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import com.owenlejeune.tvtime.utils.SessionManager
|
||||
import org.koin.core.component.KoinComponent
|
||||
import retrofit2.Response
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.DetailPerson
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.HomePagePeopleResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.PersonCreditsResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.PersonImageCollection
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.DetailPerson
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.HomePagePeopleResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.PersonCreditsResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.PersonImageCollection
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.DetailPerson
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.HomePagePeopleResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.PersonCreditsResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.PersonImageCollection
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.DetailPerson
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.HomePagePeopleResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.PersonCreditsResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.PersonImageCollection
|
||||
import org.koin.core.component.KoinComponent
|
||||
import retrofit2.Response
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.*
|
||||
import com.owenlejeune.tvtime.utils.SessionManager
|
||||
import org.koin.core.component.KoinComponent
|
||||
import retrofit2.Response
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.owenlejeune.tvtime.ui.screens.MediaViewType
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.owenlejeune.tvtime.ui.screens.MediaViewType
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
class HomePageMovie(
|
||||
id: Int,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
class HomePageTv(
|
||||
id: Int,
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.owenlejeune.tvtime.ui.screens.MediaViewType
|
||||
|
||||
class MarkAsFavoriteBody(
|
||||
@SerializedName("media_type") val mediaType: String, // media type
|
||||
@SerializedName("media_type") val mediaType: MediaViewType,
|
||||
@SerializedName("media_id") val mediaId: Int,
|
||||
@SerializedName("favorite") val isFavorite: Boolean
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.owenlejeune.tvtime.R
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.owenlejeune.tvtime.R
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.owenlejeune.tvtime.ui.screens.MediaViewType
|
||||
|
||||
class WatchlistBody(
|
||||
@SerializedName("media_type") val mediaType: String, // media type
|
||||
@SerializedName("media_type") val mediaType: MediaViewType,
|
||||
@SerializedName("media_id") val mediaId: Int,
|
||||
@SerializedName("watchlist") val onWatchlist: Boolean
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.model
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v3.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.StatusResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v4.model.*
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.DELETE
|
||||
import retrofit2.http.POST
|
||||
|
||||
interface AuthenticationV4Api {
|
||||
|
||||
@POST("auth/request_token")
|
||||
suspend fun createRequestToken(body: AuthRequestBody): Response<AuthResponse>
|
||||
|
||||
@POST("auth/access_token")
|
||||
suspend fun createAccessToken(body: AuthAccessBody): Response<AccessResponse>
|
||||
|
||||
@DELETE("auth/access_token")
|
||||
suspend fun deleteAccessToken(body: AuthDeleteBody): Response<StatusResponse>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.StatusResponse
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v4.model.*
|
||||
import retrofit2.Response
|
||||
|
||||
class AuthenticationV4Service {
|
||||
|
||||
private val service by lazy { TmdbClient().createV4AuthenticationService() }
|
||||
|
||||
suspend fun createRequestToken(body: AuthRequestBody): Response<AuthResponse> {
|
||||
return service.createRequestToken(body)
|
||||
}
|
||||
|
||||
suspend fun createAccessToken(body: AuthAccessBody): Response<AccessResponse> {
|
||||
return service.createAccessToken(body)
|
||||
}
|
||||
|
||||
suspend fun deleteAccessToken(body: AuthDeleteBody): Response<StatusResponse> {
|
||||
return service.deleteAccessToken(body)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v4.model.*
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.*
|
||||
|
||||
interface ListV4Api {
|
||||
|
||||
@GET("list/{id}")
|
||||
suspend fun getLists(
|
||||
@Path("id") listId: Int,
|
||||
@Query("api_key") apiKey: String,
|
||||
@Query("page") page: Int = 1
|
||||
): Response<MediaList>
|
||||
|
||||
@POST("list")
|
||||
suspend fun createList(body: CreateListBody): Response<CreateListResponse>
|
||||
|
||||
@PUT("list/{id}")
|
||||
suspend fun updateList(@Path("id") listId: Int, body: ListUpdateBody): Response<StatusResponse>
|
||||
|
||||
@GET("list/{id}/clear")
|
||||
suspend fun clearList(@Path("id") listId: Int): Response<ClearListResponse>
|
||||
|
||||
@DELETE("list/{id}")
|
||||
suspend fun deleteList(@Path("id") listId: Int): Response<StatusResponse>
|
||||
|
||||
@POST("list/{id}/items")
|
||||
suspend fun addItemsToList(@Path("id") listId: Int, body: AddToListBody): Response<AddToListResponse>
|
||||
|
||||
@PUT("list/{id}/items")
|
||||
suspend fun updateListItems(@Path("id") listId: Int, body: UpdateListItemBody): Response<AddToListResponse>
|
||||
|
||||
@DELETE("list/{id}/items")
|
||||
suspend fun deleteListItems(@Path("id") listId: Int, body: DeleteListItemsBody): Response<AddToListResponse>
|
||||
|
||||
@GET("list/{id}/item_status")
|
||||
suspend fun getListItemStatus(@Path("id") listId: Int, @Query("media_id") mediaId: Int, @Query("media_type") mediaType: String)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.deserializer
|
||||
|
||||
import com.google.gson.*
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v4.model.ListItem
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v4.model.ListMovie
|
||||
import com.owenlejeune.tvtime.api.tmdb.api.v4.model.ListTv
|
||||
import com.owenlejeune.tvtime.ui.screens.MediaViewType
|
||||
import java.lang.reflect.Type
|
||||
|
||||
class ListItemDeserializer: JsonDeserializer<ListItem> {
|
||||
|
||||
companion object {
|
||||
const val MEDIA_TYPE = "media_type"
|
||||
}
|
||||
|
||||
override fun deserialize(
|
||||
json: JsonElement?,
|
||||
typeOfT: Type?,
|
||||
context: JsonDeserializationContext?
|
||||
): ListItem? {
|
||||
if (json?.isJsonObject == true) {
|
||||
val obj = json.asJsonObject
|
||||
if (obj.has(MEDIA_TYPE)) {
|
||||
val typeStr = obj.get(MEDIA_TYPE).asString
|
||||
return when (Gson().fromJson(typeStr, MediaViewType::class.java)) {
|
||||
MediaViewType.MOVIE -> Gson().fromJson(obj.toString(), ListMovie::class.java)
|
||||
MediaViewType.TV -> Gson().fromJson(obj.toString(), ListTv::class.java)
|
||||
else -> throw JsonParseException("Not a valid MediaViewType: $typeStr")
|
||||
}
|
||||
}
|
||||
throw JsonParseException("JSON object has no property $MEDIA_TYPE")
|
||||
}
|
||||
throw JsonParseException("Not a JSON object")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class AccessResponse(
|
||||
@SerializedName("status_message") val statusMessage: String,
|
||||
@SerializedName("access_token") val accessToken: String,
|
||||
@SerializedName("success") val success: Boolean,
|
||||
@SerializedName("status_code") val statusCode: Int,
|
||||
@SerializedName("account_id") val accountId: String
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.owenlejeune.tvtime.ui.screens.MediaViewType
|
||||
|
||||
class AddToListBody(
|
||||
@SerializedName("items") val items: List<AddToListBodyItem>
|
||||
)
|
||||
|
||||
class AddToListBodyItem(
|
||||
@SerializedName("media_type") val mediaType: MediaViewType,
|
||||
@SerializedName("media_id") val id: Int
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class AddToListResponse(
|
||||
@SerializedName("status_message") val statusMessage: String,
|
||||
@SerializedName("success") val isSuccess: Boolean,
|
||||
@SerializedName("status_code") val statusCode: Int,
|
||||
@SerializedName("results") val results: List<AddToListBodyItem>
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class AuthAccessBody(
|
||||
@SerializedName("request_token") val requestToken: String
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class AuthDeleteBody(
|
||||
@SerializedName("access_token") val accessToken: String
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class AuthRequestBody(
|
||||
@SerializedName("redirect_to") val redirect: String
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class AuthResponse(
|
||||
@SerializedName("status_message") val statusMessage: String,
|
||||
@SerializedName("request_token") val requestToken: String,
|
||||
@SerializedName("success") val success: Boolean,
|
||||
@SerializedName("status_code") val statusCode: Int
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class ClearListResponse(
|
||||
@SerializedName("items_deleted") val deletedItemsCount: Int,
|
||||
@SerializedName("status_message") val statusMessage: String,
|
||||
@SerializedName("id") val id: Int,
|
||||
@SerializedName("status_code") val statusCode: Int,
|
||||
@SerializedName("success") val isSuccess: Boolean
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class CreateListBody(
|
||||
@SerializedName("name") val name: String,
|
||||
@SerializedName("iso_639_1") val language: String,
|
||||
@SerializedName("description") val description: String,
|
||||
@SerializedName("public") val isPublic: Boolean,
|
||||
@SerializedName("iso_3166_1") val localeCode: String
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.owenlejeune.tvtime.api.tmdb.api.v4.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class CreateListResponse(
|
||||
@SerializedName("status_message") val statusMessage: String,
|
||||
@SerializedName("id") val id: Int,
|
||||
@SerializedName("success") val isSuccess: Boolean,
|
||||
@SerializedName("status_code") val statusCode: Int
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user