Skip to content

Commit

Permalink
Merge pull request #235 from canaangifford/mod-feature/post-sticky-an…
Browse files Browse the repository at this point in the history
…d-spoiler

Mod feature/post sticky and spoiler
  • Loading branch information
mattbdean authored Mar 6, 2018
2 parents dbbe319 + 25bd4a4 commit 659b5e1
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
15 changes: 8 additions & 7 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!--- Generated 2018-02-23 at 09:53:12 EST. Use `./gradlew :meta:update` to update. DO NOT MODIFY DIRECTLY -->
<!--- Generated 2018-03-05 at 21:54:35 EST. Use `./gradlew :meta:update` to update. DO NOT MODIFY DIRECTLY -->

Endpoints
=========

This file contains a list of all the endpoints (regardless of if they have been implemented) that can be found at the [official reddit API docs](https://www.reddit.com/dev/api/oauth). To update this file, run `./gradlew :meta:update`

So far, **82** endpoints (out of 190) have been implemented.
So far, **85** endpoints (out of 191) have been implemented.

(any scope)
-----------
Expand Down Expand Up @@ -172,20 +172,20 @@ modposts

| Method | Endpoint | Implementation |
|:------:| ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `POST` | [`/api/approve`](https://www.reddit.com/dev/api/oauth#POST_api_approve) | [`PublicContributionReference.approve()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/PublicContributionReference.kt#L198) |
| `POST` | [`/api/approve`](https://www.reddit.com/dev/api/oauth#POST_api_approve) | [`PublicContributionReference.approve()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/PublicContributionReference.kt#L199) |
| `POST` | [`/api/distinguish`](https://www.reddit.com/dev/api/oauth#POST_api_distinguish) | [`PublicContributionReference.distinguish()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/PublicContributionReference.kt#L151) |
| `POST` | [`/api/remove`](https://www.reddit.com/dev/api/oauth#POST_api_remove) | [`PublicContributionReference.remove()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/PublicContributionReference.kt#L184) |
| `POST` | [`/api/remove`](https://www.reddit.com/dev/api/oauth#POST_api_remove) | [`PublicContributionReference.remove()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/PublicContributionReference.kt#L185) |
| `POST` | [`/api/set_subreddit_sticky`](https://www.reddit.com/dev/api/oauth#POST_api_set_subreddit_sticky) | [`SubmissionReference.stickyPost()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/SubmissionReference.kt#L114) |
| `POST` | [`/api/spoiler`](https://www.reddit.com/dev/api/oauth#POST_api_spoiler) | [`SubmissionReference.flagAsSpoiler()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/SubmissionReference.kt#L91) |
| `POST` | [`/api/unspoiler`](https://www.reddit.com/dev/api/oauth#POST_api_unspoiler) | [`SubmissionReference.flagAsSpoiler()`](https://github.com/mattbdean/JRAW/tree/master/lib/src/main/kotlin/net/dean/jraw/references/SubmissionReference.kt#L91) |
| `POST` | [`/api/ignore_reports`](https://www.reddit.com/dev/api/oauth#POST_api_ignore_reports) | None |
| `POST` | [`/api/lock`](https://www.reddit.com/dev/api/oauth#POST_api_lock) | None |
| `POST` | [`/api/marknsfw`](https://www.reddit.com/dev/api/oauth#POST_api_marknsfw) | None |
| `POST` | [`/api/set_contest_mode`](https://www.reddit.com/dev/api/oauth#POST_api_set_contest_mode) | None |
| `POST` | [`/api/set_subreddit_sticky`](https://www.reddit.com/dev/api/oauth#POST_api_set_subreddit_sticky) | None |
| `POST` | [`/api/set_suggested_sort`](https://www.reddit.com/dev/api/oauth#POST_api_set_suggested_sort) | None |
| `POST` | [`/api/spoiler`](https://www.reddit.com/dev/api/oauth#POST_api_spoiler) | None |
| `POST` | [`/api/unignore_reports`](https://www.reddit.com/dev/api/oauth#POST_api_unignore_reports) | None |
| `POST` | [`/api/unlock`](https://www.reddit.com/dev/api/oauth#POST_api_unlock) | None |
| `POST` | [`/api/unmarknsfw`](https://www.reddit.com/dev/api/oauth#POST_api_unmarknsfw) | None |
| `POST` | [`/api/unspoiler`](https://www.reddit.com/dev/api/oauth#POST_api_unspoiler) | None |

modself
-------
Expand Down Expand Up @@ -280,6 +280,7 @@ read
| `GET` | [`/live/{thread}/discussions`](https://www.reddit.com/dev/api/oauth#GET_live_{thread}_discussions) | None |
| `GET` | [`/live/{thread}/updates/{update_id}`](https://www.reddit.com/dev/api/oauth#GET_live_{thread}_updates_{update_id}) | None |
| `GET` | [`/prefs/{where}`](https://www.reddit.com/dev/api/oauth#GET_prefs_{where}) | None |
| `GET` | [`/profiles/search`](https://www.reddit.com/dev/api/oauth#GET_profiles_search) | None |
| `GET` | [`[/r/{subreddit}]/sidebar`](https://www.reddit.com/dev/api/oauth#GET_sidebar) | None |
| `GET` | [`[/r/{subreddit}]/sticky`](https://www.reddit.com/dev/api/oauth#GET_sticky) | None |
| `GET` | [`/subreddits/{where}`](https://www.reddit.com/dev/api/oauth#GET_subreddits_{where}) | None |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![travis-ci build status](https://img.shields.io/travis/mattbdean/JRAW.svg)](https://travis-ci.org/mattbdean/JRAW)
[![Latest release](https://img.shields.io/github/release/mattbdean/JRAW.svg)](https://bintray.com/thatjavanerd/maven/JRAW/_latestVersion)
[![Kotlin 1.2.10](https://img.shields.io/badge/Kotlin-1.2.10-blue.svg)](http://kotlinlang.org)
[![API coverage](https://img.shields.io/badge/API_coverage-43%25-9C27B0.svg)](https://github.com/thatJavaNerd/JRAW/blob/master/ENDPOINTS.md)
[![API coverage](https://img.shields.io/badge/API_coverage-45%25-9C27B0.svg)](https://github.com/thatJavaNerd/JRAW/blob/master/ENDPOINTS.md)
[![Codecov branch](https://img.shields.io/codecov/c/github/mattbdean/JRAW.svg)](https://codecov.io/gh/mattbdean/JRAW)

```groovy
Expand Down
4 changes: 4 additions & 0 deletions lib/src/gen/java/net/dean/jraw/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ public enum Endpoint {
* Represents the endpoint {@code GET /prefs/{where}}. Requires OAuth scope 'read'. See <a href="https://www.reddit.com/dev/api/oauth#GET_prefs_{where}">here</a> for more information */
GET_PREFS_WHERE("GET", "/prefs/{where}", "read"),

/**
* Represents the endpoint {@code GET /profiles/search}. Requires OAuth scope 'read'. See <a href="https://www.reddit.com/dev/api/oauth#GET_profiles_search">here</a> for more information */
GET_PROFILES_SEARCH("GET", "/profiles/search", "read"),

/**
* Represents the endpoint {@code GET /r/{subreddit}/about}. Requires OAuth scope 'read'. See <a href="https://www.reddit.com/dev/api/oauth#GET_r_{subreddit}_about">here</a> for more information */
GET_SUBREDDIT_ABOUT("GET", "/r/{subreddit}/about", "read"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ abstract class PublicContributionReference internal constructor(reddit: RedditCl
}

/**
* Distinguish a comment or submission author with a sigil. Logged in user must have the priveleges to use the
* supplied [DistinguishedStatus], i.e. moderator priveleges for [DistinguishedStatus.MODERATOR] and admin
* priveleges for [DistinguishedStatus.ADMIN] and so on.
* Distinguish a comment or submission author with a sigil. Logged in user must have the privileges to use the
* supplied [DistinguishedStatus], i.e. moderator privileges for [DistinguishedStatus.MODERATOR] and admin
* privileges for [DistinguishedStatus.ADMIN] and so on.
*
* @param sticky Flag for comments, which will stick the distingushed comment to the top of all comments threads.
* @param sticky Flag for comments, which will stick the distinguished comment to the top of all comments threads.
* If a comment is marked sticky, it will override any other stickied comment for that post (as only one comment may
* be stickied at a time.) Only top-level comments may be stickied. Requires moderator privileges. Can only be used
* with [DistinguishedStatus.MODERATOR] or [DistinguishedStatus.ADMIN].
Expand All @@ -153,7 +153,8 @@ abstract class PublicContributionReference internal constructor(reddit: RedditCl
DistinguishedStatus.MODERATOR -> "yes"
DistinguishedStatus.ADMIN -> "admin"
DistinguishedStatus.SPECIAL -> "special"
DistinguishedStatus.GOLD -> throw IllegalArgumentException("Cannot manually distinguish a contribution with a gold distinguish status")
DistinguishedStatus.GOLD -> throw IllegalArgumentException(
"Cannot manually distinguish a contribution with a gold distinguish status")
}
if (sticky && this is SubmissionReference)
throw IllegalArgumentException("Flag 'sticky' can only be set for comments, not submissions")
Expand All @@ -172,7 +173,7 @@ abstract class PublicContributionReference internal constructor(reddit: RedditCl
}

/**
* Remove the contribution as a subreddit moderator. Requires mod priveleges on the subreddit of the contribution.
* Remove the contribution as a subreddit moderator. Requires mod privileges on the subreddit of the contribution.
*
* @param spam Whether spam is the reason for the removal. Trains the subreddit spamfilter to be critical of
* similar contributions in the future
Expand All @@ -191,7 +192,7 @@ abstract class PublicContributionReference internal constructor(reddit: RedditCl
}

/**
* Approve the contribution as a subreddit moderator. Requires mod priveleges on the subreddit of the contribution.
* Approve the contribution as a subreddit moderator. Requires mod privileges on the subreddit of the contribution.
*/
@EndpointImplementation(Endpoint.POST_APPROVE)
fun approve() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,50 @@ class SubmissionReference internal constructor(reddit: RedditClient, id: String)
}
}

// TODO - Requires mod privileges for the subreddit that contains the post.
/**
* Sets the [spoilerStatus] of a post using the official Reddit spoiler flair.
*/
@EndpointImplementation(Endpoint.POST_SPOILER, Endpoint.POST_UNSPOILER)
fun flagAsSpoiler(spoilerStatus: Boolean) {
val endpoint = if (spoilerStatus) Endpoint.POST_SPOILER else Endpoint.POST_UNSPOILER
reddit.request {
it.endpoint(endpoint)
.post(mapOf(
"id" to fullName
))
}
}

// TODO - Requires mod privileges for the subreddit that contains the post.
/**
* Set or unset the announcement [state] of a post in its subreddit. Reddit provides 2 allowable announcement
* "slots" for a subreddit, often referred to as sticky posts.
*
* Setting [num] will specify which sticky slot (of 2) to place the post into. If there is already an existing post
* in that slot, the new one will replace it. Passing in 0 for [num] will ignore that property in the payload and
* place the post into the bottom slot.
*
* Setting [toProfile] will sticky the post to an authenticated user's profile page. This is only used with new
* profile pages, not supported for legacy profiles.
*/
@EndpointImplementation(Endpoint.POST_SET_SUBREDDIT_STICKY)
fun stickyPost(state: Boolean, num: Int = 0, toProfile: Boolean = false) {
val payload = mutableMapOf(
"id" to fullName,
"state" to state.toString(),
"to_profile" to toProfile.toString()
)

if (num > 0) {
payload.put("num", num.toString())
}

reddit.request {
it.endpoint(Endpoint.POST_SET_SUBREDDIT_STICKY).post(payload)
}
}

/**
* Constructs a FlairReference for the submission. `subreddit` must be the subreddit where the submission was posted
* to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ class SubmissionReferenceTest : Spek({
}
}

describe("set spoiler") {
assume({ SharedObjects.submittedSelfPost != null }, description = "should have a self post created") {
val post = SharedObjects.submittedSelfPost!!
post.flagAsSpoiler(true)
post.inspect().isSpoiler.should.be.`true`
post.flagAsSpoiler(false)
post.inspect().isSpoiler.should.be.`false`
}
}

describe("sticky post submission") {
assume({ SharedObjects.submittedSelfPost != null }, description = "should have a self post created") {
val post = SharedObjects.submittedSelfPost!!
post.stickyPost(true)
post.inspect().isStickied.should.be.`true`
post.stickyPost(false)
post.inspect().isStickied.should.be.`false`
}
}

// This test must go last, since deleting the post will make it uneditable
describe("delete") {
assume({ SharedObjects.submittedSelfPost != null }, "should delete the submission") {
Expand Down

0 comments on commit 659b5e1

Please sign in to comment.