discourse_api 0.39.3 → 0.43.1
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 +4 -4
- data/.github/workflows/ci.yml +54 -0
- data/.gitignore +0 -2
- data/.rubocop.yml +2 -6
- data/CHANGELOG.md +40 -8
- data/README.md +13 -2
- data/discourse_api.gemspec +4 -6
- data/examples/change_topic_status.rb +3 -4
- data/examples/create_topic.rb +10 -0
- data/lib/discourse_api/api/api_key.rb +0 -8
- data/lib/discourse_api/api/categories.rb +5 -0
- data/lib/discourse_api/api/groups.rb +10 -2
- data/lib/discourse_api/api/sso.rb +1 -15
- data/lib/discourse_api/api/topics.rb +8 -2
- data/lib/discourse_api/client.rb +20 -4
- data/lib/discourse_api/single_sign_on.rb +32 -3
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +2 -28
- data/spec/discourse_api/api/backups_spec.rb +2 -1
- data/spec/discourse_api/api/badges_spec.rb +2 -1
- data/spec/discourse_api/api/categories_spec.rb +9 -8
- data/spec/discourse_api/api/email_spec.rb +2 -1
- data/spec/discourse_api/api/groups_spec.rb +7 -6
- data/spec/discourse_api/api/notifications_spec.rb +1 -0
- data/spec/discourse_api/api/params_spec.rb +8 -7
- data/spec/discourse_api/api/polls_spec.rb +7 -6
- data/spec/discourse_api/api/posts_spec.rb +1 -0
- data/spec/discourse_api/api/private_messages_spec.rb +1 -0
- data/spec/discourse_api/api/search_spec.rb +4 -3
- data/spec/discourse_api/api/site_settings_spec.rb +2 -1
- data/spec/discourse_api/api/sso_spec.rb +46 -3
- data/spec/discourse_api/api/topics_spec.rb +20 -1
- data/spec/discourse_api/api/uploads_spec.rb +1 -0
- data/spec/discourse_api/api/user_actions_spec.rb +1 -0
- data/spec/discourse_api/api/users_spec.rb +4 -3
- data/spec/discourse_api/client_spec.rb +11 -10
- data/spec/fixtures/create_topic_with_tags.json +65 -0
- data/spec/spec_helper.rb +2 -1
- metadata +17 -45
- data/.travis.yml +0 -11
- data/spec/fixtures/generate_api_key.json +0 -12
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::ApiKey do
|
@@ -30,33 +31,6 @@ describe DiscourseApi::API::ApiKey do
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
describe "#generate_user_api_key" do
|
34
|
-
before do
|
35
|
-
url = "#{host}/admin/users/2/generate_api_key.json"
|
36
|
-
stub_post(url).to_return(body: fixture("generate_api_key.json"),
|
37
|
-
headers: { content_type: "application/json" })
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns the generated api key" do
|
41
|
-
api_key = subject.generate_user_api_key(2)
|
42
|
-
expect(api_key).to be_a Hash
|
43
|
-
expect(api_key['api_key']).to have_key('key')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#revoke_user_api_key" do
|
48
|
-
before do
|
49
|
-
url = "#{host}/admin/users/2/revoke_api_key.json"
|
50
|
-
stub_delete(url).to_return(body: "",
|
51
|
-
headers: { content_type: "application/json" })
|
52
|
-
end
|
53
|
-
|
54
|
-
it "returns 200" do
|
55
|
-
response = subject.revoke_user_api_key(2)
|
56
|
-
expect(response['status']).to eq(200)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
34
|
describe "#generate_master_key" do
|
61
35
|
before do
|
62
36
|
url = "#{host}/admin/api/key"
|
@@ -95,7 +69,7 @@ describe DiscourseApi::API::ApiKey do
|
|
95
69
|
before do
|
96
70
|
url = "#{host}/admin/api/key"
|
97
71
|
stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
|
98
|
-
|
72
|
+
headers: { content_type: "application/json" })
|
99
73
|
end
|
100
74
|
|
101
75
|
it "requests the correct resource" do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Backups do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#backups" do
|
7
8
|
before do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Badges do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#badges" do
|
7
8
|
before do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Categories do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#categories" do
|
7
8
|
before do
|
@@ -42,8 +43,8 @@ describe DiscourseApi::API::Categories do
|
|
42
43
|
describe '#category_top_topics' do
|
43
44
|
before do
|
44
45
|
stub_get("#{host}/c/category-slug/l/top.json")
|
45
|
-
|
46
|
-
body: fixture("category_topics.json"),
|
46
|
+
.to_return(
|
47
|
+
body: fixture("category_topics.json"),
|
47
48
|
headers: { content_type: "application/json" }
|
48
49
|
)
|
49
50
|
end
|
@@ -57,8 +58,8 @@ describe DiscourseApi::API::Categories do
|
|
57
58
|
describe '#category_new_topics' do
|
58
59
|
before do
|
59
60
|
stub_get("#{host}/c/category-slug/l/new.json")
|
60
|
-
|
61
|
-
body: fixture("category_topics.json"),
|
61
|
+
.to_return(
|
62
|
+
body: fixture("category_topics.json"),
|
62
63
|
headers: { content_type: "application/json" }
|
63
64
|
)
|
64
65
|
end
|
@@ -74,14 +75,14 @@ describe DiscourseApi::API::Categories do
|
|
74
75
|
stub_post("#{host}/categories")
|
75
76
|
subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
|
76
77
|
description: "This is a description",
|
77
|
-
permissions: {"group_1" => 1, "admins" => 1})
|
78
|
+
permissions: { "group_1" => 1, "admins" => 1 })
|
78
79
|
end
|
79
|
-
|
80
|
+
|
80
81
|
it "makes a create category request" do
|
81
82
|
expect(a_post("#{host}/categories").with(body:
|
82
83
|
"color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF")
|
83
84
|
).to have_been_made
|
84
85
|
end
|
85
|
-
end
|
86
|
+
end
|
86
87
|
|
87
88
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Email do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#email_settings" do
|
7
8
|
before do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Groups do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#groups" do
|
7
8
|
before do
|
@@ -51,28 +52,28 @@ describe DiscourseApi::API::Groups do
|
|
51
52
|
it "adds a single member by username" do
|
52
53
|
subject.group_add(123, username: "sam")
|
53
54
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
54
|
-
with(body: {usernames: "sam"})
|
55
|
+
with(body: { usernames: "sam" })
|
55
56
|
).to have_been_made
|
56
57
|
end
|
57
58
|
|
58
59
|
it "adds an array of members by username" do
|
59
60
|
subject.group_add(123, usernames: ["sam", "jeff"])
|
60
61
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
61
|
-
with(body: {usernames: "sam,jeff"})
|
62
|
+
with(body: { usernames: "sam,jeff" })
|
62
63
|
).to have_been_made
|
63
64
|
end
|
64
65
|
|
65
66
|
it "adds a single member by user_id" do
|
66
67
|
subject.group_add(123, user_id: 456)
|
67
68
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
68
|
-
with(body: {user_ids: "456"})
|
69
|
+
with(body: { user_ids: "456" })
|
69
70
|
).to have_been_made
|
70
71
|
end
|
71
72
|
|
72
73
|
it "adds an array of members by user_id" do
|
73
74
|
subject.group_add(123, user_id: [123, 456])
|
74
75
|
expect(a_request(:put, "#{host}/admin/groups/123/members.json").
|
75
|
-
with(body: {user_ids: "123,456"})
|
76
|
+
with(body: { user_ids: "123,456" })
|
76
77
|
).to have_been_made
|
77
78
|
end
|
78
79
|
end
|
@@ -122,7 +123,7 @@ describe DiscourseApi::API::Groups do
|
|
122
123
|
it "updates user's notification level for group" do
|
123
124
|
subject.group_set_user_notification_level("mygroup", 77, 3)
|
124
125
|
expect(a_post("#{host}/groups/mygroup/notifications?user_id=77¬ification_level=3"))
|
125
|
-
|
126
|
+
.to have_been_made
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Params do
|
@@ -6,31 +7,31 @@ describe DiscourseApi::API::Params do
|
|
6
7
|
end
|
7
8
|
|
8
9
|
it "should raise on missing required params" do
|
9
|
-
expect { params_for({o1: "test"}).to_h }.to raise_error(ArgumentError)
|
10
|
+
expect { params_for({ o1: "test" }).to_h }.to raise_error(ArgumentError)
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should not raise when a required param is false" do
|
13
|
-
expect { params_for({r1: false}).to_h }.not_to raise_error
|
14
|
+
expect { params_for({ r1: false }).to_h }.not_to raise_error
|
14
15
|
end
|
15
16
|
|
16
17
|
it "should not include optional params when not provided" do
|
17
|
-
expect(params_for({r1: "test"}).to_h).not_to include(:o1)
|
18
|
+
expect(params_for({ r1: "test" }).to_h).not_to include(:o1)
|
18
19
|
end
|
19
20
|
|
20
21
|
it "should include optional params if provided but blank" do
|
21
|
-
expect(params_for({r1: "test", o2: nil}).to_h).to include(:o2)
|
22
|
+
expect(params_for({ r1: "test", o2: nil }).to_h).to include(:o2)
|
22
23
|
end
|
23
24
|
|
24
25
|
it "should include default params when defined but not provided" do
|
25
|
-
expect(params_for({r1: "test"}).to_h).to include(d1: "default")
|
26
|
+
expect(params_for({ r1: "test" }).to_h).to include(d1: "default")
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should include default params when defined and provided" do
|
29
|
-
expect(params_for({r1: "test", d1: "override"}).to_h).to include(d1: "override")
|
30
|
+
expect(params_for({ r1: "test", d1: "override" }).to_h).to include(d1: "override")
|
30
31
|
end
|
31
32
|
|
32
33
|
it "should include optional and default params when defined and provided" do
|
33
|
-
expect(params_for({r1: "test", o1: "optional", d1: "override"}).to_h).to include(o1: "optional", d1: "override")
|
34
|
+
expect(params_for({ r1: "test", o1: "optional", d1: "override" }).to_h).to include(o1: "optional", d1: "override")
|
34
35
|
end
|
35
36
|
|
36
37
|
end
|
@@ -1,14 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Polls do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#poll vote" do
|
7
8
|
before do
|
8
9
|
path = "#{host}/polls/vote"
|
9
10
|
stub_put(path)
|
10
|
-
|
11
|
-
|
11
|
+
.to_return(body: fixture("polls_vote.json"), headers: { content_type: "application/json" })
|
12
|
+
|
12
13
|
end
|
13
14
|
|
14
15
|
it "requests the correct resource" do
|
@@ -29,7 +30,7 @@ describe DiscourseApi::API::Polls do
|
|
29
30
|
before do
|
30
31
|
path = "#{host}/polls/toggle_status"
|
31
32
|
stub_put(path)
|
32
|
-
|
33
|
+
.to_return(body: fixture("polls_toggle_status.json"), headers: { content_type: "application/json" })
|
33
34
|
|
34
35
|
end
|
35
36
|
|
@@ -49,7 +50,7 @@ describe DiscourseApi::API::Polls do
|
|
49
50
|
describe "#poll voters" do
|
50
51
|
before do
|
51
52
|
stub_get("#{host}/polls/voters.json?post_id=5&poll_name=poll")
|
52
|
-
|
53
|
+
.to_return(body: fixture("polls_voters.json"), headers: { content_type: "application/json" })
|
53
54
|
end
|
54
55
|
|
55
56
|
it "requests the correct resource" do
|
@@ -64,7 +65,7 @@ describe DiscourseApi::API::Polls do
|
|
64
65
|
expect(voters['voters']['e539a9df8700d0d05c69356a07b768cf']).to be_an Array
|
65
66
|
expect(voters['voters']['e539a9df8700d0d05c69356a07b768cf'][0]['id']).to eq(356)
|
66
67
|
end
|
67
|
-
|
68
|
+
end
|
68
69
|
|
69
70
|
end
|
70
71
|
end
|
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Search do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#search" do
|
7
8
|
before do
|
8
|
-
stub_get("#{host}/search/query").with(query: { term: "test"}
|
9
|
+
stub_get("#{host}/search/query").with(query: { term: "test" }).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
|
9
10
|
end
|
10
11
|
|
11
12
|
it "requests the correct resource" do
|
12
13
|
subject.search("test")
|
13
|
-
expect(a_get("#{host}/search/query").with(query: { term: "test"}
|
14
|
+
expect(a_get("#{host}/search/query").with(query: { term: "test" })).to have_been_made
|
14
15
|
end
|
15
16
|
|
16
17
|
it "returns the requested search" do
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::SiteSettings do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
5
6
|
|
6
7
|
describe "#site_setting_update" do
|
7
8
|
before do
|
@@ -1,15 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::SSO do
|
4
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user"
|
5
|
+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
6
|
+
|
7
|
+
let(:params) do
|
8
|
+
{
|
9
|
+
sso_secret: 'abc',
|
10
|
+
sso_url: 'www.google.com',
|
11
|
+
name: 'Some User',
|
12
|
+
username: 'some_user',
|
13
|
+
email: 'some@email.com',
|
14
|
+
external_id: 'abc',
|
15
|
+
suppress_welcome_message: false,
|
16
|
+
avatar_url: 'https://www.website.com',
|
17
|
+
title: 'ruby',
|
18
|
+
avatar_force_update: false,
|
19
|
+
add_groups: ['a', 'b'],
|
20
|
+
remove_groups: ['c', 'd'],
|
21
|
+
# old format (which results in custom.custom.field_1 in unsigned_payload)
|
22
|
+
'custom.field_1' => 'tomato',
|
23
|
+
# new format
|
24
|
+
custom_fields: {
|
25
|
+
field_2: 'potato'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
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'
|
34
|
+
end
|
35
|
+
let(:sso_double) { DiscourseApi::SingleSignOn.parse_hash(params) }
|
5
36
|
|
6
37
|
describe "#sync_sso" do
|
7
38
|
before do
|
8
|
-
stub_post(/.*sync_sso.*/).to_return(
|
39
|
+
stub_post(/.*sync_sso.*/).to_return(
|
40
|
+
body: fixture("user.json"),
|
41
|
+
headers: { content_type: "application/json" }
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'assigns params to sso instance' do
|
46
|
+
allow(DiscourseApi::SingleSignOn).to(receive(:parse_hash).with(params).and_return(sso_double))
|
47
|
+
|
48
|
+
subject.sync_sso(params)
|
49
|
+
|
50
|
+
expect(sso_double.custom_fields).to eql({ 'custom.field_1' => 'tomato', :field_2 => 'potato' })
|
51
|
+
expect(sso_double.unsigned_payload).to eql(expected_unsigned_payload)
|
9
52
|
end
|
10
53
|
|
11
54
|
it "requests the correct resource" do
|
12
|
-
subject.sync_sso({sso_secret: "test_d7fd0429940", "custom.riffle_url" => "test"})
|
55
|
+
subject.sync_sso({ sso_secret: "test_d7fd0429940", "custom.riffle_url" => "test" })
|
13
56
|
expect(a_post(/.*sync_sso.*/)).to have_been_made
|
14
57
|
end
|
15
58
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Topics do
|
@@ -9,7 +10,7 @@ describe DiscourseApi::API::Topics do
|
|
9
10
|
end
|
10
11
|
|
11
12
|
it "changes the topic status" do
|
12
|
-
subject.
|
13
|
+
subject.update_topic_status(57, { status: 'visible', enabled: false })
|
13
14
|
expect(a_put("#{host}/t/57/status")).to have_been_made
|
14
15
|
end
|
15
16
|
end
|
@@ -147,4 +148,22 @@ describe DiscourseApi::API::Topics do
|
|
147
148
|
expect(body['post_stream']['posts'].first).to be_a Hash
|
148
149
|
end
|
149
150
|
end
|
151
|
+
|
152
|
+
describe "#create_topic_with_tags" do
|
153
|
+
before do
|
154
|
+
stub_post("#{host}/posts").to_return(body: fixture("create_topic_with_tags.json"), headers: { content_type: "application/json" })
|
155
|
+
end
|
156
|
+
|
157
|
+
it "makes the post request" do
|
158
|
+
subject.create_topic title: "Sample Topic Title", raw: "Sample topic content body", tags: ["asdf", "fdsa"]
|
159
|
+
expect(a_post("#{host}/posts")).to have_been_made
|
160
|
+
end
|
161
|
+
|
162
|
+
it "returns success" do
|
163
|
+
response = subject.create_topic title: "Sample Topic Title", raw: "Sample topic content body", tags: ["asdf", "fdsa"]
|
164
|
+
expect(response).to be_a Hash
|
165
|
+
expect(response['topic_id']).to eq 21
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
150
169
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe DiscourseApi::API::Users do
|
@@ -113,12 +114,12 @@ describe DiscourseApi::API::Users do
|
|
113
114
|
end
|
114
115
|
|
115
116
|
it "makes the post request" do
|
116
|
-
subject.create_user :
|
117
|
+
subject.create_user name: "Test User", email: "test2@example.com", password: "P@ssword", username: "test2"
|
117
118
|
expect(a_post("#{host}/users")).to have_been_made
|
118
119
|
end
|
119
120
|
|
120
121
|
it "returns success" do
|
121
|
-
response = subject.create_user :
|
122
|
+
response = subject.create_user name: "Test User", email: "test2@example.com", password: "P@ssword", username: "test2"
|
122
123
|
expect(response).to be_a Hash
|
123
124
|
expect(response['success']).to be_truthy
|
124
125
|
end
|
@@ -163,7 +164,7 @@ describe DiscourseApi::API::Users do
|
|
163
164
|
end
|
164
165
|
|
165
166
|
it "Raises API Error" do
|
166
|
-
expect{subject.log_out(90)}.to raise_error DiscourseApi::NotFoundError
|
167
|
+
expect { subject.log_out(90) }.to raise_error DiscourseApi::NotFoundError
|
167
168
|
end
|
168
169
|
end
|
169
170
|
|