discourse_api 0.34.0 → 0.35.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +10 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -0
- data/Guardfile +2 -1
- data/Rakefile +7 -2
- data/discourse_api.gemspec +23 -22
- data/examples/backups.rb +1 -0
- data/examples/badges.rb +1 -0
- data/examples/category.rb +1 -0
- data/examples/change_topic_status.rb +3 -3
- data/examples/create_private_message.rb +1 -0
- data/examples/create_topic.rb +1 -0
- data/examples/create_update_category.rb +1 -1
- data/examples/create_user.rb +1 -0
- data/examples/dashboard.rb +3 -2
- data/examples/disposable_invite_tokens.rb +1 -0
- data/examples/example.rb +1 -0
- data/examples/group_set_user_notification_level.rb +1 -1
- data/examples/groups.rb +1 -0
- data/examples/invite_users.rb +1 -0
- data/examples/post_action.rb +1 -0
- data/examples/search.rb +1 -0
- data/examples/sent_private_messages.rb +1 -0
- data/examples/sso.rb +1 -0
- data/examples/topic_lists.rb +1 -0
- data/examples/update_user.rb +1 -0
- data/examples/upload_file.rb +1 -0
- data/lib/discourse_api.rb +1 -0
- data/lib/discourse_api/api/api_key.rb +3 -2
- data/lib/discourse_api/api/backups.rb +1 -0
- data/lib/discourse_api/api/badges.rb +5 -4
- data/lib/discourse_api/api/categories.rb +16 -15
- data/lib/discourse_api/api/dashboard.rb +7 -6
- data/lib/discourse_api/api/email.rb +1 -0
- data/lib/discourse_api/api/groups.rb +11 -10
- data/lib/discourse_api/api/invite.rb +4 -3
- data/lib/discourse_api/api/notifications.rb +2 -1
- data/lib/discourse_api/api/params.rb +3 -2
- data/lib/discourse_api/api/posts.rb +7 -6
- data/lib/discourse_api/api/private_messages.rb +4 -3
- data/lib/discourse_api/api/search.rb +2 -1
- data/lib/discourse_api/api/site_settings.rb +3 -2
- data/lib/discourse_api/api/sso.rb +3 -2
- data/lib/discourse_api/api/tags.rb +1 -0
- data/lib/discourse_api/api/topics.rb +17 -16
- data/lib/discourse_api/api/uploads.rb +4 -3
- data/lib/discourse_api/api/user_actions.rb +3 -2
- data/lib/discourse_api/api/users.rb +23 -20
- data/lib/discourse_api/client.rb +8 -7
- data/lib/discourse_api/error.rb +2 -1
- data/lib/discourse_api/single_sign_on.rb +1 -0
- data/lib/discourse_api/version.rb +2 -1
- data/spec/discourse_api/api/users_spec.rb +13 -13
- metadata +38 -25
- data/routes.txt +0 -203
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Groups
|
4
5
|
def create_group(args)
|
5
6
|
args = API.params(args)
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
.required(:name)
|
8
|
+
.default(visibility_level: 0)
|
9
|
+
.optional(:mentionable_level,
|
9
10
|
:messageable_level,
|
10
11
|
:automatic_membership_email_domains,
|
11
12
|
:automatic_membership_retroactive,
|
@@ -25,14 +26,14 @@ module DiscourseApi
|
|
25
26
|
:usernames,
|
26
27
|
:owner_usernames,
|
27
28
|
:membership_request_template)
|
28
|
-
|
29
|
+
.to_h
|
29
30
|
post("/admin/groups", group: args)
|
30
31
|
end
|
31
32
|
|
32
33
|
def update_group(group_id, args)
|
33
34
|
args = API.params(args)
|
34
|
-
|
35
|
-
|
35
|
+
.default(visibility_level: 0)
|
36
|
+
.optional(:mentionable_level,
|
36
37
|
:messageable_level,
|
37
38
|
:name,
|
38
39
|
:automatic_membership_email_domains,
|
@@ -53,7 +54,7 @@ module DiscourseApi
|
|
53
54
|
:usernames,
|
54
55
|
:owner_usernames,
|
55
56
|
:membership_request_template)
|
56
|
-
|
57
|
+
.to_h
|
57
58
|
put("/groups/#{group_id}", group: args)
|
58
59
|
end
|
59
60
|
|
@@ -107,9 +108,9 @@ module DiscourseApi
|
|
107
108
|
|
108
109
|
def group_members(group_name, params = {})
|
109
110
|
params = API.params(params)
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
.optional(:offset, :limit)
|
112
|
+
.default(offset: 0, limit: 100)
|
113
|
+
.to_h
|
113
114
|
response = get("/groups/#{group_name}/members.json", params)
|
114
115
|
response.body['members']
|
115
116
|
end
|
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Invite
|
4
|
-
def invite_user(params={})
|
5
|
+
def invite_user(params = {})
|
5
6
|
post("/invites", params)
|
6
7
|
end
|
7
8
|
|
8
|
-
def invite_user_to_topic(params={})
|
9
|
+
def invite_user_to_topic(params = {})
|
9
10
|
post("/t/#{params[:topic_id]}/invite", params)
|
10
11
|
end
|
11
12
|
|
12
13
|
# requires this plugin => https://github.com/discourse/discourse-invite-tokens
|
13
|
-
def disposable_tokens(params={})
|
14
|
+
def disposable_tokens(params = {})
|
14
15
|
post("/invite-token/generate", params)
|
15
16
|
end
|
16
17
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
def self.params(args)
|
@@ -24,7 +25,7 @@ module DiscourseApi
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def default(args)
|
27
|
-
args.each do |k,v|
|
28
|
+
args.each do |k, v|
|
28
29
|
@defaults[k] = v
|
29
30
|
end
|
30
31
|
self
|
@@ -42,7 +43,7 @@ module DiscourseApi
|
|
42
43
|
h[k] = @args[k] if @args.include?(k)
|
43
44
|
end
|
44
45
|
|
45
|
-
@defaults.each do |k,v|
|
46
|
+
@defaults.each do |k, v|
|
46
47
|
@args.key?(k) ? h[k] = @args[k] : h[k] = v
|
47
48
|
end
|
48
49
|
|
@@ -1,22 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Posts
|
4
5
|
def create_post(args)
|
5
6
|
args = API.params(args)
|
6
|
-
|
7
|
-
|
7
|
+
.required(:topic_id, :raw)
|
8
|
+
.optional(:created_at, :api_username)
|
8
9
|
post("/posts", args)
|
9
10
|
end
|
10
11
|
|
11
12
|
def create_post_action(args)
|
12
13
|
args = API.params(args)
|
13
|
-
|
14
|
+
.required(:id, :post_action_type_id)
|
14
15
|
post("/post_actions", args.to_h.merge(flag_topic: false))
|
15
16
|
end
|
16
17
|
|
17
18
|
def get_post(id, args = {})
|
18
19
|
args = API.params(args)
|
19
|
-
|
20
|
+
.optional(:version)
|
20
21
|
response = get("/posts/#{id}.json", args)
|
21
22
|
response[:body]
|
22
23
|
end
|
@@ -26,7 +27,7 @@ module DiscourseApi
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def edit_post(id, raw)
|
29
|
-
put("/posts/#{id}", post: {raw: raw})
|
30
|
+
put("/posts/#{id}", post: { raw: raw })
|
30
31
|
end
|
31
32
|
|
32
33
|
def delete_post(id)
|
@@ -38,7 +39,7 @@ module DiscourseApi
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def post_action_users(post_id, post_action_type_id)
|
41
|
-
response = get("/post_action_users.json",
|
42
|
+
response = get("/post_action_users.json", id: post_id, post_action_type_id: post_action_type_id)
|
42
43
|
response[:body]
|
43
44
|
end
|
44
45
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module PrivateMessages
|
@@ -5,11 +6,11 @@ module DiscourseApi
|
|
5
6
|
# :target_usernames REQUIRED comma separated list of usernames
|
6
7
|
# :category OPTIONAL name of category, not ID
|
7
8
|
# :created_at OPTIONAL seconds since epoch.
|
8
|
-
def create_private_message(args={})
|
9
|
+
def create_private_message(args = {})
|
9
10
|
args[:archetype] = 'private_message'
|
10
11
|
args = API.params(args)
|
11
|
-
|
12
|
-
|
12
|
+
.required(:title, :raw, :target_usernames, :archetype)
|
13
|
+
.optional(:category, :created_at, :api_username)
|
13
14
|
post("/posts", args.to_h)
|
14
15
|
end
|
15
16
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Search
|
@@ -7,7 +8,7 @@ module DiscourseApi
|
|
7
8
|
# @param options [Hash] A customizable set of options
|
8
9
|
# @option options [String] :type_filter Returns results of the specified type.
|
9
10
|
# @return [Array] Return results as an array of Hashes.
|
10
|
-
def search(term, options={})
|
11
|
+
def search(term, options = {})
|
11
12
|
raise ArgumentError.new("#{term} is required but not specified") unless term
|
12
13
|
raise ArgumentError.new("#{term} is required but not specified") unless !term.empty?
|
13
14
|
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module SiteSettings
|
4
|
-
def site_setting_update(args={})
|
5
|
+
def site_setting_update(args = {})
|
5
6
|
params = API.params(args)
|
6
|
-
|
7
|
+
.required(:name, :value).to_h
|
7
8
|
new_site_setting = { params[:name] => params[:value] }
|
8
9
|
response = put("/admin/site_settings/#{params[:name]}", new_site_setting)
|
9
10
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module SSO
|
4
|
-
def sync_sso(params={})
|
5
|
+
def sync_sso(params = {})
|
5
6
|
sso = DiscourseApi::SingleSignOn.new
|
6
7
|
sso.sso_secret = params[:sso_secret]
|
7
8
|
sso.name = params[:name]
|
@@ -14,7 +15,7 @@ module DiscourseApi
|
|
14
15
|
sso.avatar_force_update = params[:avatar_force_update] === true
|
15
16
|
sso.add_groups = params[:add_groups]
|
16
17
|
sso.remove_groups = params[:remove_groups]
|
17
|
-
params.keys.select{|key| key.to_s.start_with?("custom") }.each do |custom_key|
|
18
|
+
params.keys.select { |key| key.to_s.start_with?("custom") }.each do |custom_key|
|
18
19
|
sso.custom_fields[custom_key] = params[custom_key]
|
19
20
|
end
|
20
21
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Topics
|
@@ -5,55 +6,55 @@ module DiscourseApi
|
|
5
6
|
# :skip_validations OPTIONAL boolean
|
6
7
|
# :auto_track OPTIONAL boolean
|
7
8
|
# :created_at OPTIONAL seconds since epoch.
|
8
|
-
def create_topic(args={})
|
9
|
+
def create_topic(args = {})
|
9
10
|
args = API.params(args)
|
10
|
-
|
11
|
-
|
11
|
+
.required(:title, :raw)
|
12
|
+
.optional(:skip_validations, :category, :auto_track, :created_at, :api_username)
|
12
13
|
post("/posts", args.to_h)
|
13
14
|
end
|
14
15
|
|
15
16
|
def create_topic_action(args)
|
16
17
|
args = API.params(args)
|
17
|
-
|
18
|
+
.required(:id, :post_action_type_id)
|
18
19
|
post("/post_actions", args.to_h.merge(flag_topic: true))
|
19
20
|
end
|
20
21
|
|
21
22
|
# timestamp is seconds past the epoch.
|
22
|
-
def edit_topic_timestamp(topic_id,timestamp)
|
23
|
-
put("/t/#{topic_id}/change-timestamp",
|
23
|
+
def edit_topic_timestamp(topic_id, timestamp)
|
24
|
+
put("/t/#{topic_id}/change-timestamp", timestamp: timestamp)
|
24
25
|
end
|
25
26
|
|
26
|
-
def latest_topics(params={})
|
27
|
+
def latest_topics(params = {})
|
27
28
|
response = get('/latest.json', params)
|
28
29
|
response[:body]['topic_list']['topics']
|
29
30
|
end
|
30
31
|
|
31
|
-
def new_topics(params={})
|
32
|
+
def new_topics(params = {})
|
32
33
|
response = get("/new.json", params)
|
33
34
|
response[:body]['topic_list']['topics']
|
34
35
|
end
|
35
36
|
|
36
37
|
def rename_topic(topic_id, title)
|
37
|
-
put("/t/#{topic_id}.json",
|
38
|
+
put("/t/#{topic_id}.json", topic_id: topic_id, title: title)
|
38
39
|
end
|
39
40
|
|
40
41
|
def recategorize_topic(topic_id, category_id)
|
41
|
-
put("/t/#{topic_id}.json",
|
42
|
+
put("/t/#{topic_id}.json", topic_id: topic_id, category_id: category_id)
|
42
43
|
end
|
43
44
|
|
44
|
-
def change_topic_status(topic_slug, topic_id, params={})
|
45
|
+
def change_topic_status(topic_slug, topic_id, params = {})
|
45
46
|
params = API.params(params)
|
46
|
-
|
47
|
-
|
47
|
+
.required(:status, :enabled)
|
48
|
+
.optional(:api_username)
|
48
49
|
put("/t/#{topic_slug}/#{topic_id}/status", params.to_h)
|
49
50
|
end
|
50
51
|
|
51
|
-
def topic(id, params={})
|
52
|
+
def topic(id, params = {})
|
52
53
|
response = get("/t/#{id}.json", params)
|
53
54
|
response[:body]
|
54
55
|
end
|
55
56
|
|
56
|
-
def topics_by(username, params={})
|
57
|
+
def topics_by(username, params = {})
|
57
58
|
response = get("/topics/created-by/#{username}.json", params)
|
58
59
|
response[:body]['topic_list']['topics']
|
59
60
|
end
|
@@ -62,7 +63,7 @@ module DiscourseApi
|
|
62
63
|
delete("/t/#{id}.json")
|
63
64
|
end
|
64
65
|
|
65
|
-
def topic_posts(topic_id, post_ids=[])
|
66
|
+
def topic_posts(topic_id, post_ids = [])
|
66
67
|
url = "/t/#{topic_id}/posts.json"
|
67
68
|
if post_ids.count > 0
|
68
69
|
url << '?'
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Uploads
|
4
5
|
def upload_file(args)
|
5
6
|
args = API.params(args)
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
.optional(:file, :url, :user_id)
|
8
|
+
.default(type: 'composer', synchronous: true)
|
9
|
+
.to_h
|
9
10
|
post('/uploads', args)
|
10
11
|
end
|
11
12
|
end
|
@@ -1,14 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module UserActions
|
4
5
|
def user_replies(username)
|
5
|
-
params = {"username": username, "filter": '5'}
|
6
|
+
params = { "username": username, "filter": '5' }
|
6
7
|
response = get("/user_actions.json", params)
|
7
8
|
response.body["user_actions"]
|
8
9
|
end
|
9
10
|
|
10
11
|
def user_topics_and_replies(username)
|
11
|
-
params = {"username": username, "filter": "4,5"}
|
12
|
+
params = { "username": username, "filter": "4,5" }
|
12
13
|
response = get("/user_actions.json", params)
|
13
14
|
response.body["user_actions"]
|
14
15
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Users
|
@@ -5,7 +6,7 @@ module DiscourseApi
|
|
5
6
|
put("/admin/users/#{id}/activate")
|
6
7
|
end
|
7
8
|
|
8
|
-
def user(username, params={})
|
9
|
+
def user(username, params = {})
|
9
10
|
response = get("/users/#{username}.json", params)
|
10
11
|
response[:body]['user']
|
11
12
|
end
|
@@ -15,41 +16,43 @@ module DiscourseApi
|
|
15
16
|
response[:body]['single_sign_on_record']
|
16
17
|
end
|
17
18
|
|
18
|
-
def update_avatar(args)
|
19
|
+
def update_avatar(username, args)
|
19
20
|
args = API.params(args)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
.to_h
|
21
|
+
.optional(:file, :url)
|
22
|
+
.default(type: 'avatar', synchronous: true)
|
23
|
+
.to_h
|
24
24
|
upload_response = post("/uploads", args)
|
25
|
-
put("/
|
25
|
+
put("/u/#{username}/preferences/avatar/pick", upload_id: upload_response['id'])
|
26
26
|
end
|
27
27
|
|
28
28
|
def update_email(username, email)
|
29
|
-
put("/
|
29
|
+
put("/u/#{username}/preferences/email", email: email)
|
30
30
|
end
|
31
31
|
|
32
|
-
def update_user(username,
|
33
|
-
|
32
|
+
def update_user(username, args)
|
33
|
+
args = API.params(args)
|
34
|
+
.optional(:name, :title, :bio_raw, :location, :website, :profile_background, :card_background)
|
35
|
+
.to_h
|
36
|
+
put("/u/#{username}", args)
|
34
37
|
end
|
35
38
|
|
36
39
|
def update_username(username, new_username)
|
37
|
-
put("/
|
40
|
+
put("/u/#{username}/preferences/username", new_username: new_username)
|
38
41
|
end
|
39
42
|
|
40
|
-
def update_trust_level(args)
|
43
|
+
def update_trust_level(user_id, args)
|
41
44
|
args = API.params(args)
|
42
|
-
|
43
|
-
|
44
|
-
response = put("/admin/users/#{
|
45
|
+
.required(:level)
|
46
|
+
.to_h
|
47
|
+
response = put("/admin/users/#{user_id}/trust_level", args)
|
45
48
|
response[:body]
|
46
49
|
end
|
47
50
|
|
48
51
|
def create_user(args)
|
49
52
|
args = API.params(args)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
.required(:name, :email, :password, :username)
|
54
|
+
.optional(:active, :staged, :user_fields)
|
55
|
+
.to_h
|
53
56
|
post("/users", args)
|
54
57
|
end
|
55
58
|
|
@@ -57,7 +60,7 @@ module DiscourseApi
|
|
57
60
|
post("/admin/users/#{id}/log_out")
|
58
61
|
end
|
59
62
|
|
60
|
-
def invite_admin(args={})
|
63
|
+
def invite_admin(args = {})
|
61
64
|
post("/admin/users/invite_admin", args)
|
62
65
|
end
|
63
66
|
|
@@ -82,7 +85,7 @@ module DiscourseApi
|
|
82
85
|
end
|
83
86
|
|
84
87
|
def suspend(user_id, suspend_until, reason)
|
85
|
-
put("/admin/users/#{user_id}/suspend",
|
88
|
+
put("/admin/users/#{user_id}/suspend", suspend_until: suspend_until, reason: reason)
|
86
89
|
end
|
87
90
|
|
88
91
|
def unsuspend(user_id)
|
data/lib/discourse_api/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'faraday'
|
2
3
|
require 'faraday_middleware'
|
3
4
|
require 'json'
|
@@ -58,7 +59,7 @@ module DiscourseApi
|
|
58
59
|
|
59
60
|
def api_username=(api_username)
|
60
61
|
@api_username = api_username
|
61
|
-
@connection.
|
62
|
+
@connection.headers['Api-username'] = api_username unless @connection.nil?
|
62
63
|
end
|
63
64
|
|
64
65
|
def connection_options
|
@@ -75,15 +76,15 @@ module DiscourseApi
|
|
75
76
|
connection_options[:ssl] = options
|
76
77
|
end
|
77
78
|
|
78
|
-
def delete(path, params={})
|
79
|
+
def delete(path, params = {})
|
79
80
|
request(:delete, path, params)
|
80
81
|
end
|
81
82
|
|
82
|
-
def get(path, params={})
|
83
|
+
def get(path, params = {})
|
83
84
|
request(:get, path, params)
|
84
85
|
end
|
85
86
|
|
86
|
-
def post(path, params={})
|
87
|
+
def post(path, params = {})
|
87
88
|
response = request(:post, path, params)
|
88
89
|
case response.status
|
89
90
|
when 200, 201, 204
|
@@ -93,11 +94,11 @@ module DiscourseApi
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
def put(path, params={})
|
97
|
+
def put(path, params = {})
|
97
98
|
request(:put, path, params)
|
98
99
|
end
|
99
100
|
|
100
|
-
def patch(path, params={})
|
101
|
+
def patch(path, params = {})
|
101
102
|
request(:patch, path, params)
|
102
103
|
end
|
103
104
|
|
@@ -127,7 +128,7 @@ module DiscourseApi
|
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
|
-
def request(method, path, params={})
|
131
|
+
def request(method, path, params = {})
|
131
132
|
unless Hash === params
|
132
133
|
params = params.to_h if params.respond_to? :to_h
|
133
134
|
end
|