Module: Snoo::PM

Defined in:
lib/snoo/pms.rb

Overview

Methods for interacting with private messages

Author:

Instance Method Summary collapse

Instance Method Details

#block_pm(id) ⇒ Object

Block a user from sending you messages

Parameters:

  • id (String)

    the user id.



11
12
13
14
# File 'lib/snoo/pms.rb', line 11

def block_pm id
  logged_in?
  post('/api/block', body: {id: id, uh: @modhash, api_type: 'json'})
end

#get_messages(where = "inbox", opts = {}) ⇒ Object

Gets a listing of PMs

Parameters:

  • where (inbox, unread, sent) (defaults to: "inbox")

    Where to get messages from

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

    a customizable set of options

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

    An options hash

Options Hash (opts):

  • :mark (true, false) — default: false

    Mark the messages requested as read?

  • :limit (1..100)

    The total number of messages to get

  • :before (String)

    Get all comments before this id

  • :after (String)

    Get all comments after this



55
56
57
58
59
60
61
# File 'lib/snoo/pms.rb', line 55

def get_messages where = "inbox", opts = {}
  query = {
    mark: false
  }
  query.merge! opts
  get("/message/#{where}.json", query: query)
end

#mark_read(id) ⇒ Object

Mark a PM as read

Parameters:

  • id (String)

    The message id



32
33
34
35
# File 'lib/snoo/pms.rb', line 32

def mark_read id
  logged_in?
  post('/api/read_message', body: {id: id, uh: @modhash, api_type: 'json'})
end

#mark_unread(id) ⇒ Object

Mark a PM as unread

Parameters:

  • id (String)

    The message id



41
42
43
44
# File 'lib/snoo/pms.rb', line 41

def mark_unread id
  logged_in?
  post('/api/unread_message', body: {id: id, uh: @modhash, api_type: 'json'})
end

#send_pm(to, subject, text) ⇒ Object

Send a private message To reply to PM, use LinksComments#comment, with the PM id as the link id

Parameters:

  • to (String)

    The username you are sending to

  • subject (String)

    The subject of the message

  • text (String)

    The message body



23
24
25
26
# File 'lib/snoo/pms.rb', line 23

def send_pm to, subject, text
  logged_in?
  post('/api/compose.json', body: {to: to, subject: subject, text: text, uh: @modhash, api_type: 'json'})
end