discourse_api 0.46.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83d6fc91bd7fd472cc3eab0fa06b79d0fbaa5e4cf7a2003bef82eee43f33acf4
4
- data.tar.gz: c0aef1ea4eee35c3cf3143d100707c2850829e5551c79af3a6d6f76efb3b262c
3
+ metadata.gz: 3fffa65d4ed129c229766cecd20c2b5684570d22dcd08deaa44474f37cbe0b7c
4
+ data.tar.gz: 35db4a119a91642c632b43b78cbde678c2a753f28adb88b376bf1b5ab9bb6a2b
5
5
  SHA512:
6
- metadata.gz: 4227051151b05bd67b403a9922d0199b4cdaf84ccf5973e4be57fb63af8345053b0d80ca763aa2a9c49c27a1a73a623540bde643a714710298c57e73c4a3a0d3
7
- data.tar.gz: 5a6dfdc85bf1db5edb7e474ecfa1df038a617ebb4d3bf890611d6e195e3093d441e2dbdb3826ad468cc397e6de420f4d4d295b275ad0febb78fb32ae86dfec8e
6
+ metadata.gz: 7353e073896a9e70d38336cba97d0c0f53f951c925e21e4333cc67fd8bfbd40ce5745f50ee6c6a87ce3e5c69c77d67e3287458a96418f033c9ee88901da7e3fa
7
+ data.tar.gz: 8a3cbddb1585c72dcf3eeaa3723e4742007b076c239e47a23cbf98c87024a95e4712e54eed85be4b48f9100acef41b282b91007c05237cc10048d5753ed82db4
data/CHANGELOG.md CHANGED
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.47.0] - 2021-07-19
10
+ ### Added
11
+ - Update invite method
12
+ - Retrieve invite method
13
+ - Destroy all expired invites method
14
+ - Destroy invite method
15
+ - Resend all invites method
16
+ - Resend invite method
17
+ - Pass params to get notifications API
18
+
19
+ ### Deprecated
20
+ - `invite_user_to_topic` has been deprecated, use `invite_user` instead.
21
+ - `create_private_message` has been deprecated, use `create_pm` instead.
22
+
9
23
  ## [0.46.0] - 2021-04-12
10
24
  ### Added
11
25
  - Allow bookmarking topics
@@ -9,10 +9,28 @@ client.api_key = config['api_key'] || "YOUR_API_KEY"
9
9
  client.api_username = config['api_username'] || "YOUR_USERNAME"
10
10
 
11
11
  # invite user
12
- client.invite_user(email: "name@example.com", group_ids: "41,42")
12
+ invite = client.invite_user(email: "name@example.com", group_ids: "41,42")
13
+
14
+ #update invite
15
+ client.update_invite(invite["id"], email: "namee@example.com")
16
+
17
+ # resend invite
18
+ client.resend_invite("namee@example.com")
13
19
 
14
20
  # invite to a topic
15
21
  client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
16
22
 
17
23
  # 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")
24
+ client.invite_user_to_topic(email: "foo@bar.com", group_ids: "1,2,3", topic_id: 1)
25
+
26
+ # retrieve invite
27
+ puts client.retrieve_invite(email: "foo@bar.com")
28
+
29
+ # resend all invites
30
+ client.resend_all_invites
31
+
32
+ # destroy invite
33
+ client.destroy_invite(invite["id"])
34
+
35
+ # destroy all expired invites
36
+ client.destroy_all_expired_invites
@@ -13,3 +13,6 @@ client.category_set_user_notification_level(1, notification_level: 3)
13
13
 
14
14
  # mute a topic
15
15
  client.topic_set_user_notification_level(1, notification_level: 0)
16
+
17
+ # get user notifications
18
+ client.notifications(username: 'discourse')
@@ -3,17 +3,82 @@ module DiscourseApi
3
3
  module API
4
4
  module Invite
5
5
  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)
7
18
  end
8
19
 
20
+ # TODO: Deprecated. Remove after 20220506
9
21
  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)
36
+ end
37
+
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
11
44
  end
12
45
 
13
46
  # requires this plugin => https://github.com/discourse/discourse-invite-tokens
14
47
  def disposable_tokens(params = {})
15
48
  post("/invite-token/generate", params)
16
49
  end
50
+
51
+ def update_invite(invite_id, params = {})
52
+ args = API.params(params)
53
+ .optional(
54
+ :topic_id,
55
+ :group_ids,
56
+ :group_names,
57
+ :email,
58
+ :send_email,
59
+ :custom_message,
60
+ :max_redemptions_allowed,
61
+ :expires_at
62
+ ).to_h
63
+
64
+ put("invites/#{invite_id}", args)
65
+ end
66
+
67
+ def destroy_all_expired_invites
68
+ post("invites/destroy-all-expired")
69
+ end
70
+
71
+ def resend_all_invites
72
+ post("invites/reinvite-all")
73
+ end
74
+
75
+ def resend_invite(email)
76
+ post("invites/reinvite", { "email": email })
77
+ end
78
+
79
+ def destroy_invite(invite_id)
80
+ delete("/invites", { id: invite_id })
81
+ end
17
82
  end
18
83
  end
19
84
  end
@@ -2,8 +2,11 @@
2
2
  module DiscourseApi
3
3
  module API
4
4
  module Notifications
5
- def notifications
6
- response = get('/notifications.json')
5
+ def notifications(params = {})
6
+ params = API.params(params)
7
+ .optional(:username, :recent, :limit, :offset, :filter)
8
+
9
+ response = get('/notifications.json', params)
7
10
  response[:body]
8
11
  end
9
12
  end
@@ -3,13 +3,20 @@ module DiscourseApi
3
3
  module API
4
4
  module PrivateMessages
5
5
 
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
7
14
  # :category OPTIONAL name of category, not ID
8
15
  # :created_at OPTIONAL seconds since epoch.
9
- def create_private_message(args = {})
16
+ def create_pm(args = {})
10
17
  args[:archetype] = 'private_message'
11
18
  args = API.params(args)
12
- .required(:title, :raw, :target_usernames, :archetype)
19
+ .required(:title, :raw, :target_recipients, :archetype)
13
20
  .optional(:category, :created_at, :api_username)
14
21
  post("/posts", args.to_h)
15
22
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseApi
3
- VERSION = "0.46.0"
3
+ VERSION = "0.47.0"
4
4
  end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe DiscourseApi::API::Invite do
5
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
+
7
+ describe "#invite_user" do
8
+ before do
9
+ stub_post("#{host}/invites").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
10
+ end
11
+
12
+ it "requests the correct resource" do
13
+ subject.invite_user(email: "fake_user@example.com", group_ids: "41,42")
14
+ expect(a_post("#{host}/invites")).to have_been_made
15
+ end
16
+
17
+ it "returns success" do
18
+ response = subject.invite_user(email: "fake_user@example.com", group_ids: "41,42")
19
+ expect(response).to be_a Hash
20
+ expect(response['success']).to be_truthy
21
+ end
22
+ end
23
+
24
+ describe "#update_invite" do
25
+ before do
26
+ stub_put("#{host}/invites/27").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
27
+ end
28
+
29
+ it "updates invite" do
30
+ subject.update_invite(27, email: "namee@example.com")
31
+ expect(a_put("#{host}/invites/27")).to have_been_made
32
+ end
33
+ 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
56
+
57
+ describe "#destroy_all_expired_invites" do
58
+ let(:url) { "#{host}/invites/destroy-all-expired" }
59
+
60
+ before do
61
+ stub_post(url)
62
+ .to_return(
63
+ body: '{"success": "OK"}',
64
+ headers: { content_type: "application/json" }
65
+ )
66
+ end
67
+
68
+ it "destroys all expired invites" do
69
+ subject.destroy_all_expired_invites
70
+ expect(a_post(url)).to have_been_made
71
+ end
72
+ end
73
+
74
+ describe "#resend_all_invites" do
75
+ let(:url) { "#{host}/invites/reinvite-all" }
76
+
77
+ before do
78
+ stub_post(url)
79
+ .to_return(
80
+ body: '{"success": "OK"}',
81
+ headers: { content_type: "application/json" }
82
+ )
83
+ end
84
+
85
+ it "resends all invites" do
86
+ subject.resend_all_invites
87
+ expect(a_post(url)).to have_been_made
88
+ end
89
+ end
90
+
91
+ describe "#resend_invite" do
92
+ let(:url) { "#{host}/invites/reinvite" }
93
+
94
+ before do
95
+ stub_post(url)
96
+ .to_return(
97
+ body: '{"success": "OK"}',
98
+ headers: { content_type: "application/json" }
99
+ )
100
+ end
101
+
102
+ it "resends invite" do
103
+ subject.resend_invite("foo@bar.com")
104
+ expect(a_post(url)).to have_been_made
105
+ end
106
+ end
107
+
108
+ describe "#destroy_invite" do
109
+ let(:url) { "#{host}/invites?id=27" }
110
+
111
+ before do
112
+ stub_delete(url).to_return(
113
+ body: '{"success": "OK"}',
114
+ headers: { content_type: "application/json" }
115
+ )
116
+ end
117
+
118
+ it "destroys the invite" do
119
+ subject.destroy_invite(27)
120
+ expect(a_delete(url)).to have_been_made
121
+ end
122
+ end
123
+ end
@@ -36,19 +36,19 @@ describe DiscourseApi::API::PrivateMessages do
36
36
  end
37
37
  end
38
38
 
39
- describe '#create_private_message' do
39
+ describe '#create_pm' do
40
40
  before do
41
41
  stub_post("#{host}/posts")
42
- subject.create_private_message(
42
+ subject.create_pm(
43
43
  title: "Confidential: Hello World!",
44
44
  raw: "This is the raw markdown for my private message",
45
- target_usernames: "user1,user2"
45
+ target_recipients: "user1,user2"
46
46
  )
47
47
  end
48
48
 
49
49
  it "makes a create private message request" do
50
50
  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')
52
52
  ).to have_been_made
53
53
  end
54
54
  end
@@ -25,6 +25,11 @@ describe DiscourseApi::API::Topics do
25
25
  expect(a_post("#{host}/t/12/invite")).to have_been_made
26
26
  end
27
27
 
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
+
28
33
  it "returns success" do
29
34
  response = subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
30
35
  expect(response).to be_a Hash
@@ -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
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.46.0
4
+ version: 0.47.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-04-12 00:00:00.000000000 Z
14
+ date: 2021-07-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faraday
@@ -260,6 +260,7 @@ files:
260
260
  - spec/discourse_api/api/categories_spec.rb
261
261
  - spec/discourse_api/api/email_spec.rb
262
262
  - spec/discourse_api/api/groups_spec.rb
263
+ - spec/discourse_api/api/invite_spec.rb
263
264
  - spec/discourse_api/api/notifications_spec.rb
264
265
  - spec/discourse_api/api/params_spec.rb
265
266
  - spec/discourse_api/api/polls_spec.rb
@@ -305,6 +306,7 @@ files:
305
306
  - spec/fixtures/regenerate_api_key.json
306
307
  - spec/fixtures/replies.json
307
308
  - spec/fixtures/replies_and_topics.json
309
+ - spec/fixtures/retrieve_invite.json
308
310
  - spec/fixtures/search.json
309
311
  - spec/fixtures/top.json
310
312
  - spec/fixtures/topic.json
@@ -356,6 +358,7 @@ test_files:
356
358
  - spec/discourse_api/api/categories_spec.rb
357
359
  - spec/discourse_api/api/email_spec.rb
358
360
  - spec/discourse_api/api/groups_spec.rb
361
+ - spec/discourse_api/api/invite_spec.rb
359
362
  - spec/discourse_api/api/notifications_spec.rb
360
363
  - spec/discourse_api/api/params_spec.rb
361
364
  - spec/discourse_api/api/polls_spec.rb
@@ -401,6 +404,7 @@ test_files:
401
404
  - spec/fixtures/regenerate_api_key.json
402
405
  - spec/fixtures/replies.json
403
406
  - spec/fixtures/replies_and_topics.json
407
+ - spec/fixtures/retrieve_invite.json
404
408
  - spec/fixtures/search.json
405
409
  - spec/fixtures/top.json
406
410
  - spec/fixtures/topic.json