discourse_api 0.46.0 → 0.48.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83d6fc91bd7fd472cc3eab0fa06b79d0fbaa5e4cf7a2003bef82eee43f33acf4
4
- data.tar.gz: c0aef1ea4eee35c3cf3143d100707c2850829e5551c79af3a6d6f76efb3b262c
3
+ metadata.gz: 80a9809c17206520d47904326a0f42571ffdfccf5af07fee84e517bf52af81bc
4
+ data.tar.gz: 0d7f9a78732e3a084f272ae4cc1e5c35de8dc938a6326d0f08d052ac38163248
5
5
  SHA512:
6
- metadata.gz: 4227051151b05bd67b403a9922d0199b4cdaf84ccf5973e4be57fb63af8345053b0d80ca763aa2a9c49c27a1a73a623540bde643a714710298c57e73c4a3a0d3
7
- data.tar.gz: 5a6dfdc85bf1db5edb7e474ecfa1df038a617ebb4d3bf890611d6e195e3093d441e2dbdb3826ad468cc397e6de420f4d4d295b275ad0febb78fb32ae86dfec8e
6
+ metadata.gz: 3c6b7abab4c2c7febbe201a2dba4698930d327f77343e4eefec1261a4e87004b8957d4dcb06ee9d94caf57b56b8a8a12c908d292832a252912a898ccc44d96ca
7
+ data.tar.gz: 9b7490943e570a12cca7a6c69998c4eba8d2fdd06df8e301a5cbc1444524238a7372becd8c58bb6b0c4ee8f7e8323056ebc682994bbaaae9784f18f2705f03d4
data/CHANGELOG.md CHANGED
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.48.1] - 2022-04-13
10
+ ### Added
11
+ - New attributes for Discourse Connect (aka SSO)
12
+
13
+ ## [0.48.0] - 2022-01-28
14
+ ### Added
15
+ - `group_add_owners` method (#239)
16
+ - `group_remove_owners` method (#239)
17
+ - `anonymize` method (#241)
18
+
19
+ ### Changed
20
+ - `DiscourseApi::Timeout` error now inherits from `DiscourseApi::Error` (#240)
21
+ - `DiscourseApi::SingleSignOn#groups` now returns an array of strings where each string is a group name, rather than an array with a single string that contains all the groups comma-concatenated (#243)
22
+
23
+ ## [0.47.0] - 2021-07-19
24
+ ### Added
25
+ - Update invite method
26
+ - Retrieve invite method
27
+ - Destroy all expired invites method
28
+ - Destroy invite method
29
+ - Resend all invites method
30
+ - Resend invite method
31
+ - Pass params to get notifications API
32
+
33
+ ### Deprecated
34
+ - `invite_user_to_topic` has been deprecated, use `invite_to_topic` instead.
35
+ - `create_private_message` has been deprecated, use `create_pm` instead.
36
+
9
37
  ## [0.46.0] - 2021-04-12
10
38
  ### Added
11
39
  - 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
- client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
21
+ client.invite_to_topic(1, email: "foo@bar.com")
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_to_topic(1, email: "foo@bar.com", group_ids: "1,2,3")
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')
@@ -14,10 +14,10 @@ module DiscourseApi
14
14
  topics = global_reports[3]
15
15
  posts = global_reports[4]
16
16
 
17
- totals = {
17
+ {
18
18
  'users' => users['total'],
19
19
  'topics' => topics['total'],
20
- 'posts' => posts['total']
20
+ 'posts' => posts['total'],
21
21
  }
22
22
  end
23
23
  end
@@ -38,7 +38,6 @@ module DiscourseApi
38
38
  :messageable_level,
39
39
  :name,
40
40
  :automatic_membership_email_domains,
41
- :automatic_membership_retroactive,
42
41
  :title,
43
42
  :primary_group,
44
43
  :grant_trust_level,
@@ -47,19 +46,31 @@ module DiscourseApi
47
46
  :flair_bg_color,
48
47
  :flair_color,
49
48
  :bio_raw,
50
- :members_visibility_level,
49
+ :visibility_level,
51
50
  :public_admission,
52
51
  :public_exit,
53
52
  :allow_membership_requests,
54
53
  :full_name,
55
54
  :default_notification_level,
56
- :usernames,
57
- :owner_usernames,
58
55
  :membership_request_template)
59
56
  .to_h
60
57
  put("/groups/#{group_id}", group: args)
61
58
  end
62
59
 
60
+ def group_add_owners(group_id, args)
61
+ args = API.params(args)
62
+ .required(:usernames)
63
+ .to_h
64
+ put("/admin/groups/#{group_id}/owners.json", group: args)
65
+ end
66
+
67
+ def group_remove_owners(group_id, args)
68
+ args = API.params(args)
69
+ .required(:usernames)
70
+ .to_h
71
+ delete("/admin/groups/#{group_id}/owners.json", group: args)
72
+ end
73
+
63
74
  def groups(args = {})
64
75
  params = API.params(args)
65
76
  .optional(:page)
@@ -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
@@ -3,10 +3,10 @@ module DiscourseApi
3
3
  module API
4
4
  module SiteSettings
5
5
  def site_setting_update(args = {})
6
- params = API.params(args)
7
- .required(:name, :value).to_h
6
+ params = API.params(args).required(:name, :value).to_h
8
7
  new_site_setting = { params[:name] => params[:value] }
9
- response = put("/admin/site_settings/#{params[:name]}", new_site_setting)
8
+
9
+ put("/admin/site_settings/#{params[:name]}", new_site_setting)
10
10
  end
11
11
  end
12
12
  end
@@ -102,6 +102,10 @@ module DiscourseApi
102
102
  put("/admin/users/#{user_id}/unsuspend")
103
103
  end
104
104
 
105
+ def anonymize(user_id)
106
+ put("/admin/users/#{user_id}/anonymize")
107
+ end
108
+
105
109
  def delete_user(user_id, delete_posts = false)
106
110
  delete("/admin/users/#{user_id}.json?delete_posts=#{delete_posts}")
107
111
  end
@@ -34,6 +34,6 @@ module DiscourseApi
34
34
  class TooManyRequests < DiscourseError
35
35
  end
36
36
 
37
- class Timeout < DiscourseError
37
+ class Timeout < Error
38
38
  end
39
39
  end
@@ -5,18 +5,51 @@ require 'openssl'
5
5
 
6
6
  module DiscourseApi
7
7
  class SingleSignOn
8
- ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :profile_background_url, :card_background_url, :avatar_force_update, :require_activation,
9
- :bio, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message, :title,
10
- :add_groups, :remove_groups, :groups, :locale, :locale_force_update]
8
+ ACCESSORS = [
9
+ :add_groups,
10
+ :admin,
11
+ :avatar_force_update,
12
+ :avatar_url,
13
+ :bio,
14
+ :card_background_url,
15
+ :confirmed_2fa,
16
+ :email,
17
+ :external_id,
18
+ :groups,
19
+ :locale,
20
+ :locale_force_update,
21
+ :moderator,
22
+ :name,
23
+ :no_2fa_methods,
24
+ :nonce,
25
+ :profile_background_url,
26
+ :remove_groups,
27
+ :require_2fa,
28
+ :require_activation,
29
+ :return_sso_url,
30
+ :suppress_welcome_message,
31
+ :title,
32
+ :username,
33
+ ]
34
+
11
35
  FIXNUMS = []
12
- BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation, :suppress_welcome_message,
13
- :locale_force_update]
36
+
37
+ BOOLS = [
38
+ :admin,
39
+ :avatar_force_update,
40
+ :confirmed_2fa,
41
+ :locale_force_update,
42
+ :moderator,
43
+ :no_2fa_methods,
44
+ :require_2fa,
45
+ :require_activation,
46
+ :suppress_welcome_message,
47
+ ]
14
48
  ARRAYS = [:groups]
15
49
  #NONCE_EXPIRY_TIME = 10.minutes # minutes is a rails method and is causing an error. Is this needed in the api?
16
50
 
17
51
  attr_accessor(*ACCESSORS)
18
- attr_accessor :custom_fields
19
- attr_writer :sso_secret, :sso_url
52
+ attr_writer :custom_fields, :sso_secret, :sso_url
20
53
 
21
54
  def self.sso_secret
22
55
  raise RuntimeError, "sso_secret not implemented on class, be sure to set it on instance"
@@ -27,7 +60,6 @@ module DiscourseApi
27
60
  end
28
61
 
29
62
  def self.parse_hash(payload)
30
- payload
31
63
  sso = new
32
64
 
33
65
  sso.sso_secret = payload.delete(:sso_secret)
@@ -40,11 +72,13 @@ module DiscourseApi
40
72
  if BOOLS.include? k
41
73
  val = ["true", "false"].include?(val) ? val == "true" : nil
42
74
  end
43
- val = Array(val) if ARRAYS.include?(k) && !val.nil?
75
+ val = val.split(",") if ARRAYS.include?(k) && !val.nil?
44
76
  sso.send("#{k}=", val)
45
77
  end
78
+
46
79
  # Set custom_fields
47
80
  sso.custom_fields = payload[:custom_fields]
81
+
48
82
  # Add custom_fields (old format)
49
83
  payload.each do |k, v|
50
84
  if field = k[/^custom\.(.+)$/, 1]
@@ -79,7 +113,7 @@ module DiscourseApi
79
113
  if BOOLS.include? k
80
114
  val = ["true", "false"].include?(val) ? val == "true" : nil
81
115
  end
82
- val = Array(val) if ARRAYS.include?(k) && !val.nil?
116
+ val = val.split(",") if ARRAYS.include?(k) && !val.nil?
83
117
  sso.send("#{k}=", val)
84
118
  end
85
119
 
@@ -127,7 +161,7 @@ module DiscourseApi
127
161
 
128
162
  ACCESSORS.each do |k|
129
163
  next if (val = send k) == nil
130
- payload[k] = val
164
+ payload[k] = val
131
165
  end
132
166
 
133
167
  if @custom_fields
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseApi
3
- VERSION = "0.46.0"
3
+ VERSION = "0.48.1"
4
4
  end
@@ -91,6 +91,35 @@ describe DiscourseApi::API::Groups do
91
91
  end
92
92
  end
93
93
 
94
+ describe "add owners" do
95
+ let(:url) { "#{host}/admin/groups/123/owners.json" }
96
+
97
+ before do
98
+ stub_put(url)
99
+ end
100
+
101
+ it "makes the member an owner" do
102
+ subject.group_add_owners(123, usernames: "sam")
103
+ params = escape_params("group[usernames]" => "sam")
104
+ expect(a_request(:put, "#{host}/admin/groups/123/owners.json").
105
+ with(body: params)
106
+ ).to have_been_made
107
+ end
108
+ end
109
+
110
+ describe "remove owners" do
111
+ let(:url) { "#{host}/admin/groups/123/owners.json?group%5Busernames%5D=sam" }
112
+
113
+ before do
114
+ stub_delete(url)
115
+ end
116
+
117
+ it "removes the owner role from the group member" do
118
+ subject.group_remove_owners(123, usernames: "sam")
119
+ expect(a_delete(url)).to have_been_made
120
+ end
121
+ end
122
+
94
123
  describe "group members" do
95
124
  it "list members" do
96
125
  stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
@@ -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
@@ -27,10 +27,10 @@ describe DiscourseApi::API::SSO do
27
27
  }
28
28
  end
29
29
  let(:expected_unsigned_payload) do
30
- 'name=Some+User&username=some_user&email=some%40email.com&'\
31
- 'avatar_url=https%3A%2F%2Fwww.website.com&external_id=abc&title=ruby'\
32
- '&add_groups=a&add_groups=b&remove_groups=c&remove_groups=d&custom.field_2=potato&'\
33
- 'custom.custom.field_1=tomato'
30
+ 'add_groups=a&add_groups=b&avatar_url=https%3A%2F%2Fwww.website.com'\
31
+ '&email=some%40email.com&external_id=abc&name=Some+User&remove_groups=c'\
32
+ '&remove_groups=d&title=ruby&username=some_user&custom.field_2=potato'\
33
+ '&custom.custom.field_1=tomato'
34
34
  end
35
35
  let(:sso_double) { DiscourseApi::SingleSignOn.parse_hash(params) }
36
36
 
@@ -15,18 +15,18 @@ describe DiscourseApi::API::Topics do
15
15
  end
16
16
  end
17
17
 
18
- describe "#invite_user_to_topic" do
18
+ describe "#invite_to_topic" do
19
19
  before do
20
20
  stub_post("#{host}/t/12/invite").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
21
21
  end
22
22
 
23
23
  it "requests the correct resource" do
24
- subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
24
+ subject.invite_to_topic(12, email: "fake_user@example.com")
25
25
  expect(a_post("#{host}/t/12/invite")).to have_been_made
26
26
  end
27
27
 
28
28
  it "returns success" do
29
- response = subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
29
+ response = subject.invite_to_topic(12, email: "fake_user@example.com")
30
30
  expect(response).to be_a Hash
31
31
  expect(response['success']).to be_truthy
32
32
  end
@@ -306,6 +306,20 @@ describe DiscourseApi::API::Users do
306
306
  end
307
307
  end
308
308
 
309
+ describe "#anonymize" do
310
+ before do
311
+ url = "#{host}/admin/users/11/anonymize"
312
+ stub_put(url).to_return(body: '', status: 200)
313
+ end
314
+
315
+ it "makes the correct put request" do
316
+ result = subject.anonymize(11)
317
+ url = "#{host}/admin/users/11/anonymize"
318
+ expect(a_put(url)).to have_been_made
319
+ expect(result.status).to eq(200)
320
+ end
321
+ end
322
+
309
323
  describe "#delete_user" do
310
324
  before do
311
325
  url = "#{host}/admin/users/11.json?delete_posts=true"
@@ -41,6 +41,12 @@ describe DiscourseApi::Client do
41
41
  expect(subject.send(:connection).options.timeout).to eq(25)
42
42
  end
43
43
  end
44
+
45
+ it "raises DiscourseApi::Timeout" do
46
+ stub_get("#{host}/t/1.json").to_timeout
47
+
48
+ expect { subject.topic(1) }.to raise_error(DiscourseApi::Timeout)
49
+ end
44
50
  end
45
51
 
46
52
  describe "#api_key" do
@@ -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.48.1
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: 2022-04-13 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