Module: RedditKit::Client::Moderation

Included in:
RedditKit::Client
Defined in:
lib/redditkit/client/moderation.rb

Overview

Methods for moderating subreddits.

Instance Method Summary collapse

Instance Method Details

#accept_moderator_invitation(subreddit) ⇒ Object

Accepts an invitation to become a moderator of a subreddit.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

    The display name of the subreddit, or a RedditKit::Subreddit.



105
106
107
108
# File 'lib/redditkit/client/moderation.rb', line 105

def accept_moderator_invitation(subreddit)
  subreddit_name = extract_string(subreddit, :display_name)
  post 'api/accept_moderator_invite', :r => subreddit_name
end

#approve(link) ⇒ Object

Approves an unmoderated link.

Parameters:

  • link (String, RedditKit::Link)

    A link’s full name, or a RedditKit::Link.



29
30
31
32
# File 'lib/redditkit/client/moderation.rb', line 29

def approve(link)
  full_name = extract_full_name link
  post 'api/approve', { :id => full_name, :api_type => :json }
end

#ban(user, subreddit) ⇒ Object

Note:

If a subreddit’s name is passed as the :subreddit option, a second HTTP request will be made to get the RedditKit::Subreddit object.

Ban a user. This requires moderator privileges on the specified subreddit.

Parameters:

  • user (String, RedditKit::User)

    The user’s username, or a RedditKit::User.

  • subreddit (String, RedditKit::Subreddit)

    The subreddit’s name, or a RedditKit::Subreddit.



14
15
16
# File 'lib/redditkit/client/moderation.rb', line 14

def ban(user, subreddit)
  ban_or_unban_user true, user, subreddit
end

#contributors_to_subreddit(subreddit) ⇒ Array<OpenStruct>

Get the contributors to a subreddit.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

    The display name of a subreddit, or a RedditKit::Subreddit.

Returns:

  • (Array<OpenStruct>)


98
99
100
# File 'lib/redditkit/client/moderation.rb', line 98

def contributors_to_subreddit(subreddit)
  members_in_subreddit subreddit, 'contributors'
end

#distinguish(comment, how = 'yes') ⇒ Object

Note:

admin and special values may only be used if the current user has the right privileges.

Distinguishes a comment as being posted by a moderator or admin.

Parameters:

  • comment (String, RedditKit::Comment)

    The full name of a comment, or a RedditKit::Comment.

  • how (yes, no, admin, special) (defaults to: 'yes')

    How to distinguish the comment. Defaults to yes.



63
64
65
66
67
68
# File 'lib/redditkit/client/moderation.rb', line 63

def distinguish(comment, how = 'yes')
  full_name = extract_full_name comment
  parameters = { :id => full_name, :api_type => :json }

  post "api/distinguish/#{how}", parameters
end

#ignore_reports(object) ⇒ Object

Ignores the reports on a link or comment.

Parameters:



45
46
47
48
# File 'lib/redditkit/client/moderation.rb', line 45

def ignore_reports(object)
  full_name = extract_full_name object
  post 'api/ignore_reports', { :id => full_name, :api_type => :json }
end

#moderation_log(subreddit) ⇒ RedditKit::PaginatedResponse

Gets the moderation log for a subreddit.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

    A subreddit’s display name, or a RedditKit::Subreddit.

Returns:



138
139
140
141
# File 'lib/redditkit/client/moderation.rb', line 138

def moderation_log(subreddit)
  display_name = extract_string subreddit, :display_name
  objects_from_response(:get, "r/#{display_name}/about/log.json", nil)
end

#moderators_of_subreddit(subreddit) ⇒ Array<OpenStruct>

Get the moderators of a subreddit.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

    The display name of a subreddit, or a RedditKit::Subreddit.

Returns:

  • (Array<OpenStruct>)


90
91
92
# File 'lib/redditkit/client/moderation.rb', line 90

def moderators_of_subreddit(subreddit)
  members_in_subreddit subreddit, 'moderators'
end

#remove(object) ⇒ Object

Removes a link or comment.

Parameters:



37
38
39
40
# File 'lib/redditkit/client/moderation.rb', line 37

def remove(object)
  full_name = extract_full_name object
  post 'api/remove', { :id => full_name, :api_type => :json }
end

#reset_subreddit_header(subreddit) ⇒ Object

Resets a subreddit’s header image.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

    The display name of the subreddit, or a RedditKit::Subreddit.



129
130
131
132
# File 'lib/redditkit/client/moderation.rb', line 129

def reset_subreddit_header(subreddit)
  subreddit_name = extract_string(subreddit, :display_name)
  post 'api/delete_sr_header', :r => subreddit_name
end

#resign_as_contributor(subreddit) ⇒ Object

Resign as a contributor to a subreddit.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

    A subreddit’s full name, or a RedditKit::Subreddit.



113
114
115
116
# File 'lib/redditkit/client/moderation.rb', line 113

def resign_as_contributor(subreddit)
  full_name = extract_full_name subreddit
  post 'api/leavecontributor', :id => full_name
end

#resign_as_moderator(subreddit) ⇒ Object

Resign as a moderator of a subreddit.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

    A subreddit’s full name, or a RedditKit::Subreddit.



121
122
123
124
# File 'lib/redditkit/client/moderation.rb', line 121

def resign_as_moderator(subreddit)
  full_name = extract_full_name subreddit
  post 'api/leavemoderator', :id => full_name
end

#set_contest_mode(link, contest_mode = true) ⇒ Object

Sets a post as have its contest mode enabled or disabled.

Parameters:

  • link (String, RedditKit::Link)

    The full name of a link, or a RedditKit::Link.

  • contest_mode (Boolean) (defaults to: true)

    Whether to enable contest mode for the link’s comments. Defaults to true.



74
75
76
# File 'lib/redditkit/client/moderation.rb', line 74

def set_contest_mode(link, contest_mode = true)
  set_boolean_on_link 'api/set_contest_mode', link, contest_mode
end

#set_sticky_post(link, sticky = true) ⇒ Object

Sets a post as sticky within its parent subreddit. This will replace the existing sticky post, if there is one.

Parameters:

  • link (String, RedditKit::Link)

    The full name of a link, or a RedditKit::Link.

  • sticky (Boolean) (defaults to: true)

    Whether to mark the post as sticky or unsticky. Defaults to true.



82
83
84
# File 'lib/redditkit/client/moderation.rb', line 82

def set_sticky_post(link, sticky = true)
  set_boolean_on_link 'api/set_subreddit_sticky', link, sticky
end

#unban(user, subreddit) ⇒ Object

Lift the ban on a user. This requires moderator privileges on the specified subreddit.

Parameters:

  • user (String, RedditKit::User)

    The user’s username, or a RedditKit::User.

  • subreddit (String, RedditKit::Subreddit)

    The subreddit’s name, or a RedditKit::Subreddit.



22
23
24
# File 'lib/redditkit/client/moderation.rb', line 22

def unban(user, subreddit)
  ban_or_unban_user false, user, subreddit
end

#unignore_reports(object) ⇒ Object

Unignores the reports on a link or comment.

Parameters:



53
54
55
56
# File 'lib/redditkit/client/moderation.rb', line 53

def unignore_reports(object)
  full_name = extract_full_name object
  post 'api/unignore_reports', { :id => full_name, :api_type => :json }
end