-
Notifications
You must be signed in to change notification settings - Fork 9
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
luca
committed
Nov 1, 2019
1 parent
867d29f
commit f9e0fad
Showing
15 changed files
with
287 additions
and
25 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
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
65 changes: 65 additions & 0 deletions
65
lib/src/main/java/com/kirkbushman/araw/clients/WikisClient.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,65 @@ | ||
package com.kirkbushman.araw.clients | ||
|
||
import com.kirkbushman.araw.RedditApi | ||
import com.kirkbushman.araw.models.Subreddit | ||
import com.kirkbushman.araw.models.WikiPage | ||
import com.kirkbushman.araw.models.WikiRevision | ||
|
||
class WikisClient( | ||
|
||
private val api: RedditApi, | ||
private inline val getHeaderMap: () -> HashMap<String, String> | ||
|
||
) : BaseRedditClient(api, getHeaderMap) { | ||
|
||
fun wiki(subreddit: Subreddit): WikiPage? { | ||
return wiki(subreddit.displayName) | ||
} | ||
|
||
fun wiki(subreddit: String): WikiPage? { | ||
|
||
val authMap = getHeaderMap() | ||
val req = api.wiki(subreddit = subreddit, header = authMap) | ||
val res = req.execute() | ||
|
||
if (!res.isSuccessful) { | ||
return null | ||
} | ||
|
||
return res.body()?.data | ||
} | ||
|
||
fun wikiPages(subreddit: Subreddit): List<String>? { | ||
return wikiPages(subreddit.displayName) | ||
} | ||
|
||
fun wikiPages(subreddit: String): List<String>? { | ||
|
||
val authMap = getHeaderMap() | ||
val req = api.wikiPages(subreddit = subreddit, header = authMap) | ||
val res = req.execute() | ||
|
||
if (!res.isSuccessful) { | ||
return null | ||
} | ||
|
||
return res.body()?.data | ||
} | ||
|
||
fun wikiRevisions(subreddit: Subreddit): Any? { | ||
return wikiRevisions(subreddit.displayName) | ||
} | ||
|
||
fun wikiRevisions(subreddit: String): Any? { | ||
|
||
val authMap = getHeaderMap() | ||
val req = api.wikiRevisions(subreddit = subreddit, header = authMap) | ||
val res = req.execute() | ||
|
||
if (!res.isSuccessful) { | ||
return null | ||
} | ||
|
||
return res.body() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
lib/src/main/java/com/kirkbushman/araw/http/EnvelopedWikiRevisionListing.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 com.kirkbushman.araw.http | ||
|
||
import android.os.Parcelable | ||
import com.kirkbushman.araw.http.base.Envelope | ||
import com.kirkbushman.araw.http.base.EnvelopeKind | ||
import com.kirkbushman.araw.http.listings.WikiRevisionListing | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@JsonClass(generateAdapter = true) | ||
@Parcelize | ||
data class EnvelopedWikiRevisionListing( | ||
|
||
@Json(name = "kind") | ||
override val kind: EnvelopeKind, | ||
|
||
@Json(name = "data") | ||
override val data: WikiRevisionListing | ||
|
||
) : Envelope<WikiRevisionListing>, Parcelable |
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
27 changes: 27 additions & 0 deletions
27
lib/src/main/java/com/kirkbushman/araw/http/listings/WikiRevisionListing.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,27 @@ | ||
package com.kirkbushman.araw.http.listings | ||
|
||
import android.os.Parcelable | ||
import com.kirkbushman.araw.http.base.Listing | ||
import com.kirkbushman.araw.models.WikiRevision | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@JsonClass(generateAdapter = true) | ||
@Parcelize | ||
data class WikiRevisionListing( | ||
|
||
@Json(name = "modhash") | ||
override val modhash: String?, | ||
@Json(name = "dist") | ||
override val dist: Int?, | ||
|
||
@Json(name = "children") | ||
override val children: List<WikiRevision>, | ||
|
||
@Json(name = "after") | ||
override val after: String?, | ||
@Json(name = "before") | ||
override val before: String? | ||
|
||
) : Listing<WikiRevision>, Parcelable |
19 changes: 19 additions & 0 deletions
19
lib/src/main/java/com/kirkbushman/araw/models/WikiPageList.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,19 @@ | ||
package com.kirkbushman.araw.models | ||
|
||
import android.os.Parcelable | ||
import com.kirkbushman.araw.http.base.EnvelopeKind | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@JsonClass(generateAdapter = true) | ||
@Parcelize | ||
data class WikiPageList( | ||
|
||
@Json(name = "kind") | ||
val kind: EnvelopeKind, | ||
|
||
@Json(name = "data") | ||
val data: List<String> | ||
|
||
) : Parcelable |
23 changes: 23 additions & 0 deletions
23
lib/src/main/java/com/kirkbushman/araw/models/WikiRevision.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,23 @@ | ||
package com.kirkbushman.araw.models | ||
|
||
import android.os.Parcelable | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@JsonClass(generateAdapter = true) | ||
@Parcelize | ||
data class WikiRevision( | ||
|
||
@Json(name = "id") | ||
val id: String, | ||
|
||
@Json(name = "revision_hidden") | ||
val revisionHidden: Boolean, | ||
|
||
@Json(name = "page") | ||
val page: String, | ||
|
||
val timestamp: Long | ||
|
||
) : Parcelable |
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
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
Oops, something went wrong.