Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit 94bdba1

Browse files
committed
add: DataSource Top Headline
1 parent 082bf31 commit 94bdba1

6 files changed

Lines changed: 281 additions & 3 deletions

File tree

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/data/source/NewsApiService.kt

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.frogobox.frogonewsapi.data.source
22

33
import android.content.Context
4+
import com.frogobox.frogonewsapi.data.response.ArticleResponse
5+
import com.frogobox.frogonewsapi.util.NewsConstant
46
import com.frogobox.frogonewsapi.util.NewsUrl
57
import com.readystatesoftware.chuck.ChuckInterceptor
8+
import io.reactivex.Observable
69
import okhttp3.OkHttpClient
710
import okhttp3.logging.HttpLoggingInterceptor
811
import retrofit2.Retrofit
912
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
1013
import retrofit2.converter.gson.GsonConverterFactory
14+
import retrofit2.http.GET
15+
import retrofit2.http.Query
1116
import java.util.concurrent.TimeUnit
1217

1318
/**
@@ -29,12 +34,76 @@ import java.util.concurrent.TimeUnit
2934
*/
3035
interface NewsApiService {
3136

37+
// Get Top Headline From Country
38+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
39+
fun getTopHeadlineByCountry(
40+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
41+
@Query(NewsConstant.QUERY_COUNTRY) country: String
42+
): Observable<ArticleResponse>
43+
44+
// Get Top Headline From Country and Category
45+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
46+
fun getTopHeadlineByCountry(
47+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
48+
@Query(NewsConstant.QUERY_COUNTRY) country: String,
49+
@Query(NewsConstant.QUERY_CATEGORY) category: String
50+
): Observable<ArticleResponse>
51+
52+
// Get Top Headline From Source
53+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
54+
fun getTopHeadlineBySource(
55+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
56+
@Query(NewsConstant.QUERY_SOURCES) sources: String
57+
): Observable<ArticleResponse>
58+
59+
// Get Top Headline From Source and Category
60+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
61+
fun getTopHeadlineBySource(
62+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
63+
@Query(NewsConstant.QUERY_SOURCES) sources: String,
64+
@Query(NewsConstant.QUERY_CATEGORY) category: String
65+
): Observable<ArticleResponse>
66+
67+
// Get Top Headline From q
68+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
69+
fun getTopHeadlineByQ(
70+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
71+
@Query(NewsConstant.QUERY_Q) q: String
72+
): Observable<ArticleResponse>
73+
74+
// Get Top Headline From q
75+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
76+
fun getTopHeadlineByQ(
77+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
78+
@Query(NewsConstant.QUERY_Q) q: String,
79+
@Query(NewsConstant.QUERY_CATEGORY) category: String
80+
): Observable<ArticleResponse>
81+
82+
// Get Top Headline From Category
83+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
84+
fun getTopHeadlineByCategory(
85+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
86+
@Query(NewsConstant.QUERY_Q) q: String,
87+
@Query(NewsConstant.QUERY_CATEGORY) category: String
88+
): Observable<ArticleResponse>
89+
90+
// Get Top Headline
91+
@GET(NewsUrl.NEWS_URL_TOP_HEADLINE)
92+
fun getTopHeadline(
93+
@Query(NewsConstant.QUERY_API_KEY) apiKey: String,
94+
@Query(NewsConstant.QUERY_Q) q: String?,
95+
@Query(NewsConstant.QUERY_SOURCES) sources: String?,
96+
@Query(NewsConstant.QUERY_CATEGORY) category: String?,
97+
@Query(NewsConstant.QUERY_COUNTRY) country: String?
98+
): Observable<ArticleResponse>
99+
100+
32101
companion object Factory {
33102

34103
private var isUsingChuckInterceptor = false
35104
private lateinit var context: Context
36105

37-
fun usingChuckInterceptor(context: Context){
106+
fun usingChuckInterceptor(context: Context) {
38107
isUsingChuckInterceptor = true
39108
this.context = context
40109
}

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/data/source/NewsDataSource.kt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.frogobox.frogonewsapi.data.source
22

33
import android.content.Context
44
import com.frogobox.frogonewsapi.base.BaseNewsDataSource
5+
import com.frogobox.frogonewsapi.data.response.ArticleResponse
56

67
/**
78
* Created by Faisal Amir
@@ -25,6 +26,64 @@ interface NewsDataSource {
2526
// Switch For Using Chuck Interceptor
2627
fun usingChuckInterceptor(context: Context)
2728

29+
// Get Top Headline From Country
30+
fun getTopHeadlineByCountry(
31+
apiKey: String,
32+
country: String,
33+
callback: GetRemoteCallback<ArticleResponse>
34+
)
35+
36+
// Get Top Headline From Country and Category
37+
fun getTopHeadlineByCountry(
38+
apiKey: String,
39+
country: String,
40+
category: String,
41+
callback: GetRemoteCallback<ArticleResponse>
42+
)
43+
44+
// Get Top Headline From Source
45+
fun getTopHeadlineBySource(
46+
apiKey: String,
47+
sources: String,
48+
callback: GetRemoteCallback<ArticleResponse>
49+
)
50+
51+
// Get Top Headline From Source and Category
52+
fun getTopHeadlineBySource(
53+
apiKey: String,
54+
sources: String,
55+
category: String,
56+
callback: GetRemoteCallback<ArticleResponse>
57+
)
58+
59+
// Get Top Headline From q
60+
fun getTopHeadlineByQ(apiKey: String, q: String, callback: GetRemoteCallback<ArticleResponse>)
61+
62+
// Get Top Headline From q
63+
fun getTopHeadlineByQ(
64+
apiKey: String,
65+
q: String,
66+
category: String,
67+
callback: GetRemoteCallback<ArticleResponse>
68+
)
69+
70+
// Get Top Headline From Category
71+
fun getTopHeadlineByCategory(
72+
apiKey: String,
73+
q: String,
74+
category: String,
75+
callback: GetRemoteCallback<ArticleResponse>
76+
)
77+
78+
// Get Top Headline
79+
fun getTopHeadline(
80+
apiKey: String,
81+
q: String?,
82+
sources: String?,
83+
category: String?,
84+
country: String?,
85+
callback: GetRemoteCallback<ArticleResponse>
86+
)
2887

2988
// Response Callback
3089
interface GetRemoteCallback<T> : BaseNewsDataSource.ResponseCallback<T>

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/data/source/NewsRemoteDataSource.kt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.frogobox.frogonewsapi.data.source
22

33
import android.content.Context
4+
import com.frogobox.frogonewsapi.data.response.ArticleResponse
45

56
/**
67
* Created by Faisal Amir
@@ -27,4 +28,74 @@ object NewsRemoteDataSource : NewsDataSource {
2728
newsApiService.usingChuckInterceptor(context)
2829
}
2930

31+
override fun getTopHeadlineByCountry(
32+
apiKey: String,
33+
country: String,
34+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
35+
) {
36+
TODO("Not yet implemented")
37+
}
38+
39+
override fun getTopHeadlineByCountry(
40+
apiKey: String,
41+
country: String,
42+
category: String,
43+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
44+
) {
45+
TODO("Not yet implemented")
46+
}
47+
48+
override fun getTopHeadlineBySource(
49+
apiKey: String,
50+
sources: String,
51+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
52+
) {
53+
TODO("Not yet implemented")
54+
}
55+
56+
override fun getTopHeadlineBySource(
57+
apiKey: String,
58+
sources: String,
59+
category: String,
60+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
61+
) {
62+
TODO("Not yet implemented")
63+
}
64+
65+
override fun getTopHeadlineByQ(
66+
apiKey: String,
67+
q: String,
68+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
69+
) {
70+
TODO("Not yet implemented")
71+
}
72+
73+
override fun getTopHeadlineByQ(
74+
apiKey: String,
75+
q: String,
76+
category: String,
77+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
78+
) {
79+
TODO("Not yet implemented")
80+
}
81+
82+
override fun getTopHeadlineByCategory(
83+
apiKey: String,
84+
q: String,
85+
category: String,
86+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
87+
) {
88+
TODO("Not yet implemented")
89+
}
90+
91+
override fun getTopHeadline(
92+
apiKey: String,
93+
q: String?,
94+
sources: String?,
95+
category: String?,
96+
country: String?,
97+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
98+
) {
99+
TODO("Not yet implemented")
100+
}
30101
}

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/data/source/NewsRepository.kt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.frogobox.frogonewsapi.data.source
22

33
import android.content.Context
4+
import com.frogobox.frogonewsapi.data.response.ArticleResponse
45

56
/**
67
* Created by Faisal Amir
@@ -24,4 +25,75 @@ class NewsRepository(private val remoteDataSource: NewsRemoteDataSource) : NewsD
2425
override fun usingChuckInterceptor(context: Context) {
2526
remoteDataSource.usingChuckInterceptor(context)
2627
}
28+
29+
override fun getTopHeadlineByCountry(
30+
apiKey: String,
31+
country: String,
32+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
33+
) {
34+
remoteDataSource.getTopHeadlineByCountry(apiKey, country, callback)
35+
}
36+
37+
override fun getTopHeadlineByCountry(
38+
apiKey: String,
39+
country: String,
40+
category: String,
41+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
42+
) {
43+
remoteDataSource.getTopHeadlineByCountry(apiKey, country, category, callback)
44+
}
45+
46+
override fun getTopHeadlineBySource(
47+
apiKey: String,
48+
sources: String,
49+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
50+
) {
51+
remoteDataSource.getTopHeadlineBySource(apiKey, sources, callback)
52+
}
53+
54+
override fun getTopHeadlineBySource(
55+
apiKey: String,
56+
sources: String,
57+
category: String,
58+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
59+
) {
60+
remoteDataSource.getTopHeadlineBySource(apiKey, sources, category, callback)
61+
}
62+
63+
override fun getTopHeadlineByQ(
64+
apiKey: String,
65+
q: String,
66+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
67+
) {
68+
remoteDataSource.getTopHeadlineByQ(apiKey, q, callback)
69+
}
70+
71+
override fun getTopHeadlineByQ(
72+
apiKey: String,
73+
q: String,
74+
category: String,
75+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
76+
) {
77+
remoteDataSource.getTopHeadlineByQ(apiKey, q, category, callback)
78+
}
79+
80+
override fun getTopHeadlineByCategory(
81+
apiKey: String,
82+
q: String,
83+
category: String,
84+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
85+
) {
86+
remoteDataSource.getTopHeadlineByCategory(apiKey, q, category, callback)
87+
}
88+
89+
override fun getTopHeadline(
90+
apiKey: String,
91+
q: String?,
92+
sources: String?,
93+
category: String?,
94+
country: String?,
95+
callback: NewsDataSource.GetRemoteCallback<ArticleResponse>
96+
) {
97+
remoteDataSource.getTopHeadline(apiKey, q, sources, category, country, callback)
98+
}
2799
}

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/util/NewsConstant.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class NewsConstant {
2121

2222
companion object {
2323

24+
const val QUERY_API_KEY = "apiKey"
25+
const val QUERY_SOURCES = "sources"
26+
const val QUERY_CATEGORY = "category"
27+
const val QUERY_Q = "q"
28+
const val QUERY_LANGUAGE = "language"
29+
const val QUERY_COUNTRY = "country"
30+
2431
}
2532

2633
}

frogonewsapi/src/main/java/com/frogobox/frogonewsapi/util/NewsUrl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class NewsUrl {
3131
const val NEWS_PATH_SOURCES = "sources"
3232

3333
const val NEWS_URL_TOP_HEADLINE = "$NEWS_BASE_PATH$NEWS_PATH_TOP_HEADLINE"
34-
const val NEWS_URL_TOP_EVERYTHING = "$NEWS_BASE_PATH$NEWS_PATH_EVERYTHING"
35-
const val NEWS_URL_TOP_SOURCES = "$NEWS_BASE_PATH$NEWS_PATH_SOURCES"
34+
const val NEWS_URL_EVERYTHING = "$NEWS_BASE_PATH$NEWS_PATH_EVERYTHING"
35+
const val NEWS_URL_SOURCES = "$NEWS_BASE_PATH$NEWS_PATH_SOURCES"
3636

3737
}
3838
}

0 commit comments

Comments
 (0)