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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +6 -6
- data/.rubocop.yml +3 -0
- data/.streerc +1 -1
- data/CHANGELOG.md +10 -0
- data/config_example.yml +1 -1
- data/discourse_api.gemspec +36 -31
- data/lib/discourse_api/api/categories.rb +45 -54
- data/lib/discourse_api/api/topics.rb +13 -1
- data/lib/discourse_api/api/users.rb +0 -4
- data/lib/discourse_api/single_sign_on.rb +3 -3
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +11 -11
- data/spec/discourse_api/api/backups_spec.rb +3 -3
- data/spec/discourse_api/api/badges_spec.rb +5 -5
- data/spec/discourse_api/api/categories_spec.rb +37 -15
- data/spec/discourse_api/api/email_spec.rb +5 -5
- data/spec/discourse_api/api/groups_spec.rb +17 -17
- data/spec/discourse_api/api/invite_spec.rb +11 -11
- data/spec/discourse_api/api/notifications_spec.rb +3 -3
- data/spec/discourse_api/api/polls_spec.rb +7 -7
- data/spec/discourse_api/api/posts_spec.rb +1 -3
- data/spec/discourse_api/api/private_messages_spec.rb +6 -6
- data/spec/discourse_api/api/search_spec.rb +5 -5
- data/spec/discourse_api/api/site_settings_spec.rb +2 -2
- data/spec/discourse_api/api/sso_spec.rb +3 -3
- data/spec/discourse_api/api/topics_spec.rb +32 -32
- data/spec/discourse_api/api/uploads_spec.rb +3 -3
- data/spec/discourse_api/api/user_actions_spec.rb +5 -5
- data/spec/discourse_api/api/users_spec.rb +51 -51
- data/spec/discourse_api/client_spec.rb +33 -33
- data/spec/discourse_api/single_sign_on_spec.rb +23 -6
- data/spec/spec_helper.rb +1 -0
- metadata +9 -26
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::Client do
|
|
5
|
-
subject { DiscourseApi::Client.new(host) }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new(host) }
|
|
6
6
|
|
|
7
7
|
describe ".new" do
|
|
8
8
|
it "requires a host argument" do
|
|
@@ -10,11 +10,11 @@ describe DiscourseApi::Client do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "defaults api key to nil" do
|
|
13
|
-
expect(
|
|
13
|
+
expect(client.api_key).to be_nil
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "defaults api username to nil" do
|
|
17
|
-
expect(
|
|
17
|
+
expect(client.api_username).to be_nil
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "accepts an api key argument" do
|
|
@@ -31,55 +31,55 @@ describe DiscourseApi::Client do
|
|
|
31
31
|
describe "#timeout" do
|
|
32
32
|
context "with a custom timeout" do
|
|
33
33
|
it "is set to Faraday connection" do
|
|
34
|
-
expect(
|
|
34
|
+
expect(client.send(:connection).options.timeout).to eq(30)
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
context "with the default timeout" do
|
|
39
39
|
it "is set to Faraday connection" do
|
|
40
|
-
|
|
41
|
-
expect(
|
|
40
|
+
client.timeout = 25
|
|
41
|
+
expect(client.send(:connection).options.timeout).to eq(25)
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "raises DiscourseApi::Timeout" do
|
|
46
46
|
stub_get("#{host}/t/1.json").to_timeout
|
|
47
47
|
|
|
48
|
-
expect {
|
|
48
|
+
expect { client.topic(1) }.to raise_error(DiscourseApi::Timeout)
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
describe "#api_key" do
|
|
53
53
|
it "is publicly accessible" do
|
|
54
|
-
|
|
55
|
-
expect(
|
|
54
|
+
client.api_key = "test_d7fd0429940"
|
|
55
|
+
expect(client.api_key).to eq("test_d7fd0429940")
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
describe "#api_username" do
|
|
60
60
|
it "is publicly accessible" do
|
|
61
|
-
|
|
62
|
-
expect(
|
|
61
|
+
client.api_username = "test_user"
|
|
62
|
+
expect(client.api_username).to eq("test_user")
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
describe "#host" do
|
|
67
67
|
it "is publicly readable" do
|
|
68
|
-
expect(
|
|
68
|
+
expect(client.host).to eq("#{host}")
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
it "is not publicly writeable" do
|
|
72
|
-
expect(
|
|
72
|
+
expect(client).not_to respond_to(:host=)
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
describe "#connection" do
|
|
77
77
|
it "looks like a Faraday connection" do
|
|
78
|
-
expect(
|
|
78
|
+
expect(client.send(:connection)).to respond_to :run_request
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "memorizes the connection" do
|
|
82
|
-
c1, c2 =
|
|
82
|
+
c1, c2 = client.send(:connection), client.send(:connection)
|
|
83
83
|
expect(c1.object_id).to eq(c2.object_id)
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -87,22 +87,22 @@ describe DiscourseApi::Client do
|
|
|
87
87
|
describe "#delete" do
|
|
88
88
|
before do
|
|
89
89
|
stub_delete("#{host}/test/delete").with(query: { deleted: "object" })
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
client.api_key = "test_d7fd0429940"
|
|
91
|
+
client.api_username = "test_user"
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
it "allows custom delete requests" do
|
|
95
|
-
|
|
95
|
+
client.delete("/test/delete", { deleted: "object" })
|
|
96
96
|
expect(a_delete("#{host}/test/delete").with(query: { deleted: "object" })).to have_been_made
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
context "when using a host with a subdirectory" do
|
|
100
|
-
subject { DiscourseApi::Client.new("#{host}/forum") }
|
|
100
|
+
subject(:client) { DiscourseApi::Client.new("#{host}/forum") }
|
|
101
101
|
|
|
102
102
|
before { stub_delete("#{host}/forum/test/delete").with(query: { deleted: "object" }) }
|
|
103
103
|
|
|
104
104
|
it "allows custom delete requests" do
|
|
105
|
-
|
|
105
|
+
client.delete("/test/delete", { deleted: "object" })
|
|
106
106
|
expect(
|
|
107
107
|
a_delete("#{host}/forum/test/delete").with(query: { deleted: "object" }),
|
|
108
108
|
).to have_been_made
|
|
@@ -113,22 +113,22 @@ describe DiscourseApi::Client do
|
|
|
113
113
|
describe "#post" do
|
|
114
114
|
before do
|
|
115
115
|
stub_post("#{host}/test/post").with(body: { created: "object" })
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
client.api_key = "test_d7fd0429940"
|
|
117
|
+
client.api_username = "test_user"
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it "allows custom post requests" do
|
|
121
|
-
|
|
121
|
+
client.post("/test/post", { created: "object" })
|
|
122
122
|
expect(a_post("#{host}/test/post").with(body: { created: "object" })).to have_been_made
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
context "when using a host with a subdirectory" do
|
|
126
|
-
subject { DiscourseApi::Client.new("#{host}/forum") }
|
|
126
|
+
subject(:client) { DiscourseApi::Client.new("#{host}/forum") }
|
|
127
127
|
|
|
128
128
|
before { stub_post("#{host}/forum/test/post").with(body: { created: "object" }) }
|
|
129
129
|
|
|
130
130
|
it "allows custom post requests" do
|
|
131
|
-
|
|
131
|
+
client.post("/test/post", { created: "object" })
|
|
132
132
|
expect(
|
|
133
133
|
a_post("#{host}/forum/test/post").with(body: { created: "object" }),
|
|
134
134
|
).to have_been_made
|
|
@@ -139,22 +139,22 @@ describe DiscourseApi::Client do
|
|
|
139
139
|
describe "#put" do
|
|
140
140
|
before do
|
|
141
141
|
stub_put("#{host}/test/put").with(body: { updated: "object" })
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
client.api_key = "test_d7fd0429940"
|
|
143
|
+
client.api_username = "test_user"
|
|
144
144
|
end
|
|
145
145
|
|
|
146
146
|
it "allows custom put requests" do
|
|
147
|
-
|
|
147
|
+
client.put("/test/put", { updated: "object" })
|
|
148
148
|
expect(a_put("#{host}/test/put").with(body: { updated: "object" })).to have_been_made
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
context "when using a host with a subdirectory" do
|
|
152
|
-
subject { DiscourseApi::Client.new("#{host}/forum") }
|
|
152
|
+
subject(:client) { DiscourseApi::Client.new("#{host}/forum") }
|
|
153
153
|
|
|
154
154
|
before { stub_put("#{host}/forum/test/put").with(body: { updated: "object" }) }
|
|
155
155
|
|
|
156
156
|
it "allows custom post requests" do
|
|
157
|
-
|
|
157
|
+
client.put("/test/put", { updated: "object" })
|
|
158
158
|
expect(a_put("#{host}/forum/test/put").with(body: { updated: "object" })).to have_been_made
|
|
159
159
|
end
|
|
160
160
|
end
|
|
@@ -167,17 +167,17 @@ describe DiscourseApi::Client do
|
|
|
167
167
|
OpenStruct.new(env: { body: "error page html" }, status: 500),
|
|
168
168
|
)
|
|
169
169
|
allow(Faraday).to receive(:new).and_return(connection)
|
|
170
|
-
expect {
|
|
170
|
+
expect { client.send(:request, :get, "/test") }.to raise_error DiscourseApi::Error
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
it "catches Faraday errors" do
|
|
174
174
|
allow(Faraday).to receive(:new).and_raise(Faraday::ClientError.new("BOOM!"))
|
|
175
|
-
expect {
|
|
175
|
+
expect { client.send(:request, :get, "/test") }.to raise_error DiscourseApi::Error
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
it "catches JSON::ParserError errors" do
|
|
179
179
|
allow(Faraday).to receive(:new).and_raise(JSON::ParserError.new("unexpected token"))
|
|
180
|
-
expect {
|
|
180
|
+
expect { client.send(:request, :get, "/test") }.to raise_error DiscourseApi::Error
|
|
181
181
|
end
|
|
182
182
|
end
|
|
183
183
|
end
|
|
@@ -32,12 +32,29 @@ describe DiscourseApi::SingleSignOn do
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
describe ".parse" do
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
context "when sso is present" do
|
|
36
|
+
it "raises ParseError when there's a signature mismatch" do
|
|
37
|
+
sso = described_class.new
|
|
38
|
+
sso.sso_secret = "abcd"
|
|
39
|
+
expect { described_class.parse(sso.payload, "dcba") }.to raise_error(
|
|
40
|
+
DiscourseApi::SingleSignOn::ParseError,
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when sso is missing" do
|
|
46
|
+
it "raises ParseError when there's a signature mismatch" do
|
|
47
|
+
sso = described_class.new
|
|
48
|
+
sso.sso_secret = "abcd"
|
|
49
|
+
missing_sso = Rack::Utils.parse_query(sso.payload)
|
|
50
|
+
missing_sso.delete("sso")
|
|
51
|
+
malformed_query = Rack::Utils.build_query(missing_sso)
|
|
52
|
+
|
|
53
|
+
expect { described_class.parse(malformed_query, "dcba") }.to raise_error(
|
|
54
|
+
DiscourseApi::SingleSignOn::ParseError,
|
|
55
|
+
/The SSO field should/i,
|
|
56
|
+
)
|
|
57
|
+
end
|
|
41
58
|
end
|
|
42
59
|
end
|
|
43
60
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: discourse_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Saffron
|
|
8
8
|
- John Paul Ashenfelter
|
|
9
9
|
- Michael Herold
|
|
10
10
|
- Blake Erickson
|
|
11
|
-
autorequire:
|
|
12
11
|
bindir: bin
|
|
13
12
|
cert_chain: []
|
|
14
|
-
date:
|
|
13
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
15
14
|
dependencies:
|
|
16
15
|
- !ruby/object:Gem::Dependency
|
|
17
16
|
name: faraday
|
|
@@ -185,44 +184,30 @@ dependencies:
|
|
|
185
184
|
name: rubocop-discourse
|
|
186
185
|
requirement: !ruby/object:Gem::Requirement
|
|
187
186
|
requirements:
|
|
188
|
-
- -
|
|
187
|
+
- - '='
|
|
189
188
|
- !ruby/object:Gem::Version
|
|
190
|
-
version: 3.
|
|
189
|
+
version: 3.8.1
|
|
191
190
|
type: :development
|
|
192
191
|
prerelease: false
|
|
193
192
|
version_requirements: !ruby/object:Gem::Requirement
|
|
194
193
|
requirements:
|
|
195
|
-
- -
|
|
194
|
+
- - '='
|
|
196
195
|
- !ruby/object:Gem::Version
|
|
197
|
-
version: 3.
|
|
196
|
+
version: 3.8.1
|
|
198
197
|
- !ruby/object:Gem::Dependency
|
|
199
198
|
name: syntax_tree
|
|
200
199
|
requirement: !ruby/object:Gem::Requirement
|
|
201
200
|
requirements:
|
|
202
201
|
- - "~>"
|
|
203
202
|
- !ruby/object:Gem::Version
|
|
204
|
-
version: 6.
|
|
205
|
-
type: :development
|
|
206
|
-
prerelease: false
|
|
207
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
208
|
-
requirements:
|
|
209
|
-
- - "~>"
|
|
210
|
-
- !ruby/object:Gem::Version
|
|
211
|
-
version: 6.1.1
|
|
212
|
-
- !ruby/object:Gem::Dependency
|
|
213
|
-
name: syntax_tree-disable_ternary
|
|
214
|
-
requirement: !ruby/object:Gem::Requirement
|
|
215
|
-
requirements:
|
|
216
|
-
- - "~>"
|
|
217
|
-
- !ruby/object:Gem::Version
|
|
218
|
-
version: 1.0.0
|
|
203
|
+
version: 6.2.0
|
|
219
204
|
type: :development
|
|
220
205
|
prerelease: false
|
|
221
206
|
version_requirements: !ruby/object:Gem::Requirement
|
|
222
207
|
requirements:
|
|
223
208
|
- - "~>"
|
|
224
209
|
- !ruby/object:Gem::Version
|
|
225
|
-
version:
|
|
210
|
+
version: 6.2.0
|
|
226
211
|
description: Discourse API
|
|
227
212
|
email:
|
|
228
213
|
- sam.saffron@gmail.com
|
|
@@ -376,7 +361,6 @@ homepage: http://github.com/discourse/discourse_api
|
|
|
376
361
|
licenses:
|
|
377
362
|
- MIT
|
|
378
363
|
metadata: {}
|
|
379
|
-
post_install_message:
|
|
380
364
|
rdoc_options: []
|
|
381
365
|
require_paths:
|
|
382
366
|
- lib
|
|
@@ -391,8 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
391
375
|
- !ruby/object:Gem::Version
|
|
392
376
|
version: '0'
|
|
393
377
|
requirements: []
|
|
394
|
-
rubygems_version: 3.
|
|
395
|
-
signing_key:
|
|
378
|
+
rubygems_version: 3.6.9
|
|
396
379
|
specification_version: 4
|
|
397
380
|
summary: Allows access to the Discourse API
|
|
398
381
|
test_files:
|