discourse_api 2.0.0 → 2.1.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +6 -6
  3. data/.rubocop.yml +3 -0
  4. data/.streerc +1 -1
  5. data/CHANGELOG.md +10 -0
  6. data/config_example.yml +1 -1
  7. data/discourse_api.gemspec +36 -31
  8. data/lib/discourse_api/api/categories.rb +45 -54
  9. data/lib/discourse_api/api/topics.rb +13 -1
  10. data/lib/discourse_api/api/users.rb +0 -4
  11. data/lib/discourse_api/single_sign_on.rb +3 -3
  12. data/lib/discourse_api/version.rb +1 -1
  13. data/spec/discourse_api/api/api_key_spec.rb +11 -11
  14. data/spec/discourse_api/api/backups_spec.rb +3 -3
  15. data/spec/discourse_api/api/badges_spec.rb +5 -5
  16. data/spec/discourse_api/api/categories_spec.rb +37 -15
  17. data/spec/discourse_api/api/email_spec.rb +5 -5
  18. data/spec/discourse_api/api/groups_spec.rb +17 -17
  19. data/spec/discourse_api/api/invite_spec.rb +11 -11
  20. data/spec/discourse_api/api/notifications_spec.rb +3 -3
  21. data/spec/discourse_api/api/polls_spec.rb +7 -7
  22. data/spec/discourse_api/api/posts_spec.rb +1 -3
  23. data/spec/discourse_api/api/private_messages_spec.rb +6 -6
  24. data/spec/discourse_api/api/search_spec.rb +5 -5
  25. data/spec/discourse_api/api/site_settings_spec.rb +2 -2
  26. data/spec/discourse_api/api/sso_spec.rb +3 -3
  27. data/spec/discourse_api/api/topics_spec.rb +32 -32
  28. data/spec/discourse_api/api/uploads_spec.rb +3 -3
  29. data/spec/discourse_api/api/user_actions_spec.rb +5 -5
  30. data/spec/discourse_api/api/users_spec.rb +51 -51
  31. data/spec/discourse_api/client_spec.rb +33 -33
  32. data/spec/discourse_api/single_sign_on_spec.rb +23 -6
  33. data/spec/spec_helper.rb +1 -0
  34. metadata +9 -26
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Email do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#email_settings" do
8
8
  before do
@@ -15,12 +15,12 @@ describe DiscourseApi::API::Email do
15
15
  end
16
16
 
17
17
  it "requests the correct resource" do
18
- subject.email_settings
18
+ client.email_settings
19
19
  expect(a_get("#{host}/admin/email.json")).to have_been_made
20
20
  end
21
21
 
22
22
  it "returns the requested settings" do
23
- settings = subject.email_settings
23
+ settings = client.email_settings
24
24
  expect(settings).to be_a Hash
25
25
  expect(settings).to have_key("delivery_method")
26
26
  expect(settings).to have_key("settings")
@@ -38,12 +38,12 @@ describe DiscourseApi::API::Email do
38
38
  end
39
39
 
40
40
  it "requests the correct resource" do
41
- subject.list_email("all")
41
+ client.list_email("all")
42
42
  expect(a_get("#{host}/admin/email/all.json")).to have_been_made
43
43
  end
44
44
 
45
45
  it "returns all email" do
46
- all_email = subject.list_email("all")
46
+ all_email = client.list_email("all")
47
47
  expect(all_email).to be_an Array
48
48
  end
49
49
  end
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Groups do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#groups" do
8
8
  before do
@@ -15,12 +15,12 @@ describe DiscourseApi::API::Groups do
15
15
  end
16
16
 
17
17
  it "requests the correct resource" do
18
- subject.groups
18
+ client.groups
19
19
  expect(a_get("#{host}/groups.json")).to have_been_made
20
20
  end
21
21
 
22
22
  it "returns the requested groups" do
23
- groups = subject.groups
23
+ groups = client.groups
24
24
  expect(groups).to be_an Array
25
25
  groups.each { |g| expect(g).to be_a Hash }
26
26
  end
@@ -32,20 +32,20 @@ describe DiscourseApi::API::Groups do
32
32
  content_type: "application/json",
33
33
  },
34
34
  )
35
- group = subject.group("some-group")
35
+ group = client.group("some-group")
36
36
  expect(group["basic_group"]).to be_a Hash
37
37
  end
38
38
 
39
39
  it "create new groups" do
40
40
  stub_post("#{host}/admin/groups")
41
- subject.create_group(name: "test_group")
41
+ client.create_group(name: "test_group")
42
42
  params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
43
43
  expect(a_post("#{host}/admin/groups").with(body: params)).to have_been_made
44
44
  end
45
45
 
46
46
  it "update an existing group" do
47
47
  stub_put("#{host}/groups/42")
48
- subject.update_group(42, name: "test_group")
48
+ client.update_group(42, name: "test_group")
49
49
  params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
50
50
  expect(a_put("#{host}/groups/42").with(body: params)).to have_been_made
51
51
  end
@@ -54,14 +54,14 @@ describe DiscourseApi::API::Groups do
54
54
  before { stub_request(:put, "#{host}/admin/groups/123/members.json") }
55
55
 
56
56
  it "adds a single member by username" do
57
- subject.group_add(123, username: "sam")
57
+ client.group_add(123, username: "sam")
58
58
  expect(
59
59
  a_request(:put, "#{host}/admin/groups/123/members.json").with(body: { usernames: "sam" }),
60
60
  ).to have_been_made
61
61
  end
62
62
 
63
63
  it "adds an array of members by username" do
64
- subject.group_add(123, usernames: %w[sam jeff])
64
+ client.group_add(123, usernames: %w[sam jeff])
65
65
  expect(
66
66
  a_request(:put, "#{host}/admin/groups/123/members.json").with(
67
67
  body: {
@@ -72,14 +72,14 @@ describe DiscourseApi::API::Groups do
72
72
  end
73
73
 
74
74
  it "adds a single member by user_id" do
75
- subject.group_add(123, user_id: 456)
75
+ client.group_add(123, user_id: 456)
76
76
  expect(
77
77
  a_request(:put, "#{host}/admin/groups/123/members.json").with(body: { user_ids: "456" }),
78
78
  ).to have_been_made
79
79
  end
80
80
 
81
81
  it "adds an array of members by user_id" do
82
- subject.group_add(123, user_id: [123, 456])
82
+ client.group_add(123, user_id: [123, 456])
83
83
  expect(
84
84
  a_request(:put, "#{host}/admin/groups/123/members.json").with(
85
85
  body: {
@@ -96,7 +96,7 @@ describe DiscourseApi::API::Groups do
96
96
  before { stub_delete(url) }
97
97
 
98
98
  it "removes member" do
99
- subject.group_remove(123, username: "sam")
99
+ client.group_remove(123, username: "sam")
100
100
  expect(a_delete(url)).to have_been_made
101
101
  end
102
102
  end
@@ -107,7 +107,7 @@ describe DiscourseApi::API::Groups do
107
107
  before { stub_put(url) }
108
108
 
109
109
  it "makes the member an owner" do
110
- subject.group_add_owners(123, usernames: "sam")
110
+ client.group_add_owners(123, usernames: "sam")
111
111
  params = escape_params("group[usernames]" => "sam")
112
112
  expect(
113
113
  a_request(:put, "#{host}/admin/groups/123/owners.json").with(body: params),
@@ -121,7 +121,7 @@ describe DiscourseApi::API::Groups do
121
121
  before { stub_delete(url) }
122
122
 
123
123
  it "removes the owner role from the group member" do
124
- subject.group_remove_owners(123, usernames: "sam")
124
+ client.group_remove_owners(123, usernames: "sam")
125
125
  expect(a_delete(url)).to have_been_made
126
126
  end
127
127
  end
@@ -140,10 +140,10 @@ describe DiscourseApi::API::Groups do
140
140
  content_type: "application/json",
141
141
  },
142
142
  )
143
- members = subject.group_members("mygroup")
143
+ members = client.group_members("mygroup")
144
144
  expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
145
145
  expect(members.length).to eq(100)
146
- members = subject.group_members("mygroup", offset: 100)
146
+ members = client.group_members("mygroup", offset: 100)
147
147
  expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=100")).to have_been_made
148
148
  expect(members.length).to eq(90)
149
149
  end
@@ -156,7 +156,7 @@ describe DiscourseApi::API::Groups do
156
156
  content_type: "application/json",
157
157
  },
158
158
  )
159
- member_data = subject.group_members("mygroup", all: true)
159
+ member_data = client.group_members("mygroup", all: true)
160
160
  expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
161
161
  expect(member_data["members"].length).to eq(100)
162
162
  expect(member_data["owners"].length).to eq(7)
@@ -169,7 +169,7 @@ describe DiscourseApi::API::Groups do
169
169
  before { stub_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3") }
170
170
 
171
171
  it "updates user's notification level for group" do
172
- subject.group_set_user_notification_level("mygroup", 77, 3)
172
+ client.group_set_user_notification_level("mygroup", 77, 3)
173
173
  expect(
174
174
  a_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3"),
175
175
  ).to have_been_made
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Invite do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#invite_user" do
8
8
  before do
@@ -15,12 +15,12 @@ describe DiscourseApi::API::Invite do
15
15
  end
16
16
 
17
17
  it "requests the correct resource" do
18
- subject.invite_user(email: "fake_user@example.com", group_ids: "41,42")
18
+ client.invite_user(email: "fake_user@example.com", group_ids: "41,42")
19
19
  expect(a_post("#{host}/invites")).to have_been_made
20
20
  end
21
21
 
22
22
  it "returns success" do
23
- response = subject.invite_user(email: "fake_user@example.com", group_ids: "41,42")
23
+ response = client.invite_user(email: "fake_user@example.com", group_ids: "41,42")
24
24
  expect(response).to be_a Hash
25
25
  expect(response["success"]).to be_truthy
26
26
  end
@@ -37,7 +37,7 @@ describe DiscourseApi::API::Invite do
37
37
  end
38
38
 
39
39
  it "updates invite" do
40
- subject.update_invite(27, email: "namee@example.com")
40
+ client.update_invite(27, email: "namee@example.com")
41
41
  expect(a_put("#{host}/invites/27")).to have_been_made
42
42
  end
43
43
  end
@@ -53,17 +53,17 @@ describe DiscourseApi::API::Invite do
53
53
  end
54
54
 
55
55
  it "requests the correct resource" do
56
- subject.retrieve_invite(email: "foo@bar.com")
56
+ client.retrieve_invite(email: "foo@bar.com")
57
57
  expect(a_get("#{host}/invites/retrieve.json?email=foo@bar.com")).to have_been_made
58
58
  end
59
59
 
60
60
  it "returns the requested topics" do
61
- invites = subject.retrieve_invite(email: "foo@bar.com")
61
+ invites = client.retrieve_invite(email: "foo@bar.com")
62
62
  expect(invites).to be_an Hash
63
63
  end
64
64
 
65
65
  it "returns the requested invite" do
66
- invites = subject.retrieve_invite(email: "foo@bar.com")
66
+ invites = client.retrieve_invite(email: "foo@bar.com")
67
67
  expect(invites["email"]).to eq("foo@bar.com")
68
68
  expect(invites).to have_key("invite_key")
69
69
  end
@@ -82,7 +82,7 @@ describe DiscourseApi::API::Invite do
82
82
  end
83
83
 
84
84
  it "destroys all expired invites" do
85
- subject.destroy_all_expired_invites
85
+ client.destroy_all_expired_invites
86
86
  expect(a_post(url)).to have_been_made
87
87
  end
88
88
  end
@@ -100,7 +100,7 @@ describe DiscourseApi::API::Invite do
100
100
  end
101
101
 
102
102
  it "resends all invites" do
103
- subject.resend_all_invites
103
+ client.resend_all_invites
104
104
  expect(a_post(url)).to have_been_made
105
105
  end
106
106
  end
@@ -118,7 +118,7 @@ describe DiscourseApi::API::Invite do
118
118
  end
119
119
 
120
120
  it "resends invite" do
121
- subject.resend_invite("foo@bar.com")
121
+ client.resend_invite("foo@bar.com")
122
122
  expect(a_post(url)).to have_been_made
123
123
  end
124
124
  end
@@ -136,7 +136,7 @@ describe DiscourseApi::API::Invite do
136
136
  end
137
137
 
138
138
  it "destroys the invite" do
139
- subject.destroy_invite(27)
139
+ client.destroy_invite(27)
140
140
  expect(a_delete(url)).to have_been_made
141
141
  end
142
142
  end
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Notifications do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#notifications" do
8
8
  before do
@@ -15,12 +15,12 @@ describe DiscourseApi::API::Notifications do
15
15
  end
16
16
 
17
17
  it "requests the correct resource" do
18
- subject.notifications
18
+ client.notifications
19
19
  expect(a_get("#{host}/notifications.json")).to have_been_made
20
20
  end
21
21
 
22
22
  it "returns the requested notifications" do
23
- notifications = subject.notifications
23
+ notifications = client.notifications
24
24
  expect(notifications).to be_an Array
25
25
  expect(notifications.first).to be_an Hash
26
26
  expect(notifications[0]["notification_type"]).to eq(9)
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Polls do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#poll vote" do
8
8
  before do
@@ -17,13 +17,13 @@ describe DiscourseApi::API::Polls do
17
17
 
18
18
  it "requests the correct resource" do
19
19
  options = ["8b4736b1ae3dfb5a28088530f036f9e5"]
20
- subject.poll_vote post_id: 5, poll_name: "poll", options: options
20
+ client.poll_vote post_id: 5, poll_name: "poll", options: options
21
21
  expect(a_put("#{host}/polls/vote")).to have_been_made
22
22
  end
23
23
 
24
24
  it "returns the expected votes" do
25
25
  options = ["8b4736b1ae3dfb5a28088530f036f9e5"]
26
- vote = subject.poll_vote post_id: 5, poll_name: "poll", options: options
26
+ vote = client.poll_vote post_id: 5, poll_name: "poll", options: options
27
27
  expect(vote.body).to be_a Hash
28
28
  expect(vote.body["poll"]["options"]).to be_an Array
29
29
  expect(vote.body["vote"]).to eq(["8b4736b1ae3dfb5a28088530f036f9e5"])
@@ -41,13 +41,13 @@ describe DiscourseApi::API::Polls do
41
41
  end
42
42
 
43
43
  it "toggles the poll status to closed" do
44
- subject.toggle_poll_status post_id: 5, poll_name: "poll", status: "closed"
44
+ client.toggle_poll_status post_id: 5, poll_name: "poll", status: "closed"
45
45
  expect(a_put("#{host}/polls/toggle_status")).to have_been_made
46
46
  end
47
47
 
48
48
  it "returns the expected results of closed poll" do
49
49
  returned_poll_status =
50
- subject.toggle_poll_status post_id: 5, poll_name: "poll", status: "closed"
50
+ client.toggle_poll_status post_id: 5, poll_name: "poll", status: "closed"
51
51
  expect(returned_poll_status.body).to be_a Hash
52
52
  returned_poll_status.body["poll"]["options"].each { |g| expect(g).to be_a Hash }
53
53
  end
@@ -64,12 +64,12 @@ describe DiscourseApi::API::Polls do
64
64
  end
65
65
 
66
66
  it "requests the correct resource" do
67
- subject.poll_voters post_id: 5, poll_name: "poll"
67
+ client.poll_voters post_id: 5, poll_name: "poll"
68
68
  expect(a_get("#{host}/polls/voters.json?post_id=5&poll_name=poll")).to have_been_made
69
69
  end
70
70
 
71
71
  it "returns the expected votes" do
72
- voters = subject.poll_voters post_id: 5, poll_name: "poll"
72
+ voters = client.poll_voters post_id: 5, poll_name: "poll"
73
73
  expect(voters).to be_a Hash
74
74
  voters.each { |g| expect(g).to be_an Array }
75
75
  expect(voters["voters"]["e539a9df8700d0d05c69356a07b768cf"]).to be_an Array
@@ -2,9 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Posts do
5
- let (:client) {
6
- DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user")
7
- }
5
+ let(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
8
6
 
9
7
  describe "#get_post" do
10
8
  before do
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::PrivateMessages do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#private_messages" do
8
8
  before do
@@ -15,12 +15,12 @@ describe DiscourseApi::API::PrivateMessages do
15
15
  end
16
16
 
17
17
  it "requests the correct resource" do
18
- subject.private_messages("test_user")
18
+ client.private_messages("test_user")
19
19
  expect(a_get("#{host}/topics/private-messages/test_user.json")).to have_been_made
20
20
  end
21
21
 
22
22
  it "returns the requested private messages" do
23
- private_messages = subject.private_messages("test_user")
23
+ private_messages = client.private_messages("test_user")
24
24
  expect(private_messages).to be_an Array
25
25
  end
26
26
  end
@@ -36,12 +36,12 @@ describe DiscourseApi::API::PrivateMessages do
36
36
  end
37
37
 
38
38
  it "requests the correct resource" do
39
- subject.sent_private_messages("test_user")
39
+ client.sent_private_messages("test_user")
40
40
  expect(a_get("#{host}/topics/private-messages-sent/test_user.json")).to have_been_made
41
41
  end
42
42
 
43
43
  it "returns the requested sent private messages" do
44
- private_messages = subject.sent_private_messages("test_user")
44
+ private_messages = client.sent_private_messages("test_user")
45
45
  expect(private_messages).to be_an Array
46
46
  end
47
47
  end
@@ -49,7 +49,7 @@ describe DiscourseApi::API::PrivateMessages do
49
49
  describe "#create_pm" do
50
50
  before do
51
51
  stub_post("#{host}/posts")
52
- subject.create_pm(
52
+ client.create_pm(
53
53
  title: "Confidential: Hello World!",
54
54
  raw: "This is the raw markdown for my private message",
55
55
  target_recipients: "user1,user2",
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Search do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#search" do
8
8
  before do
@@ -15,22 +15,22 @@ describe DiscourseApi::API::Search do
15
15
  end
16
16
 
17
17
  it "requests the correct resource" do
18
- subject.search("test")
18
+ client.search("test")
19
19
  expect(a_get("#{host}/search").with(query: { q: "test" })).to have_been_made
20
20
  end
21
21
 
22
22
  it "returns the requested search" do
23
- results = subject.search("test")
23
+ results = client.search("test")
24
24
  expect(results).to be_an Array
25
25
  expect(results.first).to be_a Hash
26
26
  end
27
27
 
28
28
  it "raises an ArgumentError for nil" do
29
- expect { subject.search(nil) }.to raise_error(ArgumentError)
29
+ expect { client.search(nil) }.to raise_error(ArgumentError)
30
30
  end
31
31
 
32
32
  it "raises an ArgumentError for empty string" do
33
- expect { subject.search("") }.to raise_error(ArgumentError)
33
+ expect { client.search("") }.to raise_error(ArgumentError)
34
34
  end
35
35
  end
36
36
  end
@@ -2,12 +2,12 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::SiteSettings do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#site_setting_update" do
8
8
  before do
9
9
  stub_put("#{host}/admin/site_settings/foo")
10
- subject.site_setting_update(name: "foo", value: "bar")
10
+ client.site_setting_update(name: "foo", value: "bar")
11
11
  end
12
12
 
13
13
  it "makes a site_settings_update request" do
@@ -2,7 +2,7 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::SSO do
5
- subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
5
+ subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  let(:params) do
8
8
  {
@@ -47,7 +47,7 @@ describe DiscourseApi::API::SSO do
47
47
  it "assigns params to sso instance" do
48
48
  allow(DiscourseApi::SingleSignOn).to(receive(:parse_hash).with(params).and_return(sso_double))
49
49
 
50
- subject.sync_sso(params)
50
+ client.sync_sso(params)
51
51
 
52
52
  expect(sso_double.custom_fields).to eql(
53
53
  { "custom.field_1" => "tomato", :field_2 => "potato" },
@@ -56,7 +56,7 @@ describe DiscourseApi::API::SSO do
56
56
  end
57
57
 
58
58
  it "requests the correct resource" do
59
- subject.sync_sso({ :sso_secret => "test_d7fd0429940", "custom.riffle_url" => "test" })
59
+ client.sync_sso({ :sso_secret => "test_d7fd0429940", "custom.riffle_url" => "test" })
60
60
  expect(a_post(/.*sync_sso.*/)).to have_been_made
61
61
  end
62
62
  end