Class: Redd::Models::WikiPage

Inherits:
Model
  • Object
show all
Defined in:
lib/redd/models/wiki_page.rb

Overview

A reddit user.

Instance Attribute Summary collapse

Attributes inherited from Model

#client

Instance Method Summary collapse

Methods inherited from Model

#initialize

Constructor Details

This class inherits a constructor from Redd::Models::Model

Instance Attribute Details

#content_htmlString (readonly)

Returns the html version of the content.

Returns:

  • (String)

    the html version of the content


40
# File 'lib/redd/models/wiki_page.rb', line 40

property :content_html

#content_mdString (readonly)

Returns the markdown version of the content.

Returns:

  • (String)

    the markdown version of the content


36
# File 'lib/redd/models/wiki_page.rb', line 36

property :content_md

#may_revise?Boolean (readonly)

Returns not sure, whether you're allowed to edit the page?.

Returns:

  • (Boolean)

    not sure, whether you're allowed to edit the page?


28
# File 'lib/redd/models/wiki_page.rb', line 28

property :may_revise?, from: :may_revise

#revision_byUser (readonly)

Returns the user who made the last revision.

Returns:

  • (User)

    the user who made the last revision


44
# File 'lib/redd/models/wiki_page.rb', line 44

property :revision_by, with: ->(res) { User.new(client, res[:data]) }

#revision_dateTime (readonly)

Returns the time of the last revision.

Returns:

  • (Time)

    the time of the last revision


32
# File 'lib/redd/models/wiki_page.rb', line 32

property :revision_date, with: ->(t) { Time.at(t) }

#subredditSubreddit (readonly)

Returns the wiki page's (optional) subreddit.

Returns:

  • (Subreddit)

    the wiki page's (optional) subreddit


24
# File 'lib/redd/models/wiki_page.rb', line 24

property :subreddit, :nil

#titleString (readonly)

Returns the page title.

Returns:

  • (String)

    the page title


20
# File 'lib/redd/models/wiki_page.rb', line 20

property :title, :required

Instance Method Details

#edit(content, reason: nil) ⇒ Object

Edit the wiki page.

Parameters:

  • content (String)

    the new wiki page contents

  • reason (String, nil) (defaults to: nil)

    an optional reason for editing the page


12
13
14
15
16
# File 'lib/redd/models/wiki_page.rb', line 12

def edit(content, reason: nil)
  params = { page: read_attribute(:title), content: content }
  params[:reason] = reason if reason
  client.post("/r/#{read_attribute(:subreddit).display_name}/api/wiki/edit", params)
end