Skip to content

Commit a459d43

Browse files
DEPRECATED: create_private_message (#236)
`create_private_message` has been deprecated to remove the use of the `target_usernames` parameter. A deprecation warning message will now be outputed if you use that method. Please use `create_pm` from now on with the `target_recipients` param.
1 parent deff9d3 commit a459d43

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/discourse_api/api/private_messages.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ module DiscourseApi
33
module API
44
module PrivateMessages
55

6-
# :target_usernames REQUIRED comma separated list of usernames
6+
# TODO: Deprecated. Remove after 20220628
7+
def create_private_message(args = {})
8+
deprecated(__method__, 'create_pm')
9+
args[:target_recipients] = args.delete :target_usernames
10+
create_pm(args.to_h)
11+
end
12+
13+
# :target_recipients REQUIRED comma separated list of usernames
714
# :category OPTIONAL name of category, not ID
815
# :created_at OPTIONAL seconds since epoch.
9-
def create_private_message(args = {})
16+
def create_pm(args = {})
1017
args[:archetype] = 'private_message'
1118
args = API.params(args)
12-
.required(:title, :raw, :target_usernames, :archetype)
19+
.required(:title, :raw, :target_recipients, :archetype)
1320
.optional(:category, :created_at, :api_username)
1421
post("/posts", args.to_h)
1522
end

spec/discourse_api/api/private_messages_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@
3636
end
3737
end
3838

39-
describe '#create_private_message' do
39+
describe '#create_pm' do
4040
before do
4141
stub_post("#{host}/posts")
42-
subject.create_private_message(
42+
subject.create_pm(
4343
title: "Confidential: Hello World!",
4444
raw: "This is the raw markdown for my private message",
45-
target_usernames: "user1,user2"
45+
target_recipients: "user1,user2"
4646
)
4747
end
4848

4949
it "makes a create private message request" do
5050
expect(a_post("#{host}/posts").with(body:
51-
'archetype=private_message&raw=This+is+the+raw+markdown+for+my+private+message&target_usernames=user1%2Cuser2&title=Confidential%3A+Hello+World%21')
51+
'archetype=private_message&raw=This+is+the+raw+markdown+for+my+private+message&target_recipients=user1%2Cuser2&title=Confidential%3A+Hello+World%21')
5252
).to have_been_made
5353
end
5454
end

0 commit comments

Comments
 (0)