discourse_api 1.0.0 → 2.0.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +23 -10
  3. data/.rubocop.yml +1 -1
  4. data/.streerc +2 -0
  5. data/CHANGELOG.md +10 -0
  6. data/Gemfile +1 -1
  7. data/README.md +0 -4
  8. data/discourse_api.gemspec +7 -4
  9. data/examples/backups.rb +5 -5
  10. data/examples/badges.rb +5 -5
  11. data/examples/bookmark_topic.rb +5 -5
  12. data/examples/category.rb +10 -6
  13. data/examples/change_topic_status.rb +12 -11
  14. data/examples/create_private_message.rb +6 -6
  15. data/examples/create_topic.rb +9 -9
  16. data/examples/create_update_category.rb +13 -16
  17. data/examples/create_user.rb +12 -11
  18. data/examples/dashboard.rb +5 -5
  19. data/examples/disposable_invite_tokens.rb +9 -10
  20. data/examples/example.rb +5 -5
  21. data/examples/group_set_user_notification_level.rb +18 -19
  22. data/examples/groups.rb +7 -7
  23. data/examples/invite_users.rb +5 -5
  24. data/examples/manage_api_keys.rb +6 -11
  25. data/examples/notifications.rb +6 -6
  26. data/examples/polls.rb +12 -12
  27. data/examples/post_action.rb +5 -5
  28. data/examples/search.rb +5 -5
  29. data/examples/sent_private_messages.rb +6 -6
  30. data/examples/sso.rb +6 -6
  31. data/examples/topic_lists.rb +5 -5
  32. data/examples/update_user.rb +15 -7
  33. data/examples/upload_file.rb +7 -7
  34. data/lib/discourse_api/api/api_key.rb +1 -3
  35. data/lib/discourse_api/api/backups.rb +1 -1
  36. data/lib/discourse_api/api/badges.rb +21 -6
  37. data/lib/discourse_api/api/categories.rb +69 -37
  38. data/lib/discourse_api/api/dashboard.rb +2 -6
  39. data/lib/discourse_api/api/groups.rb +68 -73
  40. data/lib/discourse_api/api/invite.rb +30 -30
  41. data/lib/discourse_api/api/notifications.rb +2 -3
  42. data/lib/discourse_api/api/params.rb +4 -14
  43. data/lib/discourse_api/api/polls.rb +9 -12
  44. data/lib/discourse_api/api/posts.rb +5 -8
  45. data/lib/discourse_api/api/private_messages.rb +9 -8
  46. data/lib/discourse_api/api/search.rb +2 -2
  47. data/lib/discourse_api/api/topics.rb +20 -22
  48. data/lib/discourse_api/api/uploads.rb +7 -5
  49. data/lib/discourse_api/api/user_actions.rb +2 -2
  50. data/lib/discourse_api/api/users.rb +31 -19
  51. data/lib/discourse_api/client.rb +58 -56
  52. data/lib/discourse_api/example_helper.rb +2 -4
  53. data/lib/discourse_api/single_sign_on.rb +56 -57
  54. data/lib/discourse_api/version.rb +1 -1
  55. data/spec/discourse_api/api/api_key_spec.rb +39 -25
  56. data/spec/discourse_api/api/backups_spec.rb +8 -3
  57. data/spec/discourse_api/api/badges_spec.rb +17 -7
  58. data/spec/discourse_api/api/categories_spec.rb +95 -53
  59. data/spec/discourse_api/api/email_spec.rb +17 -7
  60. data/spec/discourse_api/api/groups_spec.rb +71 -52
  61. data/spec/discourse_api/api/invite_spec.rb +41 -21
  62. data/spec/discourse_api/api/notifications_spec.rb +8 -4
  63. data/spec/discourse_api/api/params_spec.rb +5 -3
  64. data/spec/discourse_api/api/polls_spec.rb +53 -44
  65. data/spec/discourse_api/api/posts_spec.rb +33 -16
  66. data/spec/discourse_api/api/private_messages_spec.rb +25 -12
  67. data/spec/discourse_api/api/search_spec.rb +8 -3
  68. data/spec/discourse_api/api/site_settings_spec.rb +2 -3
  69. data/spec/discourse_api/api/sso_spec.rb +29 -25
  70. data/spec/discourse_api/api/topics_spec.rb +100 -31
  71. data/spec/discourse_api/api/uploads_spec.rb +16 -7
  72. data/spec/discourse_api/api/user_actions_spec.rb +13 -3
  73. data/spec/discourse_api/api/users_spec.rb +137 -55
  74. data/spec/discourse_api/client_spec.rb +32 -32
  75. data/spec/discourse_api/single_sign_on_spec.rb +43 -0
  76. data/spec/fixtures/categories.json +1 -1
  77. data/spec/spec_helper.rb +10 -15
  78. metadata +57 -12
@@ -1,23 +1,33 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Topics do
5
5
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#change_topic_status" do
8
8
  before do
9
- stub_put("#{host}/t/57/status").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
9
+ stub_put("#{host}/t/57/status").to_return(
10
+ body: fixture("topic.json"),
11
+ headers: {
12
+ content_type: "application/json",
13
+ },
14
+ )
10
15
  end
11
16
 
12
17
  it "changes the topic status" do
13
- subject.update_topic_status(57, { status: 'visible', enabled: false })
18
+ subject.update_topic_status(57, { status: "visible", enabled: false })
14
19
  expect(a_put("#{host}/t/57/status")).to have_been_made
15
20
  end
16
21
  end
17
22
 
18
23
  describe "#invite_to_topic" do
19
24
  before do
20
- stub_post("#{host}/t/12/invite").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
25
+ stub_post("#{host}/t/12/invite").to_return(
26
+ body: fixture("topic_invite_user.json"),
27
+ headers: {
28
+ content_type: "application/json",
29
+ },
30
+ )
21
31
  end
22
32
 
23
33
  it "requests the correct resource" do
@@ -28,13 +38,18 @@ describe DiscourseApi::API::Topics do
28
38
  it "returns success" do
29
39
  response = subject.invite_to_topic(12, email: "fake_user@example.com")
30
40
  expect(response).to be_a Hash
31
- expect(response['success']).to be_truthy
41
+ expect(response["success"]).to be_truthy
32
42
  end
33
43
  end
34
44
 
35
45
  describe "#latest_topics" do
36
46
  before do
37
- stub_get("#{host}/latest.json").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
47
+ stub_get("#{host}/latest.json").to_return(
48
+ body: fixture("latest.json"),
49
+ headers: {
50
+ content_type: "application/json",
51
+ },
52
+ )
38
53
  end
39
54
 
40
55
  it "requests the correct resource" do
@@ -57,7 +72,12 @@ describe DiscourseApi::API::Topics do
57
72
 
58
73
  describe "#top_topics" do
59
74
  before do
60
- stub_get("#{host}/top.json").to_return(body: fixture("top.json"), headers: { content_type: "application/json" })
75
+ stub_get("#{host}/top.json").to_return(
76
+ body: fixture("top.json"),
77
+ headers: {
78
+ content_type: "application/json",
79
+ },
80
+ )
61
81
  end
62
82
 
63
83
  it "requests the correct resource" do
@@ -80,7 +100,12 @@ describe DiscourseApi::API::Topics do
80
100
 
81
101
  describe "#new_topics" do
82
102
  before do
83
- stub_get("#{host}/new.json").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
103
+ stub_get("#{host}/new.json").to_return(
104
+ body: fixture("new.json"),
105
+ headers: {
106
+ content_type: "application/json",
107
+ },
108
+ )
84
109
  end
85
110
 
86
111
  it "requests the correct resource" do
@@ -89,7 +114,7 @@ describe DiscourseApi::API::Topics do
89
114
  end
90
115
 
91
116
  it "returns the requested topics" do
92
- subject.api_username = 'test_user'
117
+ subject.api_username = "test_user"
93
118
  topics = subject.new_topics
94
119
  expect(topics).to be_an Array
95
120
  expect(topics.first).to be_a Hash
@@ -98,7 +123,12 @@ describe DiscourseApi::API::Topics do
98
123
 
99
124
  describe "#topic" do
100
125
  before do
101
- stub_get("#{host}/t/57.json").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
126
+ stub_get("#{host}/t/57.json").to_return(
127
+ body: fixture("topic.json"),
128
+ headers: {
129
+ content_type: "application/json",
130
+ },
131
+ )
102
132
  end
103
133
 
104
134
  it "requests the correct resource" do
@@ -115,7 +145,12 @@ describe DiscourseApi::API::Topics do
115
145
 
116
146
  describe "#update_topic" do
117
147
  before do
118
- stub_put("#{host}/t/57.json").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
148
+ stub_put("#{host}/t/57.json").to_return(
149
+ body: fixture("topic.json"),
150
+ headers: {
151
+ content_type: "application/json",
152
+ },
153
+ )
119
154
  end
120
155
 
121
156
  it "renames the topic" do
@@ -131,16 +166,21 @@ describe DiscourseApi::API::Topics do
131
166
 
132
167
  describe "#topics_by" do
133
168
  before do
134
- stub_get("#{host}/topics/created-by/test.json").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
169
+ stub_get("#{host}/topics/created-by/test.json").to_return(
170
+ body: fixture("topics_created_by.json"),
171
+ headers: {
172
+ content_type: "application/json",
173
+ },
174
+ )
135
175
  end
136
176
 
137
177
  it "requests the correct resource" do
138
- subject.topics_by('test')
178
+ subject.topics_by("test")
139
179
  expect(a_get("#{host}/topics/created-by/test.json")).to have_been_made
140
180
  end
141
181
 
142
182
  it "returns the requested topics" do
143
- topics = subject.topics_by('test')
183
+ topics = subject.topics_by("test")
144
184
  expect(topics).to be_an Array
145
185
  expect(topics.first).to be_a Hash
146
186
  end
@@ -148,9 +188,11 @@ describe DiscourseApi::API::Topics do
148
188
 
149
189
  describe "#topic_posts" do
150
190
  before do
151
- stub_get(/#{host}\/t\/57\/posts\.json/).to_return(
191
+ stub_get(%r{#{host}/t/57/posts\.json}).to_return(
152
192
  body: fixture("topic_posts.json"),
153
- headers: { content_type: "application/json" }
193
+ headers: {
194
+ content_type: "application/json",
195
+ },
154
196
  )
155
197
  end
156
198
 
@@ -159,7 +201,7 @@ describe DiscourseApi::API::Topics do
159
201
  expect(a_get("#{host}/t/57/posts.json")).to have_been_made
160
202
  end
161
203
 
162
- it 'allows scoping to specific post ids' do
204
+ it "allows scoping to specific post ids" do
163
205
  subject.topic_posts(57, [123, 456])
164
206
  expect(a_get("#{host}/t/57/posts.json?post_ids[]=123&post_ids[]=456")).to have_been_made
165
207
  end
@@ -167,51 +209,73 @@ describe DiscourseApi::API::Topics do
167
209
  it "returns the requested topic posts" do
168
210
  body = subject.topic_posts(57, [123])
169
211
  expect(body).to be_a Hash
170
- expect(body['post_stream']['posts']).to be_an Array
171
- expect(body['post_stream']['posts'].first).to be_a Hash
212
+ expect(body["post_stream"]["posts"]).to be_an Array
213
+ expect(body["post_stream"]["posts"].first).to be_a Hash
172
214
  end
173
215
 
174
216
  it "can retrieve a topic posts' raw attribute" do
175
217
  body = subject.topic_posts(57, [123], { include_raw: true })
176
218
  expect(body).to be_a Hash
177
- expect(body['post_stream']['posts']).to be_an Array
178
- expect(body['post_stream']['posts'].first).to be_a Hash
179
- expect(body['post_stream']['posts'].first['raw']).to be_an Array
219
+ expect(body["post_stream"]["posts"]).to be_an Array
220
+ expect(body["post_stream"]["posts"].first).to be_a Hash
221
+ expect(body["post_stream"]["posts"].first["raw"]).to be_an Array
180
222
  end
181
223
  end
182
224
 
183
225
  describe "#create_topic_with_tags" do
184
226
  before do
185
- stub_post("#{host}/posts").to_return(body: fixture("create_topic_with_tags.json"), headers: { content_type: "application/json" })
227
+ stub_post("#{host}/posts").to_return(
228
+ body: fixture("create_topic_with_tags.json"),
229
+ headers: {
230
+ content_type: "application/json",
231
+ },
232
+ )
186
233
  end
187
234
 
188
235
  it "makes the post request" do
189
- subject.create_topic title: "Sample Topic Title", raw: "Sample topic content body", tags: ["asdf", "fdsa"]
236
+ subject.create_topic title: "Sample Topic Title",
237
+ raw: "Sample topic content body",
238
+ tags: %w[asdf fdsa]
190
239
  expect(a_post("#{host}/posts")).to have_been_made
191
240
  end
192
241
 
193
242
  it "returns success" do
194
- response = subject.create_topic title: "Sample Topic Title", raw: "Sample topic content body", tags: ["asdf", "fdsa"]
243
+ response =
244
+ subject.create_topic title: "Sample Topic Title",
245
+ raw: "Sample topic content body",
246
+ tags: %w[asdf fdsa]
195
247
  expect(response).to be_a Hash
196
- expect(response['topic_id']).to eq 21
248
+ expect(response["topic_id"]).to eq 21
197
249
  end
198
250
  end
199
251
 
200
252
  describe "#topic_set_user_notification_level" do
201
253
  before do
202
- stub_post("#{host}/t/1/notifications").to_return(body: fixture("notification_success.json"), headers: { content_type: "application/json" })
254
+ stub_post("#{host}/t/1/notifications").to_return(
255
+ body: fixture("notification_success.json"),
256
+ headers: {
257
+ content_type: "application/json",
258
+ },
259
+ )
203
260
  end
204
261
 
205
262
  it "makes the post request" do
206
263
  response = subject.topic_set_user_notification_level(1, notification_level: 3)
207
- expect(a_post("#{host}/t/1/notifications").with(body: "notification_level=3")).to have_been_made
208
- expect(response['success']).to eq('OK')
264
+ expect(
265
+ a_post("#{host}/t/1/notifications").with(body: "notification_level=3"),
266
+ ).to have_been_made
267
+ expect(response["success"]).to eq("OK")
209
268
  end
210
269
  end
211
270
 
212
271
  describe "#bookmark_topic" do
213
272
  before do
214
- stub_put("#{host}/t/1/bookmark.json").to_return(body: "", headers: { content_type: "application/json" })
273
+ stub_put("#{host}/t/1/bookmark.json").to_return(
274
+ body: "",
275
+ headers: {
276
+ content_type: "application/json",
277
+ },
278
+ )
215
279
  end
216
280
 
217
281
  it "makes the put request" do
@@ -223,7 +287,12 @@ describe DiscourseApi::API::Topics do
223
287
 
224
288
  describe "#remove_topic_bookmark" do
225
289
  before do
226
- stub_put("#{host}/t/1/remove_bookmarks.json").to_return(body: "", headers: { content_type: "application/json" })
290
+ stub_put("#{host}/t/1/remove_bookmarks.json").to_return(
291
+ body: "",
292
+ headers: {
293
+ content_type: "application/json",
294
+ },
295
+ )
227
296
  end
228
297
 
229
298
  it "makes the put request" do
@@ -1,27 +1,36 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::Uploads do
5
5
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#upload_file" do
8
8
  before do
9
- stub_post("#{host}/uploads").to_return(body: fixture("upload_file.json"), headers: { content_type: "application/json" })
9
+ stub_post("#{host}/uploads").to_return(
10
+ body: fixture("upload_file.json"),
11
+ headers: {
12
+ content_type: "application/json",
13
+ },
14
+ )
10
15
  end
11
16
 
12
17
  it "uploads an image via URL" do
13
- image = "https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
18
+ image =
19
+ "https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
14
20
  args = { url: image }
15
21
  response = subject.upload_file(args)
16
- expect(response["url"]).to eq("/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg")
22
+ expect(response["url"]).to eq(
23
+ "/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg",
24
+ )
17
25
  end
18
26
 
19
27
  it "uploads a file" do
20
- file = Faraday::UploadIO.new('spec/fixtures/upload_file.json', "application/json")
28
+ file = Faraday::UploadIO.new("spec/fixtures/upload_file.json", "application/json")
21
29
  args = { file: file }
22
30
  response = subject.upload_file(args)
23
- expect(response["url"]).to eq("/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg")
31
+ expect(response["url"]).to eq(
32
+ "/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg",
33
+ )
24
34
  end
25
-
26
35
  end
27
36
  end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  describe DiscourseApi::API::UserActions do
5
5
  subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6
6
 
7
7
  describe "#user_replies" do
8
8
  before do
9
- stub_get("#{host}/user_actions.json?username=testuser&filter=5").to_return(body: fixture("replies.json"), headers: { content_type: "application/json" })
9
+ stub_get("#{host}/user_actions.json?username=testuser&filter=5").to_return(
10
+ body: fixture("replies.json"),
11
+ headers: {
12
+ content_type: "application/json",
13
+ },
14
+ )
10
15
  end
11
16
 
12
17
  it "requests the correct resource" do
@@ -22,7 +27,12 @@ describe DiscourseApi::API::UserActions do
22
27
 
23
28
  describe "#user_topics_and_replies" do
24
29
  before do
25
- stub_get("#{host}/user_actions.json?username=testuser&filter=4,5").to_return(body: fixture("replies_and_topics.json"), headers: { content_type: "application/json" })
30
+ stub_get("#{host}/user_actions.json?username=testuser&filter=4,5").to_return(
31
+ body: fixture("replies_and_topics.json"),
32
+ headers: {
33
+ content_type: "application/json",
34
+ },
35
+ )
26
36
  end
27
37
 
28
38
  it "requests the correct resource" do