discourse_api 2.0.1 → 2.1.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/.github/workflows/ci.yml +6 -6
- data/.rubocop.yml +3 -0
- data/.streerc +1 -1
- data/CHANGELOG.md +10 -0
- data/config_example.yml +1 -1
- data/discourse_api.gemspec +36 -31
- data/lib/discourse_api/api/categories.rb +45 -54
- data/lib/discourse_api/api/topics.rb +13 -1
- data/lib/discourse_api/single_sign_on.rb +3 -3
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +11 -11
- data/spec/discourse_api/api/backups_spec.rb +3 -3
- data/spec/discourse_api/api/badges_spec.rb +5 -5
- data/spec/discourse_api/api/categories_spec.rb +37 -15
- data/spec/discourse_api/api/email_spec.rb +5 -5
- data/spec/discourse_api/api/groups_spec.rb +17 -17
- data/spec/discourse_api/api/invite_spec.rb +11 -11
- data/spec/discourse_api/api/notifications_spec.rb +3 -3
- data/spec/discourse_api/api/polls_spec.rb +7 -7
- data/spec/discourse_api/api/posts_spec.rb +1 -3
- data/spec/discourse_api/api/private_messages_spec.rb +6 -6
- data/spec/discourse_api/api/search_spec.rb +5 -5
- data/spec/discourse_api/api/site_settings_spec.rb +2 -2
- data/spec/discourse_api/api/sso_spec.rb +3 -3
- data/spec/discourse_api/api/topics_spec.rb +32 -32
- data/spec/discourse_api/api/uploads_spec.rb +3 -3
- data/spec/discourse_api/api/user_actions_spec.rb +5 -5
- data/spec/discourse_api/api/users_spec.rb +51 -51
- data/spec/discourse_api/client_spec.rb +33 -33
- data/spec/discourse_api/single_sign_on_spec.rb +23 -6
- data/spec/spec_helper.rb +1 -0
- metadata +9 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b5410419d12b39c4cfce5fcf10660b377de6b33ed493b9d65cb2adbb7c077e4
|
|
4
|
+
data.tar.gz: 8a763251cd8d55335d8d4233923e93f9e17449b326f709d5d7561e9c7207926e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 48ee6f9f4814add51b8d574902410ec7b2e7a3c60c913816633f12412e21378fceeae8edce513df44d36222fcbbcf8d0eaf82adae94addf2626718306362ad05
|
|
7
|
+
data.tar.gz: 49ae595660f7662be7a9bbd881034b43f316265b7ed26de294152887b1e9ef002061b635f021b030a7f2f4c48a5eee129ce75389a1e23c0269575729335b3937
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -10,12 +10,12 @@ jobs:
|
|
|
10
10
|
lint:
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
steps:
|
|
13
|
-
- uses: actions/checkout@
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
14
|
|
|
15
15
|
- name: Setup ruby
|
|
16
16
|
uses: ruby/setup-ruby@v1
|
|
17
17
|
with:
|
|
18
|
-
ruby-version:
|
|
18
|
+
ruby-version: "3.3"
|
|
19
19
|
bundler-cache: true
|
|
20
20
|
|
|
21
21
|
- name: Rubocop
|
|
@@ -32,10 +32,10 @@ jobs:
|
|
|
32
32
|
|
|
33
33
|
strategy:
|
|
34
34
|
matrix:
|
|
35
|
-
ruby: [
|
|
35
|
+
ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
|
|
36
36
|
|
|
37
37
|
steps:
|
|
38
|
-
- uses: actions/checkout@
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
39
|
|
|
40
40
|
- name: Setup ruby
|
|
41
41
|
uses: ruby/setup-ruby@v1
|
|
@@ -52,10 +52,10 @@ jobs:
|
|
|
52
52
|
runs-on: ubuntu-latest
|
|
53
53
|
|
|
54
54
|
steps:
|
|
55
|
-
- uses: actions/checkout@
|
|
55
|
+
- uses: actions/checkout@v4
|
|
56
56
|
|
|
57
57
|
- name: Release Gem
|
|
58
|
-
uses: discourse/publish-rubygems-action@
|
|
58
|
+
uses: discourse/publish-rubygems-action@v3
|
|
59
59
|
env:
|
|
60
60
|
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
|
61
61
|
GIT_EMAIL: team@discourse.org
|
data/.rubocop.yml
CHANGED
data/.streerc
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
--print-width=100
|
|
2
|
-
--plugins=plugin/trailing_comma,
|
|
2
|
+
--plugins=plugin/trailing_comma,plugin/disable_auto_ternary
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [2.1.0] - 2025-12-02
|
|
10
|
+
### Changed
|
|
11
|
+
- Add support for `external_id` in topic creation
|
|
12
|
+
### Added
|
|
13
|
+
- Add get topic url by `external_id`
|
|
14
|
+
|
|
15
|
+
## [2.0.1] - 2023-06-09
|
|
16
|
+
### Removed
|
|
17
|
+
- Invite admin method removed
|
|
18
|
+
|
|
9
19
|
## [2.0.0] - 2023-05-26
|
|
10
20
|
### Changed
|
|
11
21
|
- The package now requires ruby 2.7+
|
data/config_example.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Specify your environment by making a copy of this file to create a file in your root directory called config.yml with your environment settings.
|
|
2
2
|
|
|
3
|
-
# host e.g. localhost:3000 or discourse.my_domain.com
|
|
3
|
+
# host e.g. http://localhost:3000 or https://discourse.my_domain.com
|
|
4
4
|
host: YOUR_HOST_NAME
|
|
5
5
|
|
|
6
6
|
# api user (can effect results returned, e.g. .categories method returns only the categories your api_username can see)
|
data/discourse_api.gemspec
CHANGED
|
@@ -1,39 +1,44 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) if !$LOAD_PATH.include?(lib)
|
|
5
|
+
require "discourse_api/version"
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name
|
|
8
|
-
spec.version
|
|
9
|
-
spec.authors
|
|
10
|
-
spec.email
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
spec.name = "discourse_api"
|
|
9
|
+
spec.version = DiscourseApi::VERSION
|
|
10
|
+
spec.authors = ["Sam Saffron", "John Paul Ashenfelter", "Michael Herold", "Blake Erickson"]
|
|
11
|
+
spec.email = %w[
|
|
12
|
+
sam.saffron@gmail.com
|
|
13
|
+
john@ashenfelter.com
|
|
14
|
+
michael.j.herold@gmail.com
|
|
15
|
+
o.blakeerickson@gmail.com
|
|
16
|
+
]
|
|
17
|
+
spec.description = "Discourse API"
|
|
18
|
+
spec.summary = "Allows access to the Discourse API"
|
|
19
|
+
spec.homepage = "http://github.com/discourse/discourse_api"
|
|
20
|
+
spec.license = "MIT"
|
|
15
21
|
|
|
16
|
-
spec.files
|
|
17
|
-
spec.executables
|
|
18
|
-
spec.test_files
|
|
19
|
-
spec.require_paths = [
|
|
22
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
25
|
+
spec.require_paths = ["lib"]
|
|
20
26
|
|
|
21
|
-
spec.add_runtime_dependency
|
|
22
|
-
spec.add_runtime_dependency
|
|
23
|
-
spec.add_runtime_dependency
|
|
24
|
-
spec.add_runtime_dependency
|
|
27
|
+
spec.add_runtime_dependency "faraday", "~> 2.7"
|
|
28
|
+
spec.add_runtime_dependency "faraday-follow_redirects"
|
|
29
|
+
spec.add_runtime_dependency "faraday-multipart"
|
|
30
|
+
spec.add_runtime_dependency "rack", ">= 1.6"
|
|
25
31
|
|
|
26
|
-
spec.add_development_dependency
|
|
27
|
-
spec.add_development_dependency
|
|
28
|
-
spec.add_development_dependency
|
|
29
|
-
spec.add_development_dependency
|
|
30
|
-
spec.add_development_dependency
|
|
31
|
-
spec.add_development_dependency
|
|
32
|
-
spec.add_development_dependency
|
|
33
|
-
spec.add_development_dependency
|
|
34
|
-
spec.add_development_dependency
|
|
35
|
-
spec.add_development_dependency
|
|
36
|
-
spec.add_development_dependency 'syntax_tree-disable_ternary', '~> 1.0.0'
|
|
32
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
33
|
+
spec.add_development_dependency "guard", "~> 2.14"
|
|
34
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
|
35
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
|
36
|
+
spec.add_development_dependency "rb-inotify", "~> 0.9"
|
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
|
38
|
+
spec.add_development_dependency "simplecov", "~> 0.11"
|
|
39
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
|
40
|
+
spec.add_development_dependency "rubocop-discourse", "= 3.8.1"
|
|
41
|
+
spec.add_development_dependency "syntax_tree", "~> 6.2.0"
|
|
37
42
|
|
|
38
|
-
spec.required_ruby_version =
|
|
43
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
39
44
|
end
|
|
@@ -6,68 +6,23 @@ module DiscourseApi
|
|
|
6
6
|
# :permissions is a hash with the group name and permission_type which is
|
|
7
7
|
# an integer 1 = Full 2 = Create Post 3 = Read Only
|
|
8
8
|
def create_category(args = {})
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.params(args)
|
|
12
|
-
.required(:name, :color, :text_color)
|
|
13
|
-
.optional(
|
|
14
|
-
:slug,
|
|
15
|
-
:permissions,
|
|
16
|
-
:auto_close_hours,
|
|
17
|
-
:auto_close_based_on_last_post,
|
|
18
|
-
:position,
|
|
19
|
-
:email_in,
|
|
20
|
-
:email_in_allow_strangers,
|
|
21
|
-
:logo_url,
|
|
22
|
-
:background_url,
|
|
23
|
-
:allow_badges,
|
|
24
|
-
:topic_template,
|
|
25
|
-
:custom_fields,
|
|
26
|
-
:description,
|
|
27
|
-
:reviewable_by_group_name,
|
|
28
|
-
:show_subcategory_list,
|
|
29
|
-
:subcategory_list_style,
|
|
30
|
-
:allowed_tags,
|
|
31
|
-
:allowed_tag_groups,
|
|
32
|
-
:required_tag_group_name,
|
|
33
|
-
)
|
|
34
|
-
.default(parent_category_id: nil)
|
|
35
|
-
response = post("/categories", args)
|
|
9
|
+
params = common_category_params(args)
|
|
10
|
+
response = post("/categories", params.to_h)
|
|
36
11
|
response["category"]
|
|
37
12
|
end
|
|
38
13
|
|
|
39
14
|
def update_category(args = {})
|
|
40
15
|
category_id = args[:id]
|
|
41
|
-
args
|
|
42
|
-
|
|
43
|
-
.params(args)
|
|
44
|
-
.required(:id, :name, :color, :text_color)
|
|
45
|
-
.optional(
|
|
46
|
-
:slug,
|
|
47
|
-
:permissions,
|
|
48
|
-
:auto_close_hours,
|
|
49
|
-
:auto_close_based_on_last_post,
|
|
50
|
-
:position,
|
|
51
|
-
:email_in,
|
|
52
|
-
:email_in_allow_strangers,
|
|
53
|
-
:logo_url,
|
|
54
|
-
:background_url,
|
|
55
|
-
:allow_badges,
|
|
56
|
-
:topic_template,
|
|
57
|
-
:custom_fields,
|
|
58
|
-
:description,
|
|
59
|
-
:reviewable_by_group_name,
|
|
60
|
-
:show_subcategory_list,
|
|
61
|
-
:subcategory_list_style,
|
|
62
|
-
:allowed_tags,
|
|
63
|
-
:allowed_tag_groups,
|
|
64
|
-
:required_tag_group_name,
|
|
65
|
-
)
|
|
66
|
-
.default(parent_category_id: nil)
|
|
67
|
-
response = put("/categories/#{category_id}", args)
|
|
16
|
+
params = common_category_params(args, include_id: true)
|
|
17
|
+
response = put("/categories/#{category_id}", params.to_h)
|
|
68
18
|
response["body"]["category"] if response["body"]
|
|
69
19
|
end
|
|
70
20
|
|
|
21
|
+
def reorder_categories(args = {})
|
|
22
|
+
params = API.params(args).required(:mapping)
|
|
23
|
+
post("/categories/reorder", params)
|
|
24
|
+
end
|
|
25
|
+
|
|
71
26
|
def delete_category(id)
|
|
72
27
|
response = delete("/categories/#{id}")
|
|
73
28
|
response[:body]["success"]
|
|
@@ -139,6 +94,42 @@ module DiscourseApi
|
|
|
139
94
|
params = API.params(params).required(:notification_level)
|
|
140
95
|
post("/category/#{category_id}/notifications", params)
|
|
141
96
|
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def common_category_params(args, include_id: false)
|
|
101
|
+
params = API.params(args)
|
|
102
|
+
params = params.required(:id) if include_id
|
|
103
|
+
params
|
|
104
|
+
.required(:name)
|
|
105
|
+
.optional(
|
|
106
|
+
:color,
|
|
107
|
+
:text_color,
|
|
108
|
+
:slug,
|
|
109
|
+
:permissions,
|
|
110
|
+
:auto_close_hours,
|
|
111
|
+
:auto_close_based_on_last_post,
|
|
112
|
+
:position,
|
|
113
|
+
:email_in,
|
|
114
|
+
:email_in_allow_strangers,
|
|
115
|
+
:logo_url,
|
|
116
|
+
:background_url,
|
|
117
|
+
:allow_badges,
|
|
118
|
+
:topic_template,
|
|
119
|
+
:custom_fields,
|
|
120
|
+
:description,
|
|
121
|
+
:reviewable_by_group_name,
|
|
122
|
+
:show_subcategory_list,
|
|
123
|
+
:subcategory_list_style,
|
|
124
|
+
:allowed_tags,
|
|
125
|
+
:allowed_tag_groups,
|
|
126
|
+
:required_tag_group_name,
|
|
127
|
+
:topic_featured_links_allowed,
|
|
128
|
+
:search_priority,
|
|
129
|
+
:form_template_ids,
|
|
130
|
+
)
|
|
131
|
+
.default(parent_category_id: nil)
|
|
132
|
+
end
|
|
142
133
|
end
|
|
143
134
|
end
|
|
144
135
|
end
|
|
@@ -11,7 +11,15 @@ module DiscourseApi
|
|
|
11
11
|
API
|
|
12
12
|
.params(args)
|
|
13
13
|
.required(:title, :raw)
|
|
14
|
-
.optional(
|
|
14
|
+
.optional(
|
|
15
|
+
:skip_validations,
|
|
16
|
+
:category,
|
|
17
|
+
:auto_track,
|
|
18
|
+
:created_at,
|
|
19
|
+
:api_username,
|
|
20
|
+
:tags,
|
|
21
|
+
:external_id,
|
|
22
|
+
)
|
|
15
23
|
post("/posts", args.to_h)
|
|
16
24
|
end
|
|
17
25
|
|
|
@@ -111,6 +119,10 @@ module DiscourseApi
|
|
|
111
119
|
def remove_topic_bookmark(topic_id)
|
|
112
120
|
put("/t/#{topic_id}/remove_bookmarks.json")
|
|
113
121
|
end
|
|
122
|
+
|
|
123
|
+
def get_topic_url_by_external_id(external_id)
|
|
124
|
+
get("/t/external_id/#{external_id}")
|
|
125
|
+
end
|
|
114
126
|
end
|
|
115
127
|
end
|
|
116
128
|
end
|
|
@@ -98,10 +98,10 @@ module DiscourseApi
|
|
|
98
98
|
sso.sso_secret = sso_secret if sso_secret
|
|
99
99
|
|
|
100
100
|
parsed = Rack::Utils.parse_query(payload)
|
|
101
|
-
if sso.sign(parsed["sso"]) != parsed["sig"]
|
|
101
|
+
if parsed["sso"].nil? || sso.sign(parsed["sso"]) != parsed["sig"]
|
|
102
102
|
diags =
|
|
103
|
-
"\n\nsso: #{parsed["sso"]}\n\nsig: #{parsed["sig"]}\n\nexpected sig: #{sso.sign(parsed
|
|
104
|
-
if parsed["sso"] =~ %r{[^a-zA-Z0-9=\r\n/+]}m
|
|
103
|
+
"\n\nsso: #{parsed["sso"].inspect}\n\nsig: #{parsed["sig"].inspect}\n\nexpected sig: #{sso.sign(parsed.fetch("sso", ""))}"
|
|
104
|
+
if parsed["sso"].nil? || parsed["sso"] =~ %r{[^a-zA-Z0-9=\r\n/+]}m
|
|
105
105
|
raise ParseError,
|
|
106
106
|
"The SSO field should be Base64 encoded, using only A-Z, a-z, 0-9, +, /, and = characters. Your input contains characters we don't understand as Base64, see http://en.wikipedia.org/wiki/Base64 #{diags}"
|
|
107
107
|
else
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::ApiKey do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#list_api_keys" do
|
|
8
8
|
before do
|
|
@@ -16,13 +16,13 @@ describe DiscourseApi::API::ApiKey do
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "requests the correct resource" do
|
|
19
|
-
|
|
19
|
+
client.list_api_keys
|
|
20
20
|
url = "#{host}/admin/api/keys"
|
|
21
21
|
expect(a_get(url)).to have_been_made
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "returns the requested api keys" do
|
|
25
|
-
keys =
|
|
25
|
+
keys = client.list_api_keys
|
|
26
26
|
expect(keys["keys"]).to be_an Array
|
|
27
27
|
expect(keys["keys"].first).to be_a Hash
|
|
28
28
|
expect(keys["keys"].first).to have_key("key")
|
|
@@ -41,13 +41,13 @@ describe DiscourseApi::API::ApiKey do
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "requests the correct resource" do
|
|
44
|
-
|
|
44
|
+
client.create_api_key(key: { username: "robin" })
|
|
45
45
|
url = "#{host}/admin/api/keys"
|
|
46
46
|
expect(a_post(url)).to have_been_made
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "returns the generated api key" do
|
|
50
|
-
api_key =
|
|
50
|
+
api_key = client.create_api_key(key: { username: "robin" })
|
|
51
51
|
expect(api_key).to be_a Hash
|
|
52
52
|
expect(api_key["key"]).to have_key("key")
|
|
53
53
|
end
|
|
@@ -65,13 +65,13 @@ describe DiscourseApi::API::ApiKey do
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "requests the correct resource" do
|
|
68
|
-
|
|
68
|
+
client.revoke_api_key(10)
|
|
69
69
|
url = "#{host}/admin/api/keys/10/revoke"
|
|
70
70
|
expect(a_post(url)).to have_been_made
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "returns the api key" do
|
|
74
|
-
api_key =
|
|
74
|
+
api_key = client.revoke_api_key(10)
|
|
75
75
|
expect(api_key["key"]).to have_key("key")
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -88,13 +88,13 @@ describe DiscourseApi::API::ApiKey do
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "requests the correct resource" do
|
|
91
|
-
|
|
91
|
+
client.undo_revoke_api_key(10)
|
|
92
92
|
url = "#{host}/admin/api/keys/10/undo-revoke"
|
|
93
93
|
expect(a_post(url)).to have_been_made
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
it "returns the api key" do
|
|
97
|
-
api_key =
|
|
97
|
+
api_key = client.undo_revoke_api_key(10)
|
|
98
98
|
expect(api_key["key"]).to have_key("key")
|
|
99
99
|
end
|
|
100
100
|
end
|
|
@@ -111,13 +111,13 @@ describe DiscourseApi::API::ApiKey do
|
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
it "requests the correct resource" do
|
|
114
|
-
|
|
114
|
+
client.delete_api_key(10)
|
|
115
115
|
url = "#{host}/admin/api/keys/10"
|
|
116
116
|
expect(a_delete(url)).to have_been_made
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
it "returns 200" do
|
|
120
|
-
response =
|
|
120
|
+
response = client.delete_api_key(10)
|
|
121
121
|
expect(response["status"]).to eq(200)
|
|
122
122
|
end
|
|
123
123
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::Backups do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#backups" do
|
|
8
8
|
before do
|
|
@@ -15,12 +15,12 @@ describe DiscourseApi::API::Backups do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "requests the correct resource" do
|
|
18
|
-
|
|
18
|
+
client.backups
|
|
19
19
|
expect(a_get("#{host}/admin/backups.json")).to have_been_made
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "returns the requested backups" do
|
|
23
|
-
backups =
|
|
23
|
+
backups = client.backups
|
|
24
24
|
expect(backups).to be_an Array
|
|
25
25
|
expect(backups.first).to be_a Hash
|
|
26
26
|
expect(backups.first).to have_key("filename")
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::Badges do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#badges" do
|
|
8
8
|
before do
|
|
@@ -15,12 +15,12 @@ describe DiscourseApi::API::Badges do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "requests the correct resource" do
|
|
18
|
-
|
|
18
|
+
client.badges
|
|
19
19
|
expect(a_get("#{host}/admin/badges.json")).to have_been_made
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "returns the requested badges" do
|
|
23
|
-
badges =
|
|
23
|
+
badges = client.badges
|
|
24
24
|
expect(badges).to be_a Hash
|
|
25
25
|
expect(badges["badges"]).to be_an Array
|
|
26
26
|
end
|
|
@@ -37,12 +37,12 @@ describe DiscourseApi::API::Badges do
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "requests the correct resource" do
|
|
40
|
-
|
|
40
|
+
client.user_badges("test_user")
|
|
41
41
|
expect(a_get("#{host}/user-badges/test_user.json")).to have_been_made
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "returns the requested user badges" do
|
|
45
|
-
badges =
|
|
45
|
+
badges = client.user_badges("test_user")
|
|
46
46
|
expect(badges).to be_an Array
|
|
47
47
|
expect(badges.first).to be_a Hash
|
|
48
48
|
expect(badges.first).to have_key("badge_type_id")
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::Categories do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#categories" do
|
|
8
8
|
before do
|
|
@@ -15,18 +15,18 @@ describe DiscourseApi::API::Categories do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "requests the correct resource" do
|
|
18
|
-
|
|
18
|
+
client.categories
|
|
19
19
|
expect(a_get("#{host}/categories.json")).to have_been_made
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "returns the requested categories" do
|
|
23
|
-
categories =
|
|
23
|
+
categories = client.categories
|
|
24
24
|
expect(categories).to be_an Array
|
|
25
25
|
expect(categories.first).to be_a Hash
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "returns the requested categories with hash arg" do
|
|
29
|
-
categories =
|
|
29
|
+
categories = client.categories({})
|
|
30
30
|
expect(categories).to be_an Array
|
|
31
31
|
expect(categories.first).to be_a Hash
|
|
32
32
|
end
|
|
@@ -43,12 +43,12 @@ describe DiscourseApi::API::Categories do
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "requests the correct resource" do
|
|
46
|
-
|
|
46
|
+
client.categories
|
|
47
47
|
expect(a_get("#{host}/categories.json")).to have_been_made
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "returns the entire categories response" do
|
|
51
|
-
categories =
|
|
51
|
+
categories = client.categories_full
|
|
52
52
|
expect(categories).to be_a Hash
|
|
53
53
|
expect(categories).to have_key "category_list"
|
|
54
54
|
expect(categories).to have_key "featured_users"
|
|
@@ -66,7 +66,7 @@ describe DiscourseApi::API::Categories do
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
it "returns the latest topics in a category" do
|
|
69
|
-
latest_topics =
|
|
69
|
+
latest_topics = client.category_latest_topics(category_slug: "category-slug")
|
|
70
70
|
expect(latest_topics).to be_an Array
|
|
71
71
|
end
|
|
72
72
|
end
|
|
@@ -82,7 +82,7 @@ describe DiscourseApi::API::Categories do
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it "returns the entire latest topics in a category response" do
|
|
85
|
-
latest_topics =
|
|
85
|
+
latest_topics = client.category_latest_topics_full(category_slug: "category-slug")
|
|
86
86
|
expect(latest_topics).to be_a Hash
|
|
87
87
|
expect(latest_topics).to have_key "topic_list"
|
|
88
88
|
expect(latest_topics).to have_key "users"
|
|
@@ -100,7 +100,7 @@ describe DiscourseApi::API::Categories do
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
it "returns the top topics in a category" do
|
|
103
|
-
topics =
|
|
103
|
+
topics = client.category_top_topics("category-slug")
|
|
104
104
|
expect(topics).to be_an Array
|
|
105
105
|
end
|
|
106
106
|
end
|
|
@@ -116,7 +116,7 @@ describe DiscourseApi::API::Categories do
|
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "returns the entire top topics in a category response" do
|
|
119
|
-
topics =
|
|
119
|
+
topics = client.category_top_topics_full("category-slug")
|
|
120
120
|
expect(topics).to be_a Hash
|
|
121
121
|
expect(topics).to have_key "topic_list"
|
|
122
122
|
expect(topics).to have_key "users"
|
|
@@ -134,7 +134,7 @@ describe DiscourseApi::API::Categories do
|
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
it "returns the new topics in a category" do
|
|
137
|
-
topics =
|
|
137
|
+
topics = client.category_new_topics("category-slug")
|
|
138
138
|
expect(topics).to be_an Array
|
|
139
139
|
end
|
|
140
140
|
end
|
|
@@ -150,7 +150,7 @@ describe DiscourseApi::API::Categories do
|
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
it "returns the new topics in a category" do
|
|
153
|
-
topics =
|
|
153
|
+
topics = client.category_new_topics_full("category-slug")
|
|
154
154
|
expect(topics).to be_a Hash
|
|
155
155
|
expect(topics).to have_key "topic_list"
|
|
156
156
|
expect(topics).to have_key "users"
|
|
@@ -160,7 +160,7 @@ describe DiscourseApi::API::Categories do
|
|
|
160
160
|
describe "#category_new_category" do
|
|
161
161
|
before do
|
|
162
162
|
stub_post("#{host}/categories")
|
|
163
|
-
|
|
163
|
+
client.create_category(
|
|
164
164
|
name: "test_category",
|
|
165
165
|
color: "283890",
|
|
166
166
|
text_color: "FFFFFF",
|
|
@@ -182,6 +182,28 @@ describe DiscourseApi::API::Categories do
|
|
|
182
182
|
end
|
|
183
183
|
end
|
|
184
184
|
|
|
185
|
+
describe "#reorder_categories" do
|
|
186
|
+
before do
|
|
187
|
+
stub_post("#{host}/categories/reorder").to_return(
|
|
188
|
+
body: fixture("notification_success.json"),
|
|
189
|
+
headers: {
|
|
190
|
+
content_type: "application/json",
|
|
191
|
+
},
|
|
192
|
+
)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it "makes a categories reordering request" do
|
|
196
|
+
payload = { "1": 2, "2": 3, "3": 4, "4": 1 }
|
|
197
|
+
response = client.reorder_categories(mapping: payload.to_json)
|
|
198
|
+
expect(
|
|
199
|
+
a_post("#{host}/categories/reorder").with(
|
|
200
|
+
body: "mapping=#{CGI.escape(payload.to_json.to_s)}",
|
|
201
|
+
),
|
|
202
|
+
).to have_been_made
|
|
203
|
+
expect(response["success"]).to eq("OK")
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
185
207
|
describe "#category_set_user_notification" do
|
|
186
208
|
before do
|
|
187
209
|
stub_post("#{host}/category/1/notifications").to_return(
|
|
@@ -193,7 +215,7 @@ describe DiscourseApi::API::Categories do
|
|
|
193
215
|
end
|
|
194
216
|
|
|
195
217
|
it "makes the post request" do
|
|
196
|
-
response =
|
|
218
|
+
response = client.category_set_user_notification(id: 1, notification_level: 3)
|
|
197
219
|
expect(a_post("#{host}/category/1/notifications")).to have_been_made
|
|
198
220
|
expect(response["success"]).to eq("OK")
|
|
199
221
|
end
|
|
@@ -210,7 +232,7 @@ describe DiscourseApi::API::Categories do
|
|
|
210
232
|
end
|
|
211
233
|
|
|
212
234
|
it "makes the post request" do
|
|
213
|
-
response =
|
|
235
|
+
response = client.category_set_user_notification_level(1, notification_level: 3)
|
|
214
236
|
expect(
|
|
215
237
|
a_post("#{host}/category/1/notifications").with(body: "notification_level=3"),
|
|
216
238
|
).to have_been_made
|