Module: Redd::Objects::Thing::Messageable

Included in:
Subreddit, User
Defined in:
lib/redd/objects/thing/messageable.rb

Overview

Things that can be sent a message.

Instance Method Summary collapse

Instance Method Details

#send_message(subject, text, from_sr = nil, captcha = nil, identifier = nil) ⇒ Object

Compose a message to a person or the moderators of a subreddit.

rubocop:disable Metrics/MethodLength

Parameters:

  • subject (String)

    The subject of the message.

  • text (String)

    The message text.

  • from_sr (String) (defaults to: nil)

    The subreddit to send the message on behalf of or nil if from the user.

  • captcha (String) (defaults to: nil)

    A possible captcha result to send if one is required.

  • identifier (String) (defaults to: nil)

    The identifier for the captcha if one is required.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/redd/objects/thing/messageable.rb', line 17

def send_message(
  subject, text, from_sr = nil, captcha = nil, identifier = nil
)
  params = { subject: subject, text: text }
  if captcha
    params[:captcha] = captcha
    params[:iden] = identifier
  end
  params[:from_sr] = client.property(from_sr, :display_name) if from_sr
  params[:to] =
    if respond_to?(:display_name)
      "/r/#{self[:display_name]}"
    else
      self[:name]
    end

  post('/api/compose', params)
end