Skip to content

Commit 3227bbd

Browse files
authored
DEV: separates required & optional params in invite module (#228)
* DEV: seperates required & optional params in invite module * DEV: adds 'agrs' variable to post method * DEV: adds topic_id as seperate param * DEV: deprecated 'invite_user_to_topic' method * DEV: deprecated 'invite_user_to_topic' method * FIX: changes remove date to 2022 * DEV: rubocop
1 parent 8bd6ef3 commit 3227bbd

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

examples/invite_users.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
1616

1717
# if the user is an admin you may invite to a group as well
18-
client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1, group_ids: "1,2,3")
18+
client.invite_user_to_topic(email: "foo@bar.com", group_ids: "1,2,3", topic_id: 1)

lib/discourse_api/api/invite.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,36 @@ module DiscourseApi
33
module API
44
module Invite
55
def invite_user(params = {})
6-
post("/invites", params)
6+
args = API.params(params)
7+
.optional(
8+
:email,
9+
:skip_email,
10+
:custom_message,
11+
:max_redemptions_allowed,
12+
:topic_id,
13+
:group_ids,
14+
:expires_at
15+
).to_h
16+
17+
post("/invites", args)
718
end
819

20+
# TODO: Deprecated. Remove after 20220506
921
def invite_user_to_topic(params = {})
10-
post("/t/#{params[:topic_id]}/invite", params)
22+
deprecated(__method__, 'invite_to_topic')
23+
invite_to_topic(params[:topic_id], params)
24+
end
25+
26+
def invite_to_topic(topic_id, params = {})
27+
args = API.params(params)
28+
.optional(
29+
:email,
30+
:user,
31+
:group_ids,
32+
:custom_message
33+
).to_h
34+
35+
post("/t/#{topic_id}/invite", args)
1136
end
1237

1338
# requires this plugin => https://github.com/discourse/discourse-invite-tokens

spec/discourse_api/api/topics_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
expect(a_post("#{host}/t/12/invite")).to have_been_made
2626
end
2727

28+
it "requests the correct resource with new method 'invite_to_topic'" do
29+
subject.invite_to_topic(12, email: "fake_user@example.com")
30+
expect(a_post("#{host}/t/12/invite")).to have_been_made
31+
end
32+
2833
it "returns success" do
2934
response = subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
3035
expect(response).to be_a Hash

0 commit comments

Comments
 (0)