-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
212d080
commit ad8fd43
Showing
27 changed files
with
371 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
core/network/src/main/kotlin/org/michaelbel/movies/network/TmdbConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
core/network/src/main/kotlin/org/michaelbel/movies/network/ktor/KtorAccountService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.michaelbel.movies.network.ktor | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.parameter | ||
import javax.inject.Inject | ||
import org.michaelbel.movies.network.model.Account | ||
|
||
class KtorAccountService @Inject constructor( | ||
private val ktorHttpClient: HttpClient | ||
) { | ||
|
||
suspend fun accountDetails( | ||
sessionId: String | ||
): Account { | ||
return ktorHttpClient.get("account") { | ||
parameter("session_id", sessionId) | ||
}.body() | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
core/network/src/main/kotlin/org/michaelbel/movies/network/ktor/KtorAuthenticationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.michaelbel.movies.network.ktor | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.delete | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.setBody | ||
import javax.inject.Inject | ||
import org.michaelbel.movies.network.model.DeletedSession | ||
import org.michaelbel.movies.network.model.RequestToken | ||
import org.michaelbel.movies.network.model.Session | ||
import org.michaelbel.movies.network.model.SessionRequest | ||
import org.michaelbel.movies.network.model.Token | ||
import org.michaelbel.movies.network.model.Username | ||
|
||
class KtorAuthenticationService @Inject constructor( | ||
private val ktorHttpClient: HttpClient | ||
) { | ||
|
||
suspend fun createRequestToken(): Token { | ||
return ktorHttpClient.get("authentication/token/new?").body() | ||
} | ||
|
||
suspend fun createSessionWithLogin( | ||
username: Username | ||
): Token { | ||
return ktorHttpClient.post("authentication/token/validate_with_login?") { | ||
setBody(username) | ||
}.body() | ||
} | ||
|
||
suspend fun createSession( | ||
authToken: RequestToken | ||
): Session { | ||
return ktorHttpClient.post("authentication/session/new?") { | ||
setBody(authToken) | ||
}.body() | ||
} | ||
|
||
suspend fun deleteSession( | ||
sessionRequest: SessionRequest | ||
): DeletedSession { | ||
return ktorHttpClient.delete("authentication/session?") { | ||
setBody(sessionRequest) | ||
}.body() | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
core/network/src/main/kotlin/org/michaelbel/movies/network/ktor/KtorMovieService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.michaelbel.movies.network.ktor | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.parameter | ||
import javax.inject.Inject | ||
import org.michaelbel.movies.network.model.ImagesResponse | ||
import org.michaelbel.movies.network.model.Movie | ||
import org.michaelbel.movies.network.model.MovieResponse | ||
import org.michaelbel.movies.network.model.Result | ||
|
||
class KtorMovieService @Inject constructor( | ||
private val ktorHttpClient: HttpClient | ||
) { | ||
|
||
suspend fun movies( | ||
list: String, | ||
language: String, | ||
page: Int | ||
): Result<MovieResponse> { | ||
return ktorHttpClient.get("movie/$list") { | ||
parameter("language", language) | ||
parameter("page", page) | ||
}.body() | ||
} | ||
|
||
suspend fun movie( | ||
movieId: Int, | ||
language: String | ||
): Movie { | ||
return ktorHttpClient.get("movie/$movieId") { | ||
parameter("language", language) | ||
}.body() | ||
} | ||
|
||
suspend fun images( | ||
movieId: Int | ||
): ImagesResponse { | ||
return ktorHttpClient.get("movie/$movieId/images").body() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core/network/src/main/kotlin/org/michaelbel/movies/network/ktor/KtorSearchService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.michaelbel.movies.network.ktor | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.parameter | ||
import javax.inject.Inject | ||
import org.michaelbel.movies.network.model.MovieResponse | ||
import org.michaelbel.movies.network.model.Result | ||
|
||
class KtorSearchService @Inject constructor( | ||
private val ktorHttpClient: HttpClient | ||
) { | ||
|
||
suspend fun searchMovies( | ||
query: String, | ||
language: String, | ||
page: Int | ||
): Result<MovieResponse> { | ||
return ktorHttpClient.get("search/movie") { | ||
parameter("query", query) | ||
parameter("language", language) | ||
parameter("page", page) | ||
}.body() | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
core/network/src/main/kotlin/org/michaelbel/movies/network/ktor/di/KtorModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.michaelbel.movies.network.ktor.di | ||
|
||
import com.chuckerteam.chucker.api.ChuckerInterceptor | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import io.github.rotbolt.flakerokhttpcore.FlakerInterceptor | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.okhttp.OkHttp | ||
import io.ktor.client.plugins.HttpTimeout | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.plugins.defaultRequest | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.contentType | ||
import io.ktor.serialization.kotlinx.json.json | ||
import javax.inject.Singleton | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.michaelbel.movies.network.TMDB_API_ENDPOINT | ||
import org.michaelbel.movies.network.okhttp.di.OkhttpModule | ||
import org.michaelbel.movies.network.okhttp.interceptor.ApikeyInterceptor | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object KtorModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideKtorHttpClient( | ||
chuckerInterceptor: ChuckerInterceptor, | ||
flakerInterceptor: FlakerInterceptor, | ||
httpLoggingInterceptor: HttpLoggingInterceptor, | ||
apikeyInterceptor: ApikeyInterceptor | ||
): HttpClient { | ||
val ktor = HttpClient(OkHttp) { | ||
defaultRequest { | ||
contentType(ContentType.Application.Json) | ||
url(TMDB_API_ENDPOINT) | ||
} | ||
install(ContentNegotiation) { | ||
json( | ||
Json { | ||
ignoreUnknownKeys = true | ||
} | ||
) | ||
} | ||
install(HttpTimeout) { | ||
requestTimeoutMillis = REQUEST_TIMEOUT_MILLIS | ||
connectTimeoutMillis = OkhttpModule.CONNECT_TIMEOUT_MILLIS | ||
socketTimeoutMillis = SOCKET_TIMEOUT_SECONDS | ||
} | ||
engine { | ||
clientCacheSize = OkhttpModule.HTTP_CACHE_SIZE_BYTES | ||
config { | ||
addInterceptor(chuckerInterceptor) | ||
addInterceptor(flakerInterceptor) | ||
addInterceptor(httpLoggingInterceptor) | ||
addInterceptor(apikeyInterceptor) | ||
} | ||
} | ||
} | ||
return ktor | ||
} | ||
|
||
private const val REQUEST_TIMEOUT_MILLIS = 10_000L | ||
private const val SOCKET_TIMEOUT_SECONDS = 10_000L | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...network/service/account/AccountService.kt → ...etwork/retrofit/RetrofitAccountService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
core/network/src/main/kotlin/org/michaelbel/movies/network/retrofit/RetrofitModule.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...s/network/service/search/SearchService.kt → ...network/retrofit/RetrofitSearchService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.