module Redd::Models::Postable

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

Public Instance Methods

delete() click to toggle source

Delete the thing.

# File lib/redd/models/postable.rb, line 17
def delete
  @client.post('/api/del', id: get_attribute(:name))
end
disable_inbox_replies() click to toggle source

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

# File lib/redd/models/postable.rb, line 65
def disable_inbox_replies
  @client.post('/api/sendreplies', id: get_attribute(:name), state: false)
end
downvote() click to toggle source

Downvote the model.

# File lib/redd/models/postable.rb, line 50
def downvote
  vote(-1)
end
edit(text) click to toggle source

Edit a thing. @param text [String] The new text. @return [self] the edited thing

# File lib/redd/models/postable.rb, line 10
def edit(text)
  @client.post('/api/editusertext', thing_id: get_attribute(:name), text: text)
  @attributes[is_a?(Submission) ? :selftext : :body] = text
  self
end
enable_inbox_replies() click to toggle source

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

# File lib/redd/models/postable.rb, line 60
def enable_inbox_replies
  @client.post('/api/sendreplies', id: get_attribute(:name), state: true)
end
hide() click to toggle source

Hide a link from the user.

# File lib/redd/models/postable.rb, line 35
def hide
  @client.post('/api/hide', id: get_attribute(:name))
end
save(category = nil) click to toggle source

Save a link or comment to the user's account. @param category [String] a category to save to

# File lib/redd/models/postable.rb, line 23
def save(category = nil)
  params = { id: get_attribute(:name) }
  params[:category] = category if category
  @client.post('/api/save', params)
end
undo_vote() click to toggle source

Clear any upvotes or downvotes on the model.

# File lib/redd/models/postable.rb, line 55
def undo_vote
  vote(0)
end
unhide() click to toggle source

Unhide a previously hidden link.

# File lib/redd/models/postable.rb, line 40
def unhide
  @client.post('/api/unhide', id: get_attribute(:name))
end
unsave() click to toggle source

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

# File lib/redd/models/postable.rb, line 30
def unsave
  @client.post('/api/unsave', id: get_attribute(:name))
end
upvote() click to toggle source

Upvote the model.

# File lib/redd/models/postable.rb, line 45
def upvote
  vote(1)
end

Private Instance Methods

vote(direction) click to toggle source

Send a vote. @param direction [-1, 0, 1] the direction to vote in

# File lib/redd/models/postable.rb, line 73
def vote(direction)
  fullname = get_attribute(:name)
  @client.post('/api/vote', id: fullname, dir: direction)
  @attributes[:ups] += direction
end