Module: RedditKit::Client::Voting

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

Overview

Methods for voting on links and comments.

Instance Method Summary collapse

Instance Method Details

#downvote(link_or_comment) ⇒ Object

Downvotes a link or comment.

Parameters:



17
18
19
# File 'lib/redditkit/client/voting.rb', line 17

def downvote(link_or_comment)
  vote link_or_comment, -1
end

#upvote(link_or_comment) ⇒ Object

Upvotes a link or comment.

Parameters:



10
11
12
# File 'lib/redditkit/client/voting.rb', line 10

def upvote(link_or_comment)
  vote link_or_comment, 1
end

#vote(link_or_comment, direction) ⇒ Object

Votes on a link or comment.

Parameters:

  • link_or_comment (String, RedditKit::Comment, RedditKit::Link)

    The link or comment from which to withdraw the vote.

  • direction (-1, 0, 1)

    Downvote, no vote, and upvote respectively.



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

def vote(link_or_comment, direction)
  full_name = extract_full_name(link_or_comment)
  parameters = { :id => full_name, :dir => direction, :api_type => 'json' }

  post('api/vote', parameters)
end

#withdraw_vote(link_or_comment) ⇒ Object

Withdraws a vote on a link or comment.

Parameters:



24
25
26
# File 'lib/redditkit/client/voting.rb', line 24

def withdraw_vote(link_or_comment)
  vote link_or_comment, 0
end