discourse_api 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +23 -10
- data/.rubocop.yml +1 -1
- data/.streerc +2 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -1
- data/README.md +0 -4
- data/discourse_api.gemspec +7 -4
- data/examples/backups.rb +5 -5
- data/examples/badges.rb +5 -5
- data/examples/bookmark_topic.rb +5 -5
- data/examples/category.rb +10 -6
- data/examples/change_topic_status.rb +12 -11
- data/examples/create_private_message.rb +6 -6
- data/examples/create_topic.rb +9 -9
- data/examples/create_update_category.rb +13 -16
- data/examples/create_user.rb +12 -11
- data/examples/dashboard.rb +5 -5
- data/examples/disposable_invite_tokens.rb +9 -10
- data/examples/example.rb +5 -5
- data/examples/group_set_user_notification_level.rb +18 -19
- data/examples/groups.rb +7 -7
- data/examples/invite_users.rb +5 -5
- data/examples/manage_api_keys.rb +6 -11
- data/examples/notifications.rb +6 -6
- data/examples/polls.rb +12 -12
- data/examples/post_action.rb +5 -5
- data/examples/search.rb +5 -5
- data/examples/sent_private_messages.rb +6 -6
- data/examples/sso.rb +6 -6
- data/examples/topic_lists.rb +5 -5
- data/examples/update_user.rb +15 -7
- data/examples/upload_file.rb +7 -7
- data/lib/discourse_api/api/api_key.rb +1 -3
- data/lib/discourse_api/api/backups.rb +1 -1
- data/lib/discourse_api/api/badges.rb +21 -6
- data/lib/discourse_api/api/categories.rb +69 -37
- data/lib/discourse_api/api/dashboard.rb +2 -6
- data/lib/discourse_api/api/groups.rb +68 -73
- data/lib/discourse_api/api/invite.rb +30 -30
- data/lib/discourse_api/api/notifications.rb +2 -3
- data/lib/discourse_api/api/params.rb +4 -14
- data/lib/discourse_api/api/polls.rb +9 -12
- data/lib/discourse_api/api/posts.rb +5 -8
- data/lib/discourse_api/api/private_messages.rb +9 -8
- data/lib/discourse_api/api/search.rb +2 -2
- data/lib/discourse_api/api/topics.rb +20 -22
- data/lib/discourse_api/api/uploads.rb +7 -5
- data/lib/discourse_api/api/user_actions.rb +2 -2
- data/lib/discourse_api/api/users.rb +31 -19
- data/lib/discourse_api/client.rb +58 -56
- data/lib/discourse_api/example_helper.rb +2 -4
- data/lib/discourse_api/single_sign_on.rb +56 -57
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +39 -25
- data/spec/discourse_api/api/backups_spec.rb +8 -3
- data/spec/discourse_api/api/badges_spec.rb +17 -7
- data/spec/discourse_api/api/categories_spec.rb +95 -53
- data/spec/discourse_api/api/email_spec.rb +17 -7
- data/spec/discourse_api/api/groups_spec.rb +71 -52
- data/spec/discourse_api/api/invite_spec.rb +41 -21
- data/spec/discourse_api/api/notifications_spec.rb +8 -4
- data/spec/discourse_api/api/params_spec.rb +5 -3
- data/spec/discourse_api/api/polls_spec.rb +53 -44
- data/spec/discourse_api/api/posts_spec.rb +33 -16
- data/spec/discourse_api/api/private_messages_spec.rb +25 -12
- data/spec/discourse_api/api/search_spec.rb +8 -3
- data/spec/discourse_api/api/site_settings_spec.rb +2 -3
- data/spec/discourse_api/api/sso_spec.rb +29 -25
- data/spec/discourse_api/api/topics_spec.rb +100 -31
- data/spec/discourse_api/api/uploads_spec.rb +16 -7
- data/spec/discourse_api/api/user_actions_spec.rb +13 -3
- data/spec/discourse_api/api/users_spec.rb +137 -55
- data/spec/discourse_api/client_spec.rb +32 -32
- data/spec/discourse_api/single_sign_on_spec.rb +43 -0
- data/spec/fixtures/categories.json +1 -1
- data/spec/spec_helper.rb +10 -15
- metadata +57 -12
@@ -3,83 +3,83 @@ module DiscourseApi
|
|
3
3
|
module API
|
4
4
|
module Groups
|
5
5
|
def create_group(args)
|
6
|
-
args =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
6
|
+
args =
|
7
|
+
API
|
8
|
+
.params(args)
|
9
|
+
.required(:name)
|
10
|
+
.default(visibility_level: 0)
|
11
|
+
.optional(
|
12
|
+
:mentionable_level,
|
13
|
+
:messageable_level,
|
14
|
+
:automatic_membership_email_domains,
|
15
|
+
:automatic_membership_retroactive,
|
16
|
+
:title,
|
17
|
+
:primary_group,
|
18
|
+
:grant_trust_level,
|
19
|
+
:incoming_email,
|
20
|
+
:flair_url,
|
21
|
+
:flair_bg_color,
|
22
|
+
:flair_color,
|
23
|
+
:bio_raw,
|
24
|
+
:members_visibility_level,
|
25
|
+
:public_admission,
|
26
|
+
:public_exit,
|
27
|
+
:allow_membership_requests,
|
28
|
+
:full_name,
|
29
|
+
:default_notification_level,
|
30
|
+
:usernames,
|
31
|
+
:owner_usernames,
|
32
|
+
:membership_request_template,
|
33
|
+
)
|
34
|
+
.to_h
|
31
35
|
post("/admin/groups", group: args)
|
32
36
|
end
|
33
37
|
|
34
38
|
def update_group(group_id, args)
|
35
|
-
args =
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
39
|
+
args =
|
40
|
+
API
|
41
|
+
.params(args)
|
42
|
+
.default(visibility_level: 0)
|
43
|
+
.optional(
|
44
|
+
:mentionable_level,
|
45
|
+
:messageable_level,
|
46
|
+
:name,
|
47
|
+
:automatic_membership_email_domains,
|
48
|
+
:title,
|
49
|
+
:primary_group,
|
50
|
+
:grant_trust_level,
|
51
|
+
:incoming_email,
|
52
|
+
:flair_url,
|
53
|
+
:flair_bg_color,
|
54
|
+
:flair_color,
|
55
|
+
:bio_raw,
|
56
|
+
:visibility_level,
|
57
|
+
:public_admission,
|
58
|
+
:public_exit,
|
59
|
+
:allow_membership_requests,
|
60
|
+
:full_name,
|
61
|
+
:default_notification_level,
|
62
|
+
:membership_request_template,
|
63
|
+
)
|
64
|
+
.to_h
|
57
65
|
put("/groups/#{group_id}", group: args)
|
58
66
|
end
|
59
67
|
|
60
68
|
def group_add_owners(group_id, args)
|
61
|
-
args = API.params(args)
|
62
|
-
.required(:usernames)
|
63
|
-
.to_h
|
69
|
+
args = API.params(args).required(:usernames).to_h
|
64
70
|
put("/admin/groups/#{group_id}/owners.json", group: args)
|
65
71
|
end
|
66
72
|
|
67
73
|
def group_remove_owners(group_id, args)
|
68
|
-
args = API.params(args)
|
69
|
-
.required(:usernames)
|
70
|
-
.to_h
|
74
|
+
args = API.params(args).required(:usernames).to_h
|
71
75
|
delete("/admin/groups/#{group_id}/owners.json", group: args)
|
72
76
|
end
|
73
77
|
|
74
78
|
def groups(args = {})
|
75
|
-
params = API.params(args)
|
76
|
-
.optional(:page)
|
77
|
-
.to_h
|
79
|
+
params = API.params(args).optional(:page).to_h
|
78
80
|
|
79
81
|
url = "/groups.json"
|
80
|
-
if params.include?(:page)
|
81
|
-
url += "?page=#{params[:page]}"
|
82
|
-
end
|
82
|
+
url += "?page=#{params[:page]}" if params.include?(:page)
|
83
83
|
response = get(url)
|
84
84
|
response.body
|
85
85
|
end
|
@@ -92,12 +92,10 @@ module DiscourseApi
|
|
92
92
|
def group_add(group_id, users)
|
93
93
|
users.keys.each do |key|
|
94
94
|
# Accept arrays and convert to comma-delimited string.
|
95
|
-
if users[key].respond_to? :join
|
96
|
-
users[key] = users[key].join(",")
|
97
|
-
end
|
95
|
+
users[key] = users[key].join(",") if users[key].respond_to? :join
|
98
96
|
|
99
97
|
# Accept non-plural user_id or username, but send pluralized version in the request.
|
100
|
-
if key.to_s[-1] !=
|
98
|
+
if key.to_s[-1] != "s"
|
101
99
|
users["#{key}s"] = users[key]
|
102
100
|
users.delete(key)
|
103
101
|
end
|
@@ -109,12 +107,10 @@ module DiscourseApi
|
|
109
107
|
def group_remove(group_id, users)
|
110
108
|
users.keys.each do |key|
|
111
109
|
# Accept arrays and convert to comma-delimited string.
|
112
|
-
if users[key].respond_to? :join
|
113
|
-
users[key] = users[key].join(",")
|
114
|
-
end
|
110
|
+
users[key] = users[key].join(",") if users[key].respond_to? :join
|
115
111
|
|
116
112
|
# Accept non-plural user_id or username, but send pluralized version in the request.
|
117
|
-
if key.to_s[-1] !=
|
113
|
+
if key.to_s[-1] != "s"
|
118
114
|
users["#{key}s"] = users[key]
|
119
115
|
users.delete(key)
|
120
116
|
end
|
@@ -129,21 +125,20 @@ module DiscourseApi
|
|
129
125
|
|
130
126
|
def group_members(group_name, params = {})
|
131
127
|
options = params
|
132
|
-
params = API.params(params)
|
133
|
-
.optional(:offset, :limit)
|
134
|
-
.default(offset: 0, limit: 100)
|
135
|
-
.to_h
|
128
|
+
params = API.params(params).optional(:offset, :limit).default(offset: 0, limit: 100).to_h
|
136
129
|
response = get("/groups/#{group_name}/members.json", params)
|
137
130
|
|
138
131
|
if options[:all] == true
|
139
132
|
response.body
|
140
133
|
else
|
141
|
-
response.body[
|
134
|
+
response.body["members"]
|
142
135
|
end
|
143
136
|
end
|
144
137
|
|
145
138
|
def group_set_user_notification_level(group, user_id, notification_level)
|
146
|
-
post(
|
139
|
+
post(
|
140
|
+
"/groups/#{group}/notifications?user_id=#{user_id}¬ification_level=#{notification_level}",
|
141
|
+
)
|
147
142
|
end
|
148
143
|
end
|
149
144
|
end
|
@@ -3,34 +3,31 @@ module DiscourseApi
|
|
3
3
|
module API
|
4
4
|
module Invite
|
5
5
|
def invite_user(params = {})
|
6
|
-
args =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
args =
|
7
|
+
API
|
8
|
+
.params(params)
|
9
|
+
.optional(
|
10
|
+
:email,
|
11
|
+
:skip_email,
|
12
|
+
:custom_message,
|
13
|
+
:max_redemptions_allowed,
|
14
|
+
:topic_id,
|
15
|
+
:group_ids,
|
16
|
+
:expires_at,
|
17
|
+
)
|
18
|
+
.to_h
|
16
19
|
|
17
20
|
post("/invites", args)
|
18
21
|
end
|
19
22
|
|
20
23
|
# TODO: Deprecated. Remove after 20220506
|
21
24
|
def invite_user_to_topic(params = {})
|
22
|
-
deprecated(__method__,
|
25
|
+
deprecated(__method__, "invite_to_topic")
|
23
26
|
invite_to_topic(params[:topic_id], params)
|
24
27
|
end
|
25
28
|
|
26
29
|
def invite_to_topic(topic_id, params = {})
|
27
|
-
args = API.params(params)
|
28
|
-
.optional(
|
29
|
-
:email,
|
30
|
-
:user,
|
31
|
-
:group_ids,
|
32
|
-
:custom_message
|
33
|
-
).to_h
|
30
|
+
args = API.params(params).optional(:email, :user, :group_ids, :custom_message).to_h
|
34
31
|
|
35
32
|
post("/t/#{topic_id}/invite", args)
|
36
33
|
end
|
@@ -49,17 +46,20 @@ module DiscourseApi
|
|
49
46
|
end
|
50
47
|
|
51
48
|
def update_invite(invite_id, params = {})
|
52
|
-
args =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
args =
|
50
|
+
API
|
51
|
+
.params(params)
|
52
|
+
.optional(
|
53
|
+
:topic_id,
|
54
|
+
:group_ids,
|
55
|
+
:group_names,
|
56
|
+
:email,
|
57
|
+
:send_email,
|
58
|
+
:custom_message,
|
59
|
+
:max_redemptions_allowed,
|
60
|
+
:expires_at,
|
61
|
+
)
|
62
|
+
.to_h
|
63
63
|
|
64
64
|
put("invites/#{invite_id}", args)
|
65
65
|
end
|
@@ -73,7 +73,7 @@ module DiscourseApi
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def resend_invite(email)
|
76
|
-
post("invites/reinvite", {
|
76
|
+
post("invites/reinvite", { email: email })
|
77
77
|
end
|
78
78
|
|
79
79
|
def destroy_invite(invite_id)
|
@@ -3,10 +3,9 @@ module DiscourseApi
|
|
3
3
|
module API
|
4
4
|
module Notifications
|
5
5
|
def notifications(params = {})
|
6
|
-
params = API.params(params)
|
7
|
-
.optional(:username, :recent, :limit, :offset, :filter)
|
6
|
+
params = API.params(params).optional(:username, :recent, :limit, :offset, :filter)
|
8
7
|
|
9
|
-
response = get(
|
8
|
+
response = get("/notifications.json", params)
|
10
9
|
response[:body]
|
11
10
|
end
|
12
11
|
end
|
@@ -28,31 +28,21 @@ module DiscourseApi
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def default(args)
|
31
|
-
args.each
|
32
|
-
@defaults[k] = v
|
33
|
-
end
|
31
|
+
args.each { |k, v| @defaults[k] = v }
|
34
32
|
self
|
35
33
|
end
|
36
34
|
|
37
35
|
def to_h
|
38
36
|
h = {}
|
39
37
|
|
40
|
-
@required.each
|
41
|
-
h[k] = @args[k]
|
42
|
-
end
|
38
|
+
@required.each { |k| h[k] = @args[k] }
|
43
39
|
|
44
|
-
@optional.each
|
45
|
-
h[k] = @args[k] if @args.include?(k)
|
46
|
-
end
|
40
|
+
@optional.each { |k| h[k] = @args[k] if @args.include?(k) }
|
47
41
|
|
48
|
-
@defaults.each
|
49
|
-
@args.key?(k) ? h[k] = @args[k] : h[k] = v
|
50
|
-
end
|
42
|
+
@defaults.each { |k, v| @args.key?(k) ? h[k] = @args[k] : h[k] = v }
|
51
43
|
|
52
44
|
h
|
53
|
-
|
54
45
|
end
|
55
46
|
end
|
56
|
-
|
57
47
|
end
|
58
48
|
end
|
@@ -4,28 +4,25 @@ module DiscourseApi
|
|
4
4
|
module API
|
5
5
|
module Polls
|
6
6
|
def poll_vote(args)
|
7
|
-
args = API.params(args)
|
8
|
-
.required(:post_id, :poll_name, :options)
|
9
|
-
.optional(:created_at)
|
7
|
+
args = API.params(args).required(:post_id, :poll_name, :options).optional(:created_at)
|
10
8
|
put("/polls/vote", args)
|
11
9
|
end
|
12
10
|
|
13
11
|
def toggle_poll_status(args)
|
14
|
-
args =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
args =
|
13
|
+
API
|
14
|
+
.params(args)
|
15
|
+
.required(:post_id, :poll_name, :status)
|
16
|
+
.optional(:api_username)
|
17
|
+
.optional(:raise_errors)
|
18
|
+
put("/polls/toggle_status", args)
|
19
19
|
end
|
20
20
|
|
21
21
|
def poll_voters(args)
|
22
|
-
args = API.params(args)
|
23
|
-
.required(:post_id, :poll_name)
|
24
|
-
.optional(:opts)
|
22
|
+
args = API.params(args).required(:post_id, :poll_name).optional(:opts)
|
25
23
|
response = get("/polls/voters.json", args)
|
26
24
|
response[:body]
|
27
25
|
end
|
28
|
-
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
@@ -3,21 +3,17 @@ module DiscourseApi
|
|
3
3
|
module API
|
4
4
|
module Posts
|
5
5
|
def create_post(args)
|
6
|
-
args = API.params(args)
|
7
|
-
.required(:topic_id, :raw)
|
8
|
-
.optional(:created_at, :api_username)
|
6
|
+
args = API.params(args).required(:topic_id, :raw).optional(:created_at, :api_username)
|
9
7
|
post("/posts", args)
|
10
8
|
end
|
11
9
|
|
12
10
|
def create_post_action(args)
|
13
|
-
args = API.params(args)
|
14
|
-
.required(:id, :post_action_type_id)
|
11
|
+
args = API.params(args).required(:id, :post_action_type_id)
|
15
12
|
post("/post_actions", args.to_h.merge(flag_topic: false))
|
16
13
|
end
|
17
14
|
|
18
15
|
def get_post(id, args = {})
|
19
|
-
args = API.params(args)
|
20
|
-
.optional(:version)
|
16
|
+
args = API.params(args).optional(:version)
|
21
17
|
response = get("/posts/#{id}.json", args)
|
22
18
|
response[:body]
|
23
19
|
end
|
@@ -45,7 +41,8 @@ module DiscourseApi
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def post_action_users(post_id, post_action_type_id)
|
48
|
-
response =
|
44
|
+
response =
|
45
|
+
get("/post_action_users.json", id: post_id, post_action_type_id: post_action_type_id)
|
49
46
|
response[:body]
|
50
47
|
end
|
51
48
|
end
|
@@ -2,10 +2,9 @@
|
|
2
2
|
module DiscourseApi
|
3
3
|
module API
|
4
4
|
module PrivateMessages
|
5
|
-
|
6
5
|
# TODO: Deprecated. Remove after 20220628
|
7
6
|
def create_private_message(args = {})
|
8
|
-
deprecated(__method__,
|
7
|
+
deprecated(__method__, "create_pm")
|
9
8
|
args[:target_recipients] = args.delete :target_usernames
|
10
9
|
create_pm(args.to_h)
|
11
10
|
end
|
@@ -14,21 +13,23 @@ module DiscourseApi
|
|
14
13
|
# :category OPTIONAL name of category, not ID
|
15
14
|
# :created_at OPTIONAL seconds since epoch.
|
16
15
|
def create_pm(args = {})
|
17
|
-
args[:archetype] =
|
18
|
-
args =
|
19
|
-
|
20
|
-
|
16
|
+
args[:archetype] = "private_message"
|
17
|
+
args =
|
18
|
+
API
|
19
|
+
.params(args)
|
20
|
+
.required(:title, :raw, :target_recipients, :archetype)
|
21
|
+
.optional(:category, :created_at, :api_username)
|
21
22
|
post("/posts", args.to_h)
|
22
23
|
end
|
23
24
|
|
24
25
|
def private_messages(username, *args)
|
25
26
|
response = get("topics/private-messages/#{username}.json", args)
|
26
|
-
response[:body][
|
27
|
+
response[:body]["topic_list"]["topics"]
|
27
28
|
end
|
28
29
|
|
29
30
|
def sent_private_messages(username, *args)
|
30
31
|
response = get("topics/private-messages-sent/#{username}.json", args)
|
31
|
-
response[:body][
|
32
|
+
response[:body]["topic_list"]["topics"]
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -10,9 +10,9 @@ module DiscourseApi
|
|
10
10
|
# @return [Array] Return results as an array of Hashes.
|
11
11
|
def search(term, options = {})
|
12
12
|
raise ArgumentError.new("#{term} is required but not specified") unless term
|
13
|
-
raise ArgumentError.new("#{term} is required but not specified")
|
13
|
+
raise ArgumentError.new("#{term} is required but not specified") if term.empty?
|
14
14
|
|
15
|
-
response = get(
|
15
|
+
response = get("/search", options.merge(q: term))
|
16
16
|
response[:body]
|
17
17
|
end
|
18
18
|
end
|
@@ -7,15 +7,16 @@ module DiscourseApi
|
|
7
7
|
# :auto_track OPTIONAL boolean
|
8
8
|
# :created_at OPTIONAL seconds since epoch.
|
9
9
|
def create_topic(args = {})
|
10
|
-
args =
|
11
|
-
|
12
|
-
|
10
|
+
args =
|
11
|
+
API
|
12
|
+
.params(args)
|
13
|
+
.required(:title, :raw)
|
14
|
+
.optional(:skip_validations, :category, :auto_track, :created_at, :api_username, :tags)
|
13
15
|
post("/posts", args.to_h)
|
14
16
|
end
|
15
17
|
|
16
18
|
def create_topic_action(args)
|
17
|
-
args = API.params(args)
|
18
|
-
.required(:id, :post_action_type_id)
|
19
|
+
args = API.params(args).required(:id, :post_action_type_id)
|
19
20
|
post("/post_actions", args.to_h.merge(flag_topic: true))
|
20
21
|
end
|
21
22
|
|
@@ -25,18 +26,18 @@ module DiscourseApi
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def latest_topics(params = {})
|
28
|
-
response = get(
|
29
|
-
response[:body][
|
29
|
+
response = get("/latest.json", params)
|
30
|
+
response[:body]["topic_list"]["topics"]
|
30
31
|
end
|
31
32
|
|
32
33
|
def top_topics(params = {})
|
33
34
|
response = get("/top.json", params)
|
34
|
-
response[:body][
|
35
|
+
response[:body]["topic_list"]["topics"]
|
35
36
|
end
|
36
37
|
|
37
38
|
def new_topics(params = {})
|
38
39
|
response = get("/new.json", params)
|
39
|
-
response[:body][
|
40
|
+
response[:body]["topic_list"]["topics"]
|
40
41
|
end
|
41
42
|
|
42
43
|
def rename_topic(topic_id, title)
|
@@ -49,14 +50,12 @@ module DiscourseApi
|
|
49
50
|
|
50
51
|
# TODO: Deprecated. Remove after 20201231
|
51
52
|
def change_topic_status(topic_slug, topic_id, params = {})
|
52
|
-
deprecated(__method__,
|
53
|
+
deprecated(__method__, "update_topic_status")
|
53
54
|
update_topic_status(topic_id, params)
|
54
55
|
end
|
55
56
|
|
56
57
|
def update_topic_status(topic_id, params = {})
|
57
|
-
params = API.params(params)
|
58
|
-
.required(:status, :enabled)
|
59
|
-
.optional(:api_username)
|
58
|
+
params = API.params(params).required(:status, :enabled).optional(:api_username)
|
60
59
|
put("/t/#{topic_id}/status", params)
|
61
60
|
end
|
62
61
|
|
@@ -67,7 +66,7 @@ module DiscourseApi
|
|
67
66
|
|
68
67
|
def topics_by(username, params = {})
|
69
68
|
response = get("/topics/created-by/#{username}.json", params)
|
70
|
-
response[:body][
|
69
|
+
response[:body]["topic_list"]["topics"]
|
71
70
|
end
|
72
71
|
|
73
72
|
def delete_topic(id)
|
@@ -75,8 +74,9 @@ module DiscourseApi
|
|
75
74
|
end
|
76
75
|
|
77
76
|
def topic_posts(topic_id, post_ids = [], params = {})
|
78
|
-
params =
|
79
|
-
.optional(
|
77
|
+
params =
|
78
|
+
API.params(params).optional(
|
79
|
+
:asc,
|
80
80
|
:filter,
|
81
81
|
:include_raw,
|
82
82
|
:include_suggested,
|
@@ -86,23 +86,21 @@ module DiscourseApi
|
|
86
86
|
|
87
87
|
url = ["/t/#{topic_id}/posts.json"]
|
88
88
|
if post_ids.count > 0
|
89
|
-
url.push(
|
90
|
-
url.push(post_ids.map { |id| "post_ids[]=#{id}" }.join(
|
89
|
+
url.push("?")
|
90
|
+
url.push(post_ids.map { |id| "post_ids[]=#{id}" }.join("&"))
|
91
91
|
end
|
92
92
|
response = get(url.join, params)
|
93
93
|
response[:body]
|
94
94
|
end
|
95
95
|
|
96
96
|
def change_owner(topic_id, params = {})
|
97
|
-
params = API.params(params)
|
98
|
-
.required(:username, :post_ids)
|
97
|
+
params = API.params(params).required(:username, :post_ids)
|
99
98
|
|
100
99
|
post("/t/#{topic_id}/change-owner.json", params)
|
101
100
|
end
|
102
101
|
|
103
102
|
def topic_set_user_notification_level(topic_id, params)
|
104
|
-
params = API.params(params)
|
105
|
-
.required(:notification_level)
|
103
|
+
params = API.params(params).required(:notification_level)
|
106
104
|
post("/t/#{topic_id}/notifications", params)
|
107
105
|
end
|
108
106
|
|
@@ -3,11 +3,13 @@ module DiscourseApi
|
|
3
3
|
module API
|
4
4
|
module Uploads
|
5
5
|
def upload_file(args)
|
6
|
-
args =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
args =
|
7
|
+
API
|
8
|
+
.params(args)
|
9
|
+
.optional(:file, :url, :user_id)
|
10
|
+
.default(type: "composer", synchronous: true)
|
11
|
+
.to_h
|
12
|
+
post("/uploads", args)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -3,13 +3,13 @@ module DiscourseApi
|
|
3
3
|
module API
|
4
4
|
module UserActions
|
5
5
|
def user_replies(username)
|
6
|
-
params = {
|
6
|
+
params = { username: username, filter: "5" }
|
7
7
|
response = get("/user_actions.json", params)
|
8
8
|
response.body["user_actions"]
|
9
9
|
end
|
10
10
|
|
11
11
|
def user_topics_and_replies(username)
|
12
|
-
params = {
|
12
|
+
params = { username: username, filter: "4,5" }
|
13
13
|
response = get("/user_actions.json", params)
|
14
14
|
response.body["user_actions"]
|
15
15
|
end
|