Module: RedditKit::Client::PrivateMessages

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

Overview

Methods for retrieving and sending private messages.

Instance Method Summary collapse

Instance Method Details

#block_author_of_message(message) ⇒ Object

Blocks the author of a private message or comment. Users cannot be blocked based on username as reddit only allows you to block those who have harassed you (thus leaving a message in your inbox).

Parameters:



61
62
63
64
# File 'lib/redditkit/client/private_messages.rb', line 61

def block_author_of_message(message)
  parameters = { :id => extract_full_name(message) }
  post('api/block', parameters)
end

#mark_as_read(message) ⇒ Object

Marks a message as read.

Parameters:



44
45
46
47
# File 'lib/redditkit/client/private_messages.rb', line 44

def mark_as_read(message)
  parameters = { :id => extract_full_name(message) }
  post('api/read_message', parameters)
end

#mark_as_unread(message) ⇒ Object

Marks a message as unread.

Parameters:



52
53
54
55
# File 'lib/redditkit/client/private_messages.rb', line 52

def mark_as_unread(message)
  parameters = { :id => extract_full_name(message) }
  post('api/unread_message', parameters)
end

#messages(options = {}) ⇒ RedditKit::PaginatedResponse

Gets the current user’s private messages or comment replies.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :category (inbox, unread, sent, messages, mentions, moderator, comments, selfreply)

    The category from which to return messages.

  • :limit (1..100)

    The number of messages to return.

  • :before (String)

    Only return subreddits before this id.

  • :after (String)

    Only return subreddits after this id.

  • :mark (Boolean)

    Whether to mark requested messages as read.

Returns:



17
18
19
20
21
22
23
24
25
# File 'lib/redditkit/client/private_messages.rb', line 17

def messages(options = {})
  options = options.clone

  category = options[:category] || 'inbox'
  path = "message/#{category}.json"
  options.delete :category

  objects_from_response(:get, path, options)
end

#send_message(message, recipient, options = {}) ⇒ Object

Send a message to another reddit user.

Parameters:

  • message (String)

    The text of the message.

  • recipient (String, RedditKit::User)

    The recipient of the message.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :subject (String)

    The subject of the message.

  • :captcha_identifier (String)

    A CAPTCHA identifier to send with the message, if the current user is required to fill one out.

  • :captcha_value (String)

    The value of the CAPTCHA to send with the message, if the current user is required to fill one out.



34
35
36
37
38
39
# File 'lib/redditkit/client/private_messages.rb', line 34

def send_message(message, recipient, options = {})
  username = extract_string(recipient, :username)
  parameters = { :to => username, :text => message, :subject => options[:subject], :captcha => options[:captcha_value], :iden => options[:captcha_identifier] }

  post('api/compose', parameters)
end

#unblock(user) ⇒ Object

Unblocks a user.

Parameters:

  • user (String, RedditKit::User)

    A user’s username, or a RedditKit::User.



69
70
71
72
# File 'lib/redditkit/client/private_messages.rb', line 69

def unblock(user)
  enemy_name = extract_string(user, :username)
  friend_request 'unfriend', :container => current_user.full_name, :name => enemy_name, :type => :enemy
end