Module: DiscourseApi::API::PrivateMessages

Included in:
Client
Defined in:
lib/discourse_api/api/private_messages.rb

Instance Method Summary collapse

Instance Method Details

#create_pm(args = {}) ⇒ Object

:target_recipients REQUIRED comma separated list of usernames :category OPTIONAL name of category, not ID :created_at OPTIONAL seconds since epoch.



15
16
17
18
19
20
21
22
23
# File 'lib/discourse_api/api/private_messages.rb', line 15

def create_pm(args = {})
  args[:archetype] = "private_message"
  args =
    API
      .params(args)
      .required(:title, :raw, :target_recipients, :archetype)
      .optional(:category, :created_at, :api_username)
  post("/posts", args.to_h)
end

#create_private_message(args = {}) ⇒ Object

TODO: Deprecated. Remove after 20220628



6
7
8
9
10
# File 'lib/discourse_api/api/private_messages.rb', line 6

def create_private_message(args = {})
  deprecated(__method__, "create_pm")
  args[:target_recipients] = args.delete :target_usernames
  create_pm(args.to_h)
end

#private_messages(username, *args) ⇒ Object



25
26
27
28
# File 'lib/discourse_api/api/private_messages.rb', line 25

def private_messages(username, *args)
  response = get("topics/private-messages/#{username}.json", args)
  response[:body]["topic_list"]["topics"]
end

#sent_private_messages(username, *args) ⇒ Object



30
31
32
33
# File 'lib/discourse_api/api/private_messages.rb', line 30

def sent_private_messages(username, *args)
  response = get("topics/private-messages-sent/#{username}.json", args)
  response[:body]["topic_list"]["topics"]
end