discourse_api 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +21 -21
- data/.travis.yml +5 -5
- data/CHANGELOG.md +105 -99
- 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 -35
- data/examples/backups.rb +18 -18
- data/examples/category.rb +21 -21
- data/examples/change_topic_status.rb +33 -33
- 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 -41
- 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 -78
- data/lib/discourse_api/api/users.rb +93 -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 -41
- 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 +255 -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 -18
- 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 +2 -2
@@ -1,24 +1,24 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
module Dashboard
|
4
|
-
def get_dashboard_stats
|
5
|
-
response = get("admin/dashboard.json")
|
6
|
-
response[:body]
|
7
|
-
end
|
8
|
-
|
9
|
-
def get_dashboard_stats_totals
|
10
|
-
stats = get_dashboard_stats
|
11
|
-
global_reports = stats['global_reports']
|
12
|
-
users = global_reports[1]
|
13
|
-
topics = global_reports[3]
|
14
|
-
posts = global_reports[4]
|
15
|
-
|
16
|
-
totals = {
|
17
|
-
'users' => users['total'],
|
18
|
-
'topics' => topics['total'],
|
19
|
-
'posts' => posts['total']
|
20
|
-
}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Dashboard
|
4
|
+
def get_dashboard_stats
|
5
|
+
response = get("admin/dashboard.json")
|
6
|
+
response[:body]
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_dashboard_stats_totals
|
10
|
+
stats = get_dashboard_stats
|
11
|
+
global_reports = stats['global_reports']
|
12
|
+
users = global_reports[1]
|
13
|
+
topics = global_reports[3]
|
14
|
+
posts = global_reports[4]
|
15
|
+
|
16
|
+
totals = {
|
17
|
+
'users' => users['total'],
|
18
|
+
'topics' => topics['total'],
|
19
|
+
'posts' => posts['total']
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
module Email
|
4
|
-
def email_settings
|
5
|
-
response = get("/admin/email.json")
|
6
|
-
response.body
|
7
|
-
end
|
8
|
-
|
9
|
-
def list_email(filter)
|
10
|
-
response = get("/admin/email/#{filter}.json")
|
11
|
-
response.body
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Email
|
4
|
+
def email_settings
|
5
|
+
response = get("/admin/email.json")
|
6
|
+
response.body
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_email(filter)
|
10
|
+
response = get("/admin/email/#{filter}.json")
|
11
|
+
response.body
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
module Groups
|
4
|
-
def create_group(args)
|
5
|
-
args = API.params(args)
|
6
|
-
.required(:name)
|
7
|
-
.default(visible: true)
|
8
|
-
.to_h
|
9
|
-
post("/admin/groups", args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def groups
|
13
|
-
response = get("/admin/groups.json")
|
14
|
-
response.body
|
15
|
-
end
|
16
|
-
|
17
|
-
def group_add(group_id, users)
|
18
|
-
users.keys.each do |key|
|
19
|
-
# Accept arrays and convert to comma-delimited string.
|
20
|
-
if users[key].respond_to? :join
|
21
|
-
users[key] = users[key].join(",")
|
22
|
-
end
|
23
|
-
|
24
|
-
# Accept non-plural user_id or username, but send pluralized version in the request.
|
25
|
-
if key.to_s[-1] != 's'
|
26
|
-
users["#{key}s"] = users[key]
|
27
|
-
users.delete(key)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
put("/admin/groups/#{group_id}/members.json", users)
|
32
|
-
end
|
33
|
-
|
34
|
-
def group_remove(group_id, user)
|
35
|
-
delete("/admin/groups/#{group_id}/members.json", user)
|
36
|
-
end
|
37
|
-
|
38
|
-
def delete_group(group_id)
|
39
|
-
delete("/admin/groups/#{group_id}.json")
|
40
|
-
end
|
41
|
-
|
42
|
-
def group_members(group_name, params = {})
|
43
|
-
params = API.params(params)
|
44
|
-
.optional(:offset, :limit)
|
45
|
-
.default(offset: 0, limit: 100)
|
46
|
-
.to_h
|
47
|
-
response = get("/groups/#{group_name}/members.json", params)
|
48
|
-
response.body['members']
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Groups
|
4
|
+
def create_group(args)
|
5
|
+
args = API.params(args)
|
6
|
+
.required(:name)
|
7
|
+
.default(visible: true)
|
8
|
+
.to_h
|
9
|
+
post("/admin/groups", args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def groups
|
13
|
+
response = get("/admin/groups.json")
|
14
|
+
response.body
|
15
|
+
end
|
16
|
+
|
17
|
+
def group_add(group_id, users)
|
18
|
+
users.keys.each do |key|
|
19
|
+
# Accept arrays and convert to comma-delimited string.
|
20
|
+
if users[key].respond_to? :join
|
21
|
+
users[key] = users[key].join(",")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Accept non-plural user_id or username, but send pluralized version in the request.
|
25
|
+
if key.to_s[-1] != 's'
|
26
|
+
users["#{key}s"] = users[key]
|
27
|
+
users.delete(key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
put("/admin/groups/#{group_id}/members.json", users)
|
32
|
+
end
|
33
|
+
|
34
|
+
def group_remove(group_id, user)
|
35
|
+
delete("/admin/groups/#{group_id}/members.json", user)
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_group(group_id)
|
39
|
+
delete("/admin/groups/#{group_id}.json")
|
40
|
+
end
|
41
|
+
|
42
|
+
def group_members(group_name, params = {})
|
43
|
+
params = API.params(params)
|
44
|
+
.optional(:offset, :limit)
|
45
|
+
.default(offset: 0, limit: 100)
|
46
|
+
.to_h
|
47
|
+
response = get("/groups/#{group_name}/members.json", params)
|
48
|
+
response.body['members']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
module Invite
|
4
|
-
def invite_user(params={})
|
5
|
-
post("/invites", params)
|
6
|
-
end
|
7
|
-
|
8
|
-
def invite_user_to_topic(params={})
|
9
|
-
post("/t/#{params[:topic_id]}/invite", params)
|
10
|
-
end
|
11
|
-
|
12
|
-
def disposable_tokens(params={})
|
13
|
-
post("/invites/disposable", params)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Invite
|
4
|
+
def invite_user(params={})
|
5
|
+
post("/invites", params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def invite_user_to_topic(params={})
|
9
|
+
post("/t/#{params[:topic_id]}/invite", params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def disposable_tokens(params={})
|
13
|
+
post("/invites/disposable", params)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
module Notifications
|
4
|
-
def notifications
|
5
|
-
response = get('/notifications.json')
|
6
|
-
response[:body]
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Notifications
|
4
|
+
def notifications
|
5
|
+
response = get('/notifications.json')
|
6
|
+
response[:body]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
10
|
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
def self.params(args)
|
4
|
-
Params.new(args)
|
5
|
-
end
|
6
|
-
|
7
|
-
class Params
|
8
|
-
def initialize(args)
|
9
|
-
raise ArgumentError.new("Required to be initialized with a Hash") unless args.is_a? Hash
|
10
|
-
@args = args
|
11
|
-
@required = []
|
12
|
-
@optional = []
|
13
|
-
@defaults = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
def required(*keys)
|
17
|
-
@required.concat(keys)
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
def optional(*keys)
|
22
|
-
@optional.concat(keys)
|
23
|
-
self
|
24
|
-
end
|
25
|
-
|
26
|
-
def default(args)
|
27
|
-
args.each do |k,v|
|
28
|
-
@defaults[k] = v
|
29
|
-
end
|
30
|
-
self
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_h
|
34
|
-
h = {}
|
35
|
-
|
36
|
-
@required.each do |k|
|
37
|
-
h[k] = @args[k]
|
38
|
-
raise ArgumentError.new("#{k} is required but not specified") unless h[k]
|
39
|
-
end
|
40
|
-
|
41
|
-
@optional.each do |k|
|
42
|
-
h[k] = @args[k] if @args.include?(k)
|
43
|
-
end
|
44
|
-
|
45
|
-
@defaults.each do |k,v|
|
46
|
-
@args.key?(k) ? h[k] = @args[k] : h[k] = v
|
47
|
-
end
|
48
|
-
|
49
|
-
h
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
def self.params(args)
|
4
|
+
Params.new(args)
|
5
|
+
end
|
6
|
+
|
7
|
+
class Params
|
8
|
+
def initialize(args)
|
9
|
+
raise ArgumentError.new("Required to be initialized with a Hash") unless args.is_a? Hash
|
10
|
+
@args = args
|
11
|
+
@required = []
|
12
|
+
@optional = []
|
13
|
+
@defaults = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def required(*keys)
|
17
|
+
@required.concat(keys)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def optional(*keys)
|
22
|
+
@optional.concat(keys)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def default(args)
|
27
|
+
args.each do |k,v|
|
28
|
+
@defaults[k] = v
|
29
|
+
end
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_h
|
34
|
+
h = {}
|
35
|
+
|
36
|
+
@required.each do |k|
|
37
|
+
h[k] = @args[k]
|
38
|
+
raise ArgumentError.new("#{k} is required but not specified") unless h[k]
|
39
|
+
end
|
40
|
+
|
41
|
+
@optional.each do |k|
|
42
|
+
h[k] = @args[k] if @args.include?(k)
|
43
|
+
end
|
44
|
+
|
45
|
+
@defaults.each do |k,v|
|
46
|
+
@args.key?(k) ? h[k] = @args[k] : h[k] = v
|
47
|
+
end
|
48
|
+
|
49
|
+
h
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
module Posts
|
4
|
-
def create_post(args)
|
5
|
-
args = API.params(args)
|
6
|
-
.required(:topic_id, :raw)
|
7
|
-
post("/posts", args)
|
8
|
-
end
|
9
|
-
|
10
|
-
def create_post_action(args)
|
11
|
-
args = API.params(args)
|
12
|
-
.required(:id, :post_action_type_id)
|
13
|
-
post("/post_actions", args.to_h.merge(flag_topic: false))
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_post(id, args = {})
|
17
|
-
args = API.params(args)
|
18
|
-
.optional(:version)
|
19
|
-
response = get("/posts/#{id}.json", args)
|
20
|
-
response[:body]
|
21
|
-
end
|
22
|
-
|
23
|
-
def wikify_post(id)
|
24
|
-
put("/posts/#{id}/wiki", wiki: true)
|
25
|
-
end
|
26
|
-
|
27
|
-
def edit_post(id, raw)
|
28
|
-
put("/posts/#{id}", post: {raw: raw})
|
29
|
-
end
|
30
|
-
|
31
|
-
def destroy_post_action(post_id, post_action_type_id)
|
32
|
-
delete("/post_actions/#{post_id}.json", post_action_type_id: post_action_type_id)
|
33
|
-
end
|
34
|
-
|
35
|
-
def post_action_users(post_id, post_action_type_id)
|
36
|
-
response = get("/post_action_users.json", {id: post_id, post_action_type_id: post_action_type_id})
|
37
|
-
response[:body]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Posts
|
4
|
+
def create_post(args)
|
5
|
+
args = API.params(args)
|
6
|
+
.required(:topic_id, :raw)
|
7
|
+
post("/posts", args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_post_action(args)
|
11
|
+
args = API.params(args)
|
12
|
+
.required(:id, :post_action_type_id)
|
13
|
+
post("/post_actions", args.to_h.merge(flag_topic: false))
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_post(id, args = {})
|
17
|
+
args = API.params(args)
|
18
|
+
.optional(:version)
|
19
|
+
response = get("/posts/#{id}.json", args)
|
20
|
+
response[:body]
|
21
|
+
end
|
22
|
+
|
23
|
+
def wikify_post(id)
|
24
|
+
put("/posts/#{id}/wiki", wiki: true)
|
25
|
+
end
|
26
|
+
|
27
|
+
def edit_post(id, raw)
|
28
|
+
put("/posts/#{id}", post: {raw: raw})
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy_post_action(post_id, post_action_type_id)
|
32
|
+
delete("/post_actions/#{post_id}.json", post_action_type_id: post_action_type_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def post_action_users(post_id, post_action_type_id)
|
36
|
+
response = get("/post_action_users.json", {id: post_id, post_action_type_id: post_action_type_id})
|
37
|
+
response[:body]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module DiscourseApi
|
2
|
-
module API
|
3
|
-
module PrivateMessages
|
4
|
-
def private_messages(username, *args)
|
5
|
-
response = get("topics/private-messages/#{username}.json", args)
|
6
|
-
response[:body]['topic_list']['topics']
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module PrivateMessages
|
4
|
+
def private_messages(username, *args)
|
5
|
+
response = get("topics/private-messages/#{username}.json", args)
|
6
|
+
response[:body]['topic_list']['topics']
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|