Module: RedditKit::Client::Wiki

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

Overview

Methods for interacting with a subreddit’s wiki.

Instance Method Summary collapse

Instance Method Details

#add_wiki_editor(subreddit, user, page) ⇒ Object

Adds a user as an approved editor of a wiki page.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

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

  • user (String, RedditKit::User)

    A user’s full name, or a RedditKit::User.

  • page (String)

    page The name of an existing wiki page.



12
13
14
# File 'lib/redditkit/client/wiki.rb', line 12

def add_wiki_editor(subreddit, user, page)
  toggle_wiki_editor(subreddit, user, page, 'add')
end

#edit_wiki_page(options) ⇒ Object

Edits a wiki page.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • subreddit (String, RedditKit::Subreddit)

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

  • page (String)

    The name of an existing wiki page.

  • content (String)

    The contents of the edit.

  • reason (String)

    The reason for the edit.

  • previous_revision (String)

    The starting revision for this edit.



32
33
34
35
36
37
# File 'lib/redditkit/client/wiki.rb', line 32

def edit_wiki_page(options)
  subreddit_name = extract_string(options[:subreddit], :display_name)
  parameters = { :page => options[:page], :previous => options[:previous_revision], :content => options[:content], :reason => options[:reason] }

  post("r/#{subreddit_name}/api/wiki/edit", parameters)
end

#hide_wiki_revision(options) ⇒ Boolean

Hides a wiki page revision. If the revision is already hidden, this will unhide it.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • subreddit (String, RedditKit::Subreddit)

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

  • page (String)

    The name of an existing wiki page.

  • revision (String)

    The revision to hide.

Returns:

  • (Boolean)

    True if the revision is now hidden, false if it is not hidden.



45
46
47
48
49
50
51
52
53
# File 'lib/redditkit/client/wiki.rb', line 45

def hide_wiki_revision(options)
  options = options.clone

  subreddit_name = extract_string(options[:subreddit], :display_name)
  options.delete :subreddit

  response = post("r/#{subreddit_name}/api/wiki/hide", options)
  response[:body][:status]
end

#remove_wiki_editor(subreddit, user, page) ⇒ Object

Removes a user from being an approved editor of a wiki page.

Parameters:

  • subreddit (String, RedditKit::Subreddit)

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

  • user (String, RedditKit::User)

    A user’s full name, or a RedditKit::User.

  • page (String)

    page The name of an existing wiki page.



21
22
23
# File 'lib/redditkit/client/wiki.rb', line 21

def remove_wiki_editor(subreddit, user, page)
  toggle_wiki_editor(subreddit, user, page, 'del')
end

#revert_to_revision(options) ⇒ Object

Reverts to a specific wiki page revision.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • subreddit (String, RedditKit::Subreddit)

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

  • page (String)

    The name of an existing wiki page.

  • revision (String)

    The revision to revert to.



60
61
62
63
64
65
66
67
# File 'lib/redditkit/client/wiki.rb', line 60

def revert_to_revision(options)
  options = options.clone

  subreddit_name = extract_string(options[:subreddit], :display_name)
  options.delete :subreddit

  post("r/#{subreddit_name}/api/wiki/revert", options)
end