Skip to content

Commit

Permalink
more api uniformity, uni testing
Browse files Browse the repository at this point in the history
  • Loading branch information
KirkBushman committed Nov 21, 2021
1 parent 60eaacd commit aff0125
Show file tree
Hide file tree
Showing 27 changed files with 534 additions and 46 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
min_sdk_ver = 21
compile_sdk_ver = 31

version_code = 4
version_name = "1.1.0-alpha01"
version_code = 5
version_name = "1.1.0-alpha02"

java_target = JavaVersion.VERSION_11
jvm_target = '11'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ContributionsClient(
return res.body()?.data?.children?.firstOrNull()?.data
}

fun submissions(
fun createSubmissionsFetcher(

subreddit: SubredditData,

Expand All @@ -62,15 +62,15 @@ class ContributionsClient(

): SubmissionsFetcher {

return submissions(
return createSubmissionsFetcher(
subreddit = subreddit.displayName,
limit = limit,
sorting = sorting,
timePeriod = timePeriod
)
}

fun submissions(
fun createSubmissionsFetcher(

subreddit: String,

Expand All @@ -93,7 +93,7 @@ class ContributionsClient(
)
}

fun multiredditSubmissions(
fun createSubmissionsFetcher(

vararg subreddits: String,

Expand Down Expand Up @@ -134,7 +134,7 @@ class ContributionsClient(
return res.body()?.data?.children?.firstOrNull()?.data
}

fun comments(
fun createCommentsFetcher(

submissionId: String,
focusedCommentId: String? = null,
Expand Down
10 changes: 5 additions & 5 deletions lib/src/main/java/com/kirkbushman/araw/clients/SearchClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.kirkbushman.araw.clients
import androidx.annotation.IntRange
import com.kirkbushman.araw.RedditApi
import com.kirkbushman.araw.fetcher.Fetcher
import com.kirkbushman.araw.fetcher.RedditorSearchFetcher
import com.kirkbushman.araw.fetcher.RedditorsSearchFetcher
import com.kirkbushman.araw.fetcher.SubmissionsSearchFetcher
import com.kirkbushman.araw.fetcher.SubredditsSearchFetcher
import com.kirkbushman.araw.models.SubredditSearchResult
Expand Down Expand Up @@ -106,17 +106,17 @@ class SearchClient(

query: String,

sorting: RedditorSearchSorting = RedditorSearchFetcher.DEFAULT_SORTING,
timePeriod: TimePeriod = RedditorSearchFetcher.DEFAULT_TIMEPERIOD,
sorting: RedditorSearchSorting = RedditorsSearchFetcher.DEFAULT_SORTING,
timePeriod: TimePeriod = RedditorsSearchFetcher.DEFAULT_TIMEPERIOD,

@IntRange(from = Fetcher.MIN_LIMIT, to = Fetcher.MAX_LIMIT)
limit: Long = Fetcher.DEFAULT_LIMIT,

showAll: Boolean = false

): RedditorSearchFetcher {
): RedditorsSearchFetcher {

return RedditorSearchFetcher(
return RedditorsSearchFetcher(
api = api,
query = query,
showAll = showAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ class ContributionsFetcher(
?.map { it.data }
}

fun getUsername(): String? {
return username
}

fun getWhere(): String {
return where
}

fun getSorting(): ContributionsSorting = sorting
fun setSorting(newSorting: ContributionsSorting) {
sorting = newSorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ class InboxFetcher(
?.children
?.map { it.data }
}

fun getWhere(): String {
return where
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ class MultiSubmissionsFetcher(
?.toList()
}

fun getUsername(): String {
return username
}

fun getMultiname(): String {
return multiname
}

fun getSorting(): SubmissionsSorting = sorting
fun setSorting(newSorting: SubmissionsSorting) {
sorting = newSorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.kirkbushman.araw.models.base.RedditorData
import com.kirkbushman.araw.models.enums.RedditorSearchSorting
import com.kirkbushman.araw.models.enums.TimePeriod

class RedditorSearchFetcher(
class RedditorsSearchFetcher(

private val api: RedditApi,
private val query: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class SubmissionsFetcher(
?.toList()
}

fun getSubreddit(): String {
return subreddit
}

fun getSorting(): SubmissionsSorting = sorting
fun setSorting(newSorting: SubmissionsSorting) {
sorting = newSorting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ class SubredditsFetcher(
?.children
?.map { it.data }
}

fun getWhere(): String {
return where
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ data class FlairRichtext(
@Json(name = "u")
val url: String?

) : Parcelable
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CommentDataTest {
client = RedditClient(bearer, true)

val randomSub = subreddits.random()
val fetcher = client!!.contributionsClient.submissions(subreddit = randomSub, limit = LIMIT)
val fetcher = client!!.contributionsClient.createSubmissionsFetcher(subreddit = randomSub, limit = LIMIT)

val addendum = fetcher.fetchNext()
submissions.addAll(addendum ?: emptyList())
Expand All @@ -53,7 +53,7 @@ class CommentDataTest {
.maxByOrNull { it.numComments }
?: throw IllegalAccessError("No submission found!")

val commentsFetcher = client!!.contributionsClient.comments(selectedSubmission.id)
val commentsFetcher = client!!.contributionsClient.createCommentsFetcher(selectedSubmission.id)
val comments = commentsFetcher.fetchNext() ?: emptyList()

val linearList = comments.toLinearList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FetcherTest {

@Test
fun testFetcher() {
val fetcher = client?.subredditsClient?.all(limit = LIMIT)
val fetcher = client?.subredditsClient?.createAllSubmissionsFetcher(limit = LIMIT)

assertTrue("Starting index should be null", fetcher?.getPageNum() == null)
assertTrue("Initially hasStarted should not be true", !(fetcher?.hasStarted() ?: false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ModelsFetchTest {

try {

val fetcher = client?.subredditsClient?.frontpage(limit = LIMIT)
val fetcher = client?.subredditsClient?.createFrontpageSubmissionsFetcher(limit = LIMIT)
val submissions = fetcher?.fetchNext()
assertNotEquals("Assert that submissions from /r/frontpage are not null", null, submissions)
assertTrue(
Expand All @@ -98,7 +98,7 @@ class ModelsFetchTest {

try {

val fetcher = client?.subredditsClient?.all(limit = LIMIT)
val fetcher = client?.subredditsClient?.createAllSubmissionsFetcher(limit = LIMIT)
val submissions = fetcher?.fetchNext()
assertNotEquals("Assert that submissions from /r/all are not null", null, submissions)
assertTrue(
Expand All @@ -122,7 +122,7 @@ class ModelsFetchTest {

subreddits.forEach {

val fetcher = client?.contributionsClient?.submissions(it, limit = LIMIT)
val fetcher = client?.contributionsClient?.createSubmissionsFetcher(it, limit = LIMIT)
val submissions = fetcher?.fetchNext()
assertNotEquals("Assert that submissions from /r/$it are not null", null, submissions)
assertTrue(
Expand Down Expand Up @@ -165,7 +165,7 @@ class ModelsFetchTest {

try {

val fetcher = client?.messagesClient?.sent(limit = LIMIT)
val fetcher = client?.messagesClient?.createSentInboxFetcher(limit = LIMIT)
val messages = fetcher?.fetchNext()
assertNotEquals("Assert that messages in inbox are not null", null, messages)
assertTrue("Assert that messages in inbox are not empty", messages?.isNotEmpty() ?: false)
Expand All @@ -184,7 +184,7 @@ class ModelsFetchTest {

try {

val fetcher = client?.messagesClient?.inbox(limit = LIMIT)
val fetcher = client?.messagesClient?.createOverviewInboxFetcher(limit = LIMIT)
val messages = fetcher?.fetchNext()
assertNotEquals("Assert that messages in inbox are not null", null, messages)
assertTrue("Assert that messages in inbox are not empty", messages?.isNotEmpty() ?: false)
Expand All @@ -199,14 +199,14 @@ class ModelsFetchTest {
@Test
fun modelsCommentsTest() {

val fetcher = client?.subredditsClient?.all(limit = LIMIT)
val fetcher = client?.subredditsClient?.createAllSubmissionsFetcher(limit = LIMIT)
val submissions = fetcher?.fetchNext()

val randomSub = submissions?.randomOrNull()

assertNotEquals("Assert that this random submission is not null", null, randomSub)

val fetcherComm = client?.contributionsClient?.comments(randomSub!!.id)
val fetcherComm = client?.contributionsClient?.createCommentsFetcher(randomSub!!.id)
val comments = fetcherComm?.fetchNext()

assertNotEquals("Assert that comments in submission are not null", null, comments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SearchDataTesting {

try {

val fetcher = client?.searchClient?.submissionsSearch(
val fetcher = client?.searchClient?.createSubmissionsSearchFetcher(
subreddit = "news",
query = "news",
limit = LIMIT,
Expand Down Expand Up @@ -70,7 +70,7 @@ class SearchDataTesting {

try {

val fetcher = client?.searchClient?.submissionsSearch(
val fetcher = client?.searchClient?.createSubmissionsSearchFetcher(
subreddit = "news",
query = "sakifjewijr3o4jr8fs9dfsadofishadfkjasdhfskaldjfhasdkjlfhsadklfhasdfjksdbcsc7738783",
limit = LIMIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class UserlessFetchTest {

try {

val fetcher = client?.subredditsClient?.frontpage(limit = LIMIT)
val fetcher = client?.subredditsClient?.createFrontpageSubmissionsFetcher(limit = LIMIT)
val submissions = fetcher?.fetchNext()
assertNotEquals("Assert that submissions from /r/frontpage are not null", null, submissions)
assertTrue(
Expand All @@ -98,7 +98,7 @@ class UserlessFetchTest {

try {

val fetcher = client?.subredditsClient?.all(limit = LIMIT)
val fetcher = client?.subredditsClient?.createAllSubmissionsFetcher(limit = LIMIT)
val submissions = fetcher?.fetchNext()
assertNotEquals("Assert that submissions from /r/all are not null", null, submissions)
assertTrue(
Expand All @@ -122,7 +122,7 @@ class UserlessFetchTest {

subreddits.forEach {

val fetcher = client?.contributionsClient?.submissions(it, limit = LIMIT)
val fetcher = client?.contributionsClient?.createSubmissionsFetcher(it, limit = LIMIT)
val submissions = fetcher?.fetchNext()
assertNotEquals("Assert that submissions from /r/$it are not null", null, submissions)
assertTrue(
Expand Down Expand Up @@ -165,7 +165,7 @@ class UserlessFetchTest {

try {

val fetcher = client?.messagesClient?.sent(limit = LIMIT)
val fetcher = client?.messagesClient?.createSentInboxFetcher(limit = LIMIT)
val messages = fetcher?.fetchNext()
assertNotEquals("Assert that messages in inbox are not null", null, messages)
assertTrue("Assert that messages in inbox are not empty", messages?.isNotEmpty() ?: false)
Expand All @@ -184,7 +184,7 @@ class UserlessFetchTest {

try {

val fetcher = client?.messagesClient?.inbox(limit = LIMIT)
val fetcher = client?.messagesClient?.createOverviewInboxFetcher(limit = LIMIT)
val messages = fetcher?.fetchNext()
assertNotEquals("Assert that messages in inbox are not null", null, messages)
assertTrue("Assert that messages in inbox are not empty", messages?.isNotEmpty() ?: false)
Expand All @@ -199,14 +199,14 @@ class UserlessFetchTest {
@Test
fun modelsCommentsTest() {

val fetcher = client?.subredditsClient?.all(limit = LIMIT)
val fetcher = client?.subredditsClient?.createAllSubmissionsFetcher(limit = LIMIT)
val submissions = fetcher?.fetchNext()

val randomSub = submissions?.randomOrNull()

assertNotEquals("Assert that this random submission is not null", null, randomSub)

val fetcherComm = client?.contributionsClient?.comments(randomSub!!.id)
val fetcherComm = client?.contributionsClient?.createCommentsFetcher(randomSub!!.id)
val comments = fetcherComm?.fetchNext()

assertNotEquals("Assert that comments in submission are not null", null, comments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,21 +441,21 @@ class ApiDetailActivity : BaseActivity() {

API_SUB_COMMENT -> {
val submissionId = getRandomSubmissionIdFromRandomSubreddit()
val fetcher = client.contributionsClient.comments(submissionId)
val fetcher = client.contributionsClient.createCommentsFetcher(submissionId)
val comments = fetcher.fetchNext()
comments?.random().toString()
}

API_SUB_SUBMISSIONS -> {
val subreddit = getRandomSubredditName()
val fetcher = client.contributionsClient.submissions(subreddit)
val fetcher = client.contributionsClient.createSubmissionsFetcher(subreddit)
val submissions = fetcher.fetchNext()
submissions.toString()
}

API_SUB_COMMENTS -> {
val submissionId = getRandomSubmissionIdFromRandomSubreddit()
val fetcher = client.contributionsClient.comments(submissionId)
val fetcher = client.contributionsClient.createCommentsFetcher(submissionId)
val comments = fetcher.fetchNext()
comments.toString()
}
Expand All @@ -464,7 +464,7 @@ class ApiDetailActivity : BaseActivity() {
val subreddits = getRandomSubredditNames()
val fetcher = client
.contributionsClient
.multiredditSubmissions(*subreddits, limit = 100)
.createSubmissionsFetcher(*subreddits, limit = 100)

val submissions = fetcher.fetchNext()
submissions.toString()
Expand Down Expand Up @@ -839,7 +839,7 @@ class ApiDetailActivity : BaseActivity() {

private fun getRandomSubmissionIdFromRandomSubreddit(): String {
val subredditName = getRandomSubredditName()
val fetcher = client.contributionsClient.submissions(subredditName)
val fetcher = client.contributionsClient.createSubmissionsFetcher(subredditName)
val submissions = fetcher.fetchNext()

return submissions
Expand All @@ -850,7 +850,7 @@ class ApiDetailActivity : BaseActivity() {

private fun getRandomUserFromRandomSubreddit(): String {
val subredditName = getRandomSubredditName()
val fetcher = client.contributionsClient.submissions(subredditName)
val fetcher = client.contributionsClient.createSubmissionsFetcher(subredditName)
val submissions = fetcher.fetchNext()

return submissions
Expand Down
Loading

0 comments on commit aff0125

Please sign in to comment.