discourse_api 0.10.1 → 0.11.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/.gitignore +21 -21
- data/.travis.yml +5 -7
- data/CHANGELOG.md +99 -85
- data/Gemfile +4 -4
- data/Guardfile +5 -5
- data/LICENSE.txt +22 -22
- data/README.md +73 -73
- data/Rakefile +7 -7
- data/discourse_api.gemspec +35 -33
- data/examples/backups.rb +18 -18
- data/examples/category.rb +21 -21
- data/examples/change_topic_status.rb +33 -0
- data/examples/create_topic.rb +23 -23
- data/examples/create_user.rb +14 -14
- data/examples/dashboard.rb +13 -13
- data/examples/disposable_invite_tokens.rb +18 -18
- data/examples/example.rb +9 -9
- data/examples/groups.rb +25 -25
- data/examples/invite_users.rb +15 -15
- data/examples/post_action.rb +25 -25
- data/examples/search.rb +9 -9
- data/examples/sso.rb +14 -14
- data/examples/topic_lists.rb +15 -15
- data/examples/update_user.rb +22 -22
- data/lib/discourse_api.rb +5 -5
- data/lib/discourse_api/api/api_key.rb +31 -31
- data/lib/discourse_api/api/backups.rb +24 -24
- data/lib/discourse_api/api/badges.rb +28 -28
- data/lib/discourse_api/api/categories.rb +57 -57
- data/lib/discourse_api/api/dashboard.rb +24 -24
- data/lib/discourse_api/api/email.rb +15 -15
- data/lib/discourse_api/api/groups.rb +52 -52
- data/lib/discourse_api/api/invite.rb +17 -17
- data/lib/discourse_api/api/notifications.rb +9 -9
- data/lib/discourse_api/api/params.rb +55 -55
- data/lib/discourse_api/api/posts.rb +41 -42
- data/lib/discourse_api/api/private_messages.rb +10 -10
- data/lib/discourse_api/api/search.rb +19 -19
- data/lib/discourse_api/api/sso.rb +22 -22
- data/lib/discourse_api/api/tags.rb +10 -10
- data/lib/discourse_api/api/topics.rb +78 -65
- data/lib/discourse_api/api/users.rb +85 -85
- data/lib/discourse_api/client.rb +133 -133
- data/lib/discourse_api/error.rb +17 -17
- data/lib/discourse_api/single_sign_on.rb +110 -110
- data/lib/discourse_api/version.rb +3 -3
- data/routes.txt +203 -203
- data/spec/discourse_api/api/api_key_spec.rb +121 -121
- data/spec/discourse_api/api/backups_spec.rb +23 -23
- data/spec/discourse_api/api/badges_spec.rb +40 -40
- data/spec/discourse_api/api/categories_spec.rb +87 -87
- data/spec/discourse_api/api/email_spec.rb +39 -39
- data/spec/discourse_api/api/groups_spec.rb +94 -94
- data/spec/discourse_api/api/notifications_spec.rb +24 -24
- data/spec/discourse_api/api/params_spec.rb +32 -32
- data/spec/discourse_api/api/posts_spec.rb +41 -29
- data/spec/discourse_api/api/private_messages_spec.rb +22 -22
- data/spec/discourse_api/api/search_spec.rb +30 -30
- data/spec/discourse_api/api/sso_spec.rb +16 -16
- data/spec/discourse_api/api/topics_spec.rb +113 -113
- data/spec/discourse_api/api/users_spec.rb +227 -227
- data/spec/discourse_api/client_spec.rb +115 -115
- data/spec/fixtures/api.json +12 -12
- data/spec/fixtures/backups.json +12 -12
- data/spec/fixtures/badges.json +569 -569
- data/spec/fixtures/categories.json +72 -72
- data/spec/fixtures/category_latest_topics.json +92 -92
- data/spec/fixtures/category_topics.json +91 -91
- data/spec/fixtures/email_list_all.json +749 -749
- data/spec/fixtures/email_settings.json +13 -13
- data/spec/fixtures/generate_api_key.json +12 -12
- data/spec/fixtures/generate_master_key.json +7 -7
- data/spec/fixtures/groups.json +18 -18
- data/spec/fixtures/hot.json +113 -113
- data/spec/fixtures/latest.json +115 -115
- data/spec/fixtures/members_0.json +403 -403
- data/spec/fixtures/members_1.json +363 -363
- data/spec/fixtures/new.json +113 -113
- data/spec/fixtures/notifications.json +16 -16
- data/spec/fixtures/post.json +94 -94
- data/spec/fixtures/post_action_users.json +18 -0
- data/spec/fixtures/private_messages.json +69 -69
- data/spec/fixtures/regenerate_api_key.json +7 -7
- data/spec/fixtures/search.json +24 -24
- data/spec/fixtures/topic.json +739 -739
- data/spec/fixtures/topic_invite_user.json +3 -3
- data/spec/fixtures/topics_created_by.json +49 -49
- data/spec/fixtures/update_trust_level.json +37 -37
- data/spec/fixtures/upload_avatar.json +13 -13
- data/spec/fixtures/user.json +65 -65
- data/spec/fixtures/user_activate_success.json +3 -3
- data/spec/fixtures/user_badges.json +170 -170
- data/spec/fixtures/user_create_success.json +5 -5
- data/spec/fixtures/user_grant_admin.json +37 -37
- data/spec/fixtures/user_list.json +583 -583
- data/spec/fixtures/user_log_out_success.json +3 -3
- data/spec/fixtures/user_update_avatar_success.json +3 -3
- data/spec/fixtures/user_update_user.json +3 -3
- data/spec/fixtures/user_update_username.json +4 -4
- data/spec/spec_helper.rb +61 -61
- metadata +31 -28
data/examples/post_action.rb
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# Post Action Type IDs
|
|
9
|
-
# 1 - Bookmark
|
|
10
|
-
# 2 - Like
|
|
11
|
-
# 3 - Flag: Off-topic
|
|
12
|
-
# 4 - Flag: Inappropriate
|
|
13
|
-
# 5 - Vote
|
|
14
|
-
# 6 - Notify User
|
|
15
|
-
# 7 - Flag - Notify Moderators
|
|
16
|
-
# 8 - Flag - Spam
|
|
17
|
-
|
|
18
|
-
# Like a post
|
|
19
|
-
client.create_post_action(id: 2, post_action_type_id: 2)
|
|
20
|
-
|
|
21
|
-
# Flag a topic as spam
|
|
22
|
-
client.create_topic_action(id: 1, post_action_type_id: 8)
|
|
23
|
-
|
|
24
|
-
# Unlike a post
|
|
25
|
-
client.destroy_post_action(id: 3, post_action_type_id: 2)
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# Post Action Type IDs
|
|
9
|
+
# 1 - Bookmark
|
|
10
|
+
# 2 - Like
|
|
11
|
+
# 3 - Flag: Off-topic
|
|
12
|
+
# 4 - Flag: Inappropriate
|
|
13
|
+
# 5 - Vote
|
|
14
|
+
# 6 - Notify User
|
|
15
|
+
# 7 - Flag - Notify Moderators
|
|
16
|
+
# 8 - Flag - Spam
|
|
17
|
+
|
|
18
|
+
# Like a post
|
|
19
|
+
client.create_post_action(id: 2, post_action_type_id: 2)
|
|
20
|
+
|
|
21
|
+
# Flag a topic as spam
|
|
22
|
+
client.create_topic_action(id: 1, post_action_type_id: 8)
|
|
23
|
+
|
|
24
|
+
# Unlike a post
|
|
25
|
+
client.destroy_post_action(id: 3, post_action_type_id: 2)
|
data/examples/search.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# search for term
|
|
9
|
-
puts client.search("discourse")
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# search for term
|
|
9
|
+
puts client.search("discourse")
|
data/examples/sso.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
client.sync_sso(
|
|
9
|
-
sso_secret: "discourse_sso_rocks",
|
|
10
|
-
name: "Test Name",
|
|
11
|
-
username: "test_name",
|
|
12
|
-
email: "name@example.com",
|
|
13
|
-
external_id: "2"
|
|
14
|
-
)
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
client.sync_sso(
|
|
9
|
+
sso_secret: "discourse_sso_rocks",
|
|
10
|
+
name: "Test Name",
|
|
11
|
+
username: "test_name",
|
|
12
|
+
email: "name@example.com",
|
|
13
|
+
external_id: "2"
|
|
14
|
+
)
|
data/examples/topic_lists.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# get latest topics
|
|
9
|
-
puts client.latest_topics({})
|
|
10
|
-
|
|
11
|
-
# recategorize topic
|
|
12
|
-
puts client.recategorize_topic(topic_id: 108, category_id: 5)
|
|
13
|
-
|
|
14
|
-
# get all categories
|
|
15
|
-
puts client.categories({})
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# get latest topics
|
|
9
|
+
puts client.latest_topics({})
|
|
10
|
+
|
|
11
|
+
# recategorize topic
|
|
12
|
+
puts client.recategorize_topic(topic_id: 108, category_id: 5)
|
|
13
|
+
|
|
14
|
+
# get all categories
|
|
15
|
+
puts client.categories({})
|
data/examples/update_user.rb
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# update username from "robin" to "batman"
|
|
9
|
-
puts client.update_username("robin", "batman")
|
|
10
|
-
# update name of user whose username is "batman"
|
|
11
|
-
puts client.update_user("batman", name: "Bruce Wayne")
|
|
12
|
-
# update email of user whose username is "batman"
|
|
13
|
-
puts client.update_email("batman", "batman@gotham.com")
|
|
14
|
-
# update avatar of user whose username is "batman"
|
|
15
|
-
puts client.update_avatar(username: "batman", url: "http://meta-discourse.r.worldssl.net/uploads/default/2497/724a6ef2e79d2bc7.png")
|
|
16
|
-
# update trust level of user whose id is "102"
|
|
17
|
-
puts client.update_trust_level(user_id: 102, level: 2)
|
|
18
|
-
# update user bio, location or website
|
|
19
|
-
puts client.update_user("batman", bio_raw: "I am Batman.", location: "Gotham", website: "https://en.wikipedia.org/wiki/Batman")
|
|
20
|
-
|
|
21
|
-
# log out everywhere and refresh browser of user whose id is "2"
|
|
22
|
-
puts client.log_out(2)
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# update username from "robin" to "batman"
|
|
9
|
+
puts client.update_username("robin", "batman")
|
|
10
|
+
# update name of user whose username is "batman"
|
|
11
|
+
puts client.update_user("batman", name: "Bruce Wayne")
|
|
12
|
+
# update email of user whose username is "batman"
|
|
13
|
+
puts client.update_email("batman", "batman@gotham.com")
|
|
14
|
+
# update avatar of user whose username is "batman"
|
|
15
|
+
puts client.update_avatar(username: "batman", url: "http://meta-discourse.r.worldssl.net/uploads/default/2497/724a6ef2e79d2bc7.png")
|
|
16
|
+
# update trust level of user whose id is "102"
|
|
17
|
+
puts client.update_trust_level(user_id: 102, level: 2)
|
|
18
|
+
# update user bio, location or website
|
|
19
|
+
puts client.update_user("batman", bio_raw: "I am Batman.", location: "Gotham", website: "https://en.wikipedia.org/wiki/Batman")
|
|
20
|
+
|
|
21
|
+
# log out everywhere and refresh browser of user whose id is "2"
|
|
22
|
+
puts client.log_out(2)
|
data/lib/discourse_api.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require "discourse_api/api/params"
|
|
2
|
-
require "discourse_api/client"
|
|
3
|
-
require "discourse_api/error"
|
|
4
|
-
require "discourse_api/version"
|
|
5
|
-
require "discourse_api/single_sign_on"
|
|
1
|
+
require "discourse_api/api/params"
|
|
2
|
+
require "discourse_api/client"
|
|
3
|
+
require "discourse_api/error"
|
|
4
|
+
require "discourse_api/version"
|
|
5
|
+
require "discourse_api/single_sign_on"
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
module DiscourseApi
|
|
2
|
-
module API
|
|
3
|
-
module ApiKey
|
|
4
|
-
def api
|
|
5
|
-
response = get("/admin/api.json")
|
|
6
|
-
response.body
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def generate_user_api_key(user_id)
|
|
10
|
-
response = post("/admin/users/#{user_id}/generate_api_key.json")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def revoke_user_api_key(user_id)
|
|
14
|
-
response = delete("/admin/users/#{user_id}/revoke_api_key.json")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def generate_master_key
|
|
18
|
-
response = post("/admin/api/key")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def revoke_api_key(id)
|
|
22
|
-
response = delete("/admin/api/key", {id: id})
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def regenerate_api_key(id)
|
|
26
|
-
response = put("/admin/api/key", {id: id})
|
|
27
|
-
response.body
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
1
|
+
module DiscourseApi
|
|
2
|
+
module API
|
|
3
|
+
module ApiKey
|
|
4
|
+
def api
|
|
5
|
+
response = get("/admin/api.json")
|
|
6
|
+
response.body
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def generate_user_api_key(user_id)
|
|
10
|
+
response = post("/admin/users/#{user_id}/generate_api_key.json")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def revoke_user_api_key(user_id)
|
|
14
|
+
response = delete("/admin/users/#{user_id}/revoke_api_key.json")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def generate_master_key
|
|
18
|
+
response = post("/admin/api/key")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def revoke_api_key(id)
|
|
22
|
+
response = delete("/admin/api/key", {id: id})
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def regenerate_api_key(id)
|
|
26
|
+
response = put("/admin/api/key", {id: id})
|
|
27
|
+
response.body
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
module DiscourseApi
|
|
2
|
-
module API
|
|
3
|
-
module Backups
|
|
4
|
-
def backups
|
|
5
|
-
response = get("/admin/backups.json")
|
|
6
|
-
response.body
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def create_backup
|
|
10
|
-
post("/admin/backups", with_uploads: true)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def restore_backup(file_name)
|
|
14
|
-
post("/admin/backups/#{file_name}/restore")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def download_backup(file_name)
|
|
18
|
-
response = get("/admin/backups/#{file_name}")
|
|
19
|
-
# write file
|
|
20
|
-
File.open(
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
1
|
+
module DiscourseApi
|
|
2
|
+
module API
|
|
3
|
+
module Backups
|
|
4
|
+
def backups
|
|
5
|
+
response = get("/admin/backups.json")
|
|
6
|
+
response.body
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def create_backup
|
|
10
|
+
post("/admin/backups", with_uploads: true)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def restore_backup(file_name)
|
|
14
|
+
post("/admin/backups/#{file_name}/restore")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def download_backup(file_name, destination)
|
|
18
|
+
response = get("/admin/backups/#{file_name}")
|
|
19
|
+
# write file
|
|
20
|
+
File.open("#{destination}/#{file_name}", 'wb') { |fp| fp.write(response.body) }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
module DiscourseApi
|
|
2
|
-
module API
|
|
3
|
-
module Badges
|
|
4
|
-
def badges
|
|
5
|
-
response = get("/admin/badges.json")
|
|
6
|
-
response.body
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def user_badges(username)
|
|
10
|
-
response = get("/users/#{username}/activity/badges.json")
|
|
11
|
-
response.body['badges']
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def grant_user_badge(params={})
|
|
15
|
-
post("/user_badges", params)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def create_badge(params={})
|
|
19
|
-
args = API.params(params)
|
|
20
|
-
.required(:name, :badge_type_id)
|
|
21
|
-
.optional(:description, :allow_title, :multiple_grant, :icon, :listable,
|
|
22
|
-
:target_posts, :query, :enabled, :auto_revoke, :badge_grouping_id,
|
|
23
|
-
:trigger, :show_posts, :image, :long_description)
|
|
24
|
-
post("/admin/badges.json", args)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
module DiscourseApi
|
|
2
|
+
module API
|
|
3
|
+
module Badges
|
|
4
|
+
def badges
|
|
5
|
+
response = get("/admin/badges.json")
|
|
6
|
+
response.body
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def user_badges(username)
|
|
10
|
+
response = get("/users/#{username}/activity/badges.json")
|
|
11
|
+
response.body['badges']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def grant_user_badge(params={})
|
|
15
|
+
post("/user_badges", params)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create_badge(params={})
|
|
19
|
+
args = API.params(params)
|
|
20
|
+
.required(:name, :badge_type_id)
|
|
21
|
+
.optional(:description, :allow_title, :multiple_grant, :icon, :listable,
|
|
22
|
+
:target_posts, :query, :enabled, :auto_revoke, :badge_grouping_id,
|
|
23
|
+
:trigger, :show_posts, :image, :long_description)
|
|
24
|
+
post("/admin/badges.json", args)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
module DiscourseApi
|
|
2
|
-
module API
|
|
3
|
-
module Categories
|
|
4
|
-
# :color and :text_color are RGB hexadecimal strings
|
|
5
|
-
# :permissions is a hash with the group name and permission_type which is
|
|
6
|
-
# an integer 1 = Full 2 = Create Post 3 = Read Only
|
|
7
|
-
def create_category(args={})
|
|
8
|
-
args = API.params(args)
|
|
9
|
-
.required(:name, :color, :text_color)
|
|
10
|
-
.optional(:description, :permissions)
|
|
11
|
-
.default(parent_category_id: nil)
|
|
12
|
-
response = post("/categories", args)
|
|
13
|
-
response['category']
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def categories(params={})
|
|
17
|
-
response = get('/categories.json', params)
|
|
18
|
-
response[:body]['category_list']['categories']
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def category_latest_topics(args={})
|
|
22
|
-
params = API.params(args)
|
|
23
|
-
.required(:category_slug)
|
|
24
|
-
.optional(:page).to_h
|
|
25
|
-
url = "/c/#{params[:category_slug]}/l/latest.json"
|
|
26
|
-
if params.include?(:page)
|
|
27
|
-
url = "#{url}?page=#{params[:page]}"
|
|
28
|
-
end
|
|
29
|
-
response = get(url)
|
|
30
|
-
if response[:body]['errors']
|
|
31
|
-
response[:body]['errors']
|
|
32
|
-
else
|
|
33
|
-
response[:body]['topic_list']['topics']
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def category_top_topics(category_slug)
|
|
38
|
-
response = get("/c/#{category_slug}/l/top.json")
|
|
39
|
-
if response[:body]['errors']
|
|
40
|
-
response[:body]['errors']
|
|
41
|
-
else
|
|
42
|
-
response[:body]['topic_list']['topics']
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def category_new_topics(category_slug)
|
|
47
|
-
response = get("/c/#{category_slug}/l/new.json")
|
|
48
|
-
response[:body]['topic_list']['topics']
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def category(id)
|
|
52
|
-
response = get("/c/#{id}/show")
|
|
53
|
-
response.body['category']
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
1
|
+
module DiscourseApi
|
|
2
|
+
module API
|
|
3
|
+
module Categories
|
|
4
|
+
# :color and :text_color are RGB hexadecimal strings
|
|
5
|
+
# :permissions is a hash with the group name and permission_type which is
|
|
6
|
+
# an integer 1 = Full 2 = Create Post 3 = Read Only
|
|
7
|
+
def create_category(args={})
|
|
8
|
+
args = API.params(args)
|
|
9
|
+
.required(:name, :color, :text_color)
|
|
10
|
+
.optional(:description, :permissions)
|
|
11
|
+
.default(parent_category_id: nil)
|
|
12
|
+
response = post("/categories", args)
|
|
13
|
+
response['category']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def categories(params={})
|
|
17
|
+
response = get('/categories.json', params)
|
|
18
|
+
response[:body]['category_list']['categories']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def category_latest_topics(args={})
|
|
22
|
+
params = API.params(args)
|
|
23
|
+
.required(:category_slug)
|
|
24
|
+
.optional(:page).to_h
|
|
25
|
+
url = "/c/#{params[:category_slug]}/l/latest.json"
|
|
26
|
+
if params.include?(:page)
|
|
27
|
+
url = "#{url}?page=#{params[:page]}"
|
|
28
|
+
end
|
|
29
|
+
response = get(url)
|
|
30
|
+
if response[:body]['errors']
|
|
31
|
+
response[:body]['errors']
|
|
32
|
+
else
|
|
33
|
+
response[:body]['topic_list']['topics']
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def category_top_topics(category_slug)
|
|
38
|
+
response = get("/c/#{category_slug}/l/top.json")
|
|
39
|
+
if response[:body]['errors']
|
|
40
|
+
response[:body]['errors']
|
|
41
|
+
else
|
|
42
|
+
response[:body]['topic_list']['topics']
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def category_new_topics(category_slug)
|
|
47
|
+
response = get("/c/#{category_slug}/l/new.json")
|
|
48
|
+
response[:body]['topic_list']['topics']
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def category(id)
|
|
52
|
+
response = get("/c/#{id}/show")
|
|
53
|
+
response.body['category']
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|