Skip to content

Commit 3068694

Browse files
authored
DEV: Adds method to retrieve invite (#230)
* DEV: Adds method to retrieve invite * DEV: allows nil params * DEV: checks email in invite spec
1 parent 167f04a commit 3068694

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

examples/invite_users.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919

2020
# if the user is an admin you may invite to a group as well
2121
client.invite_user_to_topic(email: "foo@bar.com", group_ids: "1,2,3", topic_id: 1)
22+
23+
# retrieve invite
24+
puts client.retrieve_invite(email: "foo@bar.com")

lib/discourse_api/api/invite.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def invite_to_topic(topic_id, params = {})
3535
post("/t/#{topic_id}/invite", args)
3636
end
3737

38+
def retrieve_invite(params = {})
39+
args = API.params(params).required(:email).to_h
40+
41+
response = get("invites/retrieve.json", args)
42+
43+
response.body
44+
end
45+
3846
# requires this plugin => https://github.com/discourse/discourse-invite-tokens
3947
def disposable_tokens(params = {})
4048
post("/invite-token/generate", params)

spec/discourse_api/api/invite_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,26 @@
3131
expect(a_put("#{host}/invites/27")).to have_been_made
3232
end
3333
end
34+
35+
describe "#retrieve_invite" do
36+
before do
37+
stub_get("#{host}/invites/retrieve.json?email=foo@bar.com").to_return(body: fixture("retrieve_invite.json"), headers: { content_type: "application/json" })
38+
end
39+
40+
it "requests the correct resource" do
41+
subject.retrieve_invite(email: "foo@bar.com")
42+
expect(a_get("#{host}/invites/retrieve.json?email=foo@bar.com")).to have_been_made
43+
end
44+
45+
it "returns the requested topics" do
46+
invites = subject.retrieve_invite(email: "foo@bar.com")
47+
expect(invites).to be_an Hash
48+
end
49+
50+
it "returns the requested invite" do
51+
invites = subject.retrieve_invite(email: "foo@bar.com")
52+
expect(invites["email"]).to eq("foo@bar.com")
53+
expect(invites).to have_key("invite_key")
54+
end
55+
end
3456
end

spec/fixtures/retrieve_invite.json

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"id": 26,
3+
"invite_key": "CGUHjNC4Na",
4+
"link": "http://localhost:3000/invites/CGUHjNC4Na",
5+
"email": "foo@bar.com",
6+
"emailed": true,
7+
"custom_message": null,
8+
"created_at": "2021-05-07T20:48:14.278Z",
9+
"updated_at": "2021-05-07T20:48:14.278Z",
10+
"expires_at": "2021-06-06T20:48:14.278Z",
11+
"expired": false,
12+
"topics": [
13+
{
14+
"id": 1,
15+
"title": "About the Site Feedback category",
16+
"fancy_title": "About the Site Feedback category",
17+
"slug": "about-the-site-feedback-category",
18+
"posts_count": 1
19+
}
20+
],
21+
"groups": [
22+
{
23+
"id": 1,
24+
"automatic": true,
25+
"name": "admins",
26+
"display_name": "admins",
27+
"user_count": 1,
28+
"mentionable_level": 0,
29+
"messageable_level": 0,
30+
"visibility_level": 1,
31+
"primary_group": false,
32+
"title": null,
33+
"grant_trust_level": null,
34+
"incoming_email": null,
35+
"has_messages": true,
36+
"flair_url": null,
37+
"flair_bg_color": null,
38+
"flair_color": null,
39+
"bio_raw": "",
40+
"bio_cooked": null,
41+
"bio_excerpt": null,
42+
"public_admission": false,
43+
"public_exit": false,
44+
"allow_membership_requests": false,
45+
"full_name": null,
46+
"default_notification_level": 3,
47+
"membership_request_template": null,
48+
"members_visibility_level": 0,
49+
"can_see_members": true,
50+
"can_admin_group": true,
51+
"publish_read_state": false
52+
},
53+
{
54+
"id": 2,
55+
"automatic": true,
56+
"name": "moderators",
57+
"display_name": "moderators",
58+
"user_count": 1,
59+
"mentionable_level": 0,
60+
"messageable_level": 99,
61+
"visibility_level": 1,
62+
"primary_group": false,
63+
"title": null,
64+
"grant_trust_level": null,
65+
"incoming_email": null,
66+
"has_messages": true,
67+
"flair_url": null,
68+
"flair_bg_color": null,
69+
"flair_color": null,
70+
"bio_raw": null,
71+
"bio_cooked": null,
72+
"bio_excerpt": null,
73+
"public_admission": false,
74+
"public_exit": false,
75+
"allow_membership_requests": false,
76+
"full_name": null,
77+
"default_notification_level": 2,
78+
"membership_request_template": null,
79+
"members_visibility_level": 0,
80+
"can_see_members": true,
81+
"can_admin_group": true,
82+
"publish_read_state": false
83+
},
84+
{
85+
"id": 3,
86+
"automatic": true,
87+
"name": "staff",
88+
"display_name": "staff",
89+
"user_count": 2,
90+
"mentionable_level": 0,
91+
"messageable_level": 0,
92+
"visibility_level": 1,
93+
"primary_group": false,
94+
"title": null,
95+
"grant_trust_level": null,
96+
"incoming_email": null,
97+
"has_messages": false,
98+
"flair_url": null,
99+
"flair_bg_color": null,
100+
"flair_color": null,
101+
"bio_raw": null,
102+
"bio_cooked": null,
103+
"bio_excerpt": null,
104+
"public_admission": false,
105+
"public_exit": false,
106+
"allow_membership_requests": false,
107+
"full_name": null,
108+
"default_notification_level": 3,
109+
"membership_request_template": null,
110+
"members_visibility_level": 0,
111+
"can_see_members": true,
112+
"can_admin_group": true,
113+
"publish_read_state": false
114+
}
115+
]
116+
}

0 commit comments

Comments
 (0)