Module: Redd::Models::Postable

Included in:
Comment, Submission
Defined in:
lib/redd/models/postable.rb

Overview

Methods for user-submitted content, i.e. Submissions and Comments.

Instance Method Summary collapse

Instance Method Details

#deleteObject

Delete the thing.


16
17
18
# File 'lib/redd/models/postable.rb', line 16

def delete
  client.post('/api/del', id: read_attribute(:name))
end

#deleted?Boolean

Returns whether the item is probably deleted.

Returns:

  • (Boolean)

    whether the item is probably deleted


21
22
23
# File 'lib/redd/models/postable.rb', line 21

def deleted?
  read_attribute(:author).name == '[deleted]'
end

#disable_inbox_repliesObject

Stop sending replies to this thing to the user's inbox.


69
70
71
# File 'lib/redd/models/postable.rb', line 69

def disable_inbox_replies
  client.post('/api/sendreplies', id: read_attribute(:name), state: false)
end

#downvoteObject

Downvote the model.


54
55
56
# File 'lib/redd/models/postable.rb', line 54

def downvote
  vote(-1)
end

#edit(text) ⇒ self

Edit a thing.

Parameters:

  • text (String)

    The new text.

Returns:

  • (self)

    the edited thing


10
11
12
13
# File 'lib/redd/models/postable.rb', line 10

def edit(text)
  client.post('/api/editusertext', thing_id: read_attribute(:name), text: text)
  self
end

#enable_inbox_repliesObject

Send replies to this thing to the user's inbox.


64
65
66
# File 'lib/redd/models/postable.rb', line 64

def enable_inbox_replies
  client.post('/api/sendreplies', id: read_attribute(:name), state: true)
end

#hideObject

Hide a link from the user.


39
40
41
# File 'lib/redd/models/postable.rb', line 39

def hide
  client.post('/api/hide', id: read_attribute(:name))
end

#save(category = nil) ⇒ Object

Save a link or comment to the user's account.

Parameters:

  • category (String) (defaults to: nil)

    a category to save to


27
28
29
30
31
# File 'lib/redd/models/postable.rb', line 27

def save(category = nil)
  params = { id: read_attribute(:name) }
  params[:category] = category if category
  client.post('/api/save', params)
end

#undo_voteObject

Clear any upvotes or downvotes on the model.


59
60
61
# File 'lib/redd/models/postable.rb', line 59

def undo_vote
  vote(0)
end

#unhideObject

Unhide a previously hidden link.


44
45
46
# File 'lib/redd/models/postable.rb', line 44

def unhide
  client.post('/api/unhide', id: read_attribute(:name))
end

#unsaveObject

Remove the link or comment from the user's saved links.


34
35
36
# File 'lib/redd/models/postable.rb', line 34

def unsave
  client.post('/api/unsave', id: read_attribute(:name))
end

#upvoteObject

Upvote the model.


49
50
51
# File 'lib/redd/models/postable.rb', line 49

def upvote
  vote(1)
end