Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit

Permalink
Revert "WIP News API"
Browse files Browse the repository at this point in the history
This reverts commit 93af0c8
  • Loading branch information
1RandomDev committed Jan 1, 2024
1 parent a1f9a3a commit aa02061
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 204 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ keyAlias=github
keyPassword=github
storePassword=github
```
4. Add your [Trakt.tv](https://trakt.tv/oauth/applications), [TMDB](https://developers.themoviedb.org/3/), [OMDB](http://www.omdbapi.com) API keys as following properties into your `local.properties` file located in the root directory of the project:
4. Add your [Trakt.tv](https://trakt.tv/oauth/applications), [TMDB](https://developers.themoviedb.org/3/), [OMDB](http://www.omdbapi.com) and [Reddit](https://www.reddit.com/prefs/apps) API keys as following properties into your `local.properties` file located in the root directory of the project:
```
traktClientId="your trakt client id"
traktClientSecret="your trakt client secret"
tmdbApiKey="your tmdb api key (v4)"
omdbApiKey="your omdb api key"
redditClientId="your reddit client id"
```
5. Rebuild and start the app.

Expand Down
2 changes: 1 addition & 1 deletion data-remote/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ android {
buildConfigField("String", "TRAKT_CLIENT_ID", properties.getProperty("traktClientId"))
buildConfigField("String", "TRAKT_CLIENT_SECRET", properties.getProperty("traktClientSecret"))
buildConfigField("String", "TMDB_API_KEY", properties.getProperty("tmdbApiKey"))
buildConfigField("String", "CLOUD_API_KEY", properties.getProperty("gcloudApiKey"))
buildConfigField("String", "OMDB_API_KEY", properties.getProperty("omdbApiKey"))
buildConfigField("String", "REDDIT_CLIENT_ID", properties.getProperty("redditClientId"))
buildConfigField 'String', 'VER_NAME', "\"${versions.versionName}\""
}

Expand Down
2 changes: 1 addition & 1 deletion data-remote/consumer-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
-keep class com.michaldrabik.data_remote.omdb.model.** { *; }
-keep class com.michaldrabik.data_remote.trakt.model.** { *; }
-keep class com.michaldrabik.data_remote.aws.model.** { *; }
-keep class com.michaldrabik.data_remote.gcloud.model.** { *; }
-keep class com.michaldrabik.data_remote.reddit.model.** { *; }

### OkHttp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ object Config {
const val OMDB_BASE_URL = "https://www.omdbapi.com/"
const val OMDB_API_KEY = BuildConfig.OMDB_API_KEY

const val GCLOUD_BASE_URL = "https://showly-gateway-5kzyanut.uc.gateway.dev/"
const val REDDIT_BASE_URL = "https://www.reddit.com/api/v1/"
const val REDDIT_OAUTH_BASE_URL = "https://oauth.reddit.com/"
const val REDDIT_CLIENT_ID = BuildConfig.REDDIT_CLIENT_ID
const val REDDIT_GRANT_TYPE = "https://oauth.reddit.com/grants/installed_client"
const val REDDIT_DEVICE_ID = "DO_NOT_TRACK_THIS_DEVICE"
const val REDDIT_LIST_LIMIT = 75
const val REDDIT_LIST_PAGES = 2

const val AWS_BASE_URL = "https://showly2.s3.eu-west-2.amazonaws.com/"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.michaldrabik.data_remote

import com.michaldrabik.data_remote.aws.AwsRemoteDataSource
import com.michaldrabik.data_remote.gcloud.GCloudRemoteDataSource
import com.michaldrabik.data_remote.omdb.OmdbRemoteDataSource
import com.michaldrabik.data_remote.reddit.RedditRemoteDataSource
import com.michaldrabik.data_remote.tmdb.TmdbRemoteDataSource
import com.michaldrabik.data_remote.trakt.TraktRemoteDataSource
import javax.inject.Inject
Expand All @@ -16,14 +16,14 @@ interface RemoteDataSource {
val aws: AwsRemoteDataSource
val tmdb: TmdbRemoteDataSource
val omdb: OmdbRemoteDataSource
val gcloud: GCloudRemoteDataSource
val reddit: RedditRemoteDataSource
}

@Singleton
internal class MainRemoteDataSource @Inject constructor(
override val trakt: TraktRemoteDataSource,
override val tmdb: TmdbRemoteDataSource,
override val aws: AwsRemoteDataSource,
override val gcloud: GCloudRemoteDataSource,
override val reddit: RedditRemoteDataSource,
override val omdb: OmdbRemoteDataSource,
) : RemoteDataSource

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.michaldrabik.data_remote.di.module

import com.michaldrabik.data_remote.BuildConfig
import com.michaldrabik.data_remote.gcloud.interceptors.GCloudAuthorizationInterceptor
import com.michaldrabik.data_remote.omdb.OmdbInterceptor
import com.michaldrabik.data_remote.tmdb.TmdbInterceptor
import com.michaldrabik.data_remote.trakt.interceptors.TraktAuthenticator
Expand Down Expand Up @@ -60,8 +59,8 @@ object OkHttpModule {
httpLoggingInterceptor: HttpLoggingInterceptor,
tmdbInterceptor: TmdbInterceptor,
) = createBaseOkHttpClient()
.addInterceptor(tmdbInterceptor)
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(tmdbInterceptor)
.build()

@Provides
Expand All @@ -71,8 +70,8 @@ object OkHttpModule {
httpLoggingInterceptor: HttpLoggingInterceptor,
omdbInterceptor: OmdbInterceptor,
) = createBaseOkHttpClient()
.addInterceptor(omdbInterceptor)
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(omdbInterceptor)
.build()

@Provides
Expand All @@ -86,12 +85,10 @@ object OkHttpModule {

@Provides
@Singleton
@Named("okHttpGCloud")
fun providesGCloudOkHttp(
@Named("okHttpReddit")
fun providesRedditOkHttp(
httpLoggingInterceptor: HttpLoggingInterceptor,
authInterceptor: GCloudAuthorizationInterceptor,
) = createBaseOkHttpClient()
.addInterceptor(authInterceptor)
.addInterceptor(httpLoggingInterceptor)
.build()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.michaldrabik.data_remote.di.module

import com.michaldrabik.data_remote.Config.AWS_BASE_URL
import com.michaldrabik.data_remote.Config.GCLOUD_BASE_URL
import com.michaldrabik.data_remote.Config.OMDB_BASE_URL
import com.michaldrabik.data_remote.Config.REDDIT_BASE_URL
import com.michaldrabik.data_remote.Config.REDDIT_OAUTH_BASE_URL
import com.michaldrabik.data_remote.Config.TMDB_BASE_URL
import com.michaldrabik.data_remote.Config.TRAKT_BASE_URL
import com.squareup.moshi.Moshi
Expand Down Expand Up @@ -74,15 +75,28 @@ object RetrofitModule {

@Provides
@Singleton
@Named("retrofitGCloud")
fun providesCloudRetrofit(
@Named("okHttpGCloud") okHttpClient: OkHttpClient,
@Named("retrofitRedditAuth")
fun providesRedditRetrofit(
@Named("okHttpReddit") okHttpClient: OkHttpClient,
moshi: Moshi,
): Retrofit =
Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.baseUrl(GCLOUD_BASE_URL)
.baseUrl(REDDIT_BASE_URL)
.build()

@Provides
@Singleton
@Named("retrofitRedditListing")
fun providesRedditRetrofitOAuth(
@Named("okHttpReddit") okHttpClient: OkHttpClient,
moshiConverter: MoshiConverterFactory,
): Retrofit =
Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(moshiConverter)
.baseUrl(REDDIT_OAUTH_BASE_URL)
.build()

@Provides
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NewsRepository @Inject constructor(
localSource.news.getAllByType(type.slug)
.map { mappers.news.fromDatabase(it) }

suspend fun loadShowsNews(forceRefresh: Boolean): List<NewsItem> {
suspend fun loadShowsNews(token: RedditAuthToken, forceRefresh: Boolean): List<NewsItem> {
if (!forceRefresh) {
val cachedNews = getCachedNews(SHOW)
val cacheTimestamp = cachedNews.firstOrNull()?.createdAt?.toMillis() ?: 0
Expand All @@ -38,7 +38,7 @@ class NewsRepository @Inject constructor(
}
}

val remoteItems = remoteSource.gcloud.fetchTelevisionItems()
val remoteItems = remoteSource.reddit.fetchTelevisionItems(token.token)
.map { mappers.news.fromNetwork(it, SHOW) }

val dbItems = remoteItems.map { mappers.news.toDatabase(it) }
Expand All @@ -47,7 +47,7 @@ class NewsRepository @Inject constructor(
return remoteItems.toList()
}

suspend fun loadMoviesNews(forceRefresh: Boolean): List<NewsItem> {
suspend fun loadMoviesNews(token: RedditAuthToken, forceRefresh: Boolean): List<NewsItem> {
if (!forceRefresh) {
val cachedNews = getCachedNews(MOVIE)
val cacheTimestamp = cachedNews.firstOrNull()?.createdAt?.toMillis() ?: 0
Expand All @@ -58,7 +58,7 @@ class NewsRepository @Inject constructor(
}
}

val remoteItems = remoteSource.gcloud.fetchMoviesItems()
val remoteItems = remoteSource.reddit.fetchMoviesItems(token.token)
.map { mappers.news.fromNetwork(it, MOVIE) }

val dbItems = remoteItems.map { mappers.news.toDatabase(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.michaldrabik.common.extensions.dateFromMillis
import com.michaldrabik.common.extensions.nowUtc
import com.michaldrabik.common.extensions.nowUtcMillis
import com.michaldrabik.common.extensions.toMillis
import com.michaldrabik.data_remote.reddit.model.RedditItem
import com.michaldrabik.ui_model.NewsItem
import javax.inject.Inject
import com.michaldrabik.data_local.database.model.News as NewsDb
import com.michaldrabik.data_remote.gcloud.model.NewsItem as NewsItemNetwork

class NewsMapper @Inject constructor() {

fun fromNetwork(input: NewsItemNetwork, type: NewsItem.Type) = NewsItem(
fun fromNetwork(input: RedditItem, type: NewsItem.Type) = NewsItem(
id = input.id,
title = input.title,
url = input.url,
Expand Down
Loading

0 comments on commit aa02061

Please sign in to comment.