discourse_api 0.43.0 → 0.46.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 +13 -17
- data/.gitignore +0 -19
- data/CHANGELOG.md +35 -5
- data/discourse_api.gemspec +6 -6
- data/examples/bookmark_topic.rb +15 -0
- data/examples/category.rb +3 -0
- data/examples/manage_api_keys.rb +42 -0
- data/examples/notifications.rb +15 -0
- data/examples/topic_lists.rb +3 -0
- data/lib/discourse_api/api/api_key.rb +15 -9
- data/lib/discourse_api/api/categories.rb +41 -13
- data/lib/discourse_api/api/search.rb +1 -1
- data/lib/discourse_api/api/tags.rb +1 -1
- data/lib/discourse_api/api/topics.rb +37 -2
- data/lib/discourse_api/api/users.rb +1 -1
- data/lib/discourse_api/client.rb +13 -1
- data/lib/discourse_api/error.rb +3 -0
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +59 -35
- data/spec/discourse_api/api/categories_spec.rb +90 -0
- data/spec/discourse_api/api/search_spec.rb +2 -2
- data/spec/discourse_api/api/topics_spec.rb +66 -0
- data/spec/discourse_api/client_spec.rb +15 -0
- data/spec/fixtures/api_key.json +12 -0
- data/spec/fixtures/list_api_keys.json +14 -0
- data/spec/fixtures/notification_success.json +3 -0
- data/spec/fixtures/top.json +108 -0
- data/spec/fixtures/topic_posts.json +1 -0
- metadata +21 -14
- data/spec/fixtures/api.json +0 -12
- data/spec/fixtures/generate_master_key.json +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d6fc91bd7fd472cc3eab0fa06b79d0fbaa5e4cf7a2003bef82eee43f33acf4
|
4
|
+
data.tar.gz: c0aef1ea4eee35c3cf3143d100707c2850829e5551c79af3a6d6f76efb3b262c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4227051151b05bd67b403a9922d0199b4cdaf84ccf5973e4be57fb63af8345053b0d80ca763aa2a9c49c27a1a73a623540bde643a714710298c57e73c4a3a0d3
|
7
|
+
data.tar.gz: 5a6dfdc85bf1db5edb7e474ecfa1df038a617ebb4d3bf890611d6e195e3093d441e2dbdb3826ad468cc397e6de420f4d4d295b275ad0febb78fb32ae86dfec8e
|
data/.github/workflows/ci.yml
CHANGED
@@ -5,8 +5,7 @@ on:
|
|
5
5
|
push:
|
6
6
|
branches:
|
7
7
|
- master
|
8
|
-
|
9
|
-
- v*
|
8
|
+
- main
|
10
9
|
|
11
10
|
jobs:
|
12
11
|
build:
|
@@ -18,30 +17,25 @@ jobs:
|
|
18
17
|
- 2.5
|
19
18
|
- 2.6
|
20
19
|
- 2.7
|
20
|
+
- 3.0
|
21
21
|
|
22
22
|
steps:
|
23
|
-
- uses: actions/checkout@
|
23
|
+
- uses: actions/checkout@v2
|
24
24
|
|
25
25
|
- name: Setup ruby
|
26
|
-
uses:
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
27
|
with:
|
28
28
|
ruby-version: ${{ matrix.ruby }}
|
29
|
-
|
30
|
-
|
31
|
-
- name: Setup bundler
|
32
|
-
run: gem install bundler
|
33
|
-
|
34
|
-
- name: Setup gems
|
35
|
-
run: bundle install
|
29
|
+
bundler-cache: true
|
36
30
|
|
37
|
-
- name:
|
31
|
+
- name: Lint
|
38
32
|
run: bundle exec rubocop
|
39
33
|
|
40
|
-
- name:
|
41
|
-
run: bundle exec
|
34
|
+
- name: Tests
|
35
|
+
run: bundle exec rake test
|
42
36
|
|
43
37
|
publish:
|
44
|
-
if:
|
38
|
+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
|
45
39
|
needs: build
|
46
40
|
runs-on: ubuntu-latest
|
47
41
|
|
@@ -49,6 +43,8 @@ jobs:
|
|
49
43
|
- uses: actions/checkout@v2
|
50
44
|
|
51
45
|
- name: Release Gem
|
52
|
-
uses:
|
46
|
+
uses: discourse/publish-rubygems-action@v2-beta
|
53
47
|
env:
|
54
|
-
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
48
|
+
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
49
|
+
GIT_EMAIL: team@discourse.org
|
50
|
+
GIT_NAME: discoursebot
|
data/.gitignore
CHANGED
@@ -1,22 +1,3 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
1
|
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
2
|
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
bin/
|
19
|
-
.ruby-gemset
|
20
|
-
.ruby-version
|
21
|
-
.env
|
22
3
|
/config.yml
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.46.0] - 2021-04-12
|
10
|
+
### Added
|
11
|
+
- Allow bookmarking topics
|
12
|
+
- Add timeout to requests
|
13
|
+
- Add params to get_topic_posts
|
14
|
+
|
15
|
+
## [0.45.1] - 2021-03-11
|
16
|
+
### Added
|
17
|
+
- Fetch global top topics
|
18
|
+
- Allow setting topic notifications
|
19
|
+
- Return full category response
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
- Use new search endpoint
|
23
|
+
|
24
|
+
## [0.45.0] - 2021-01-15
|
25
|
+
### Added
|
26
|
+
- Tag configuration in create_category/update_category
|
27
|
+
- Topic#change_owner
|
28
|
+
- Support passing approved to #create_user
|
29
|
+
### Changed
|
30
|
+
- API key methods use the latest endpoints
|
31
|
+
|
32
|
+
## [0.44.0] - 2020-11-13
|
33
|
+
### Fixed
|
34
|
+
- Updated `show_tag` method to use new route
|
35
|
+
### Removed
|
36
|
+
- Support for Ruby 2.3 and 2.4
|
37
|
+
|
38
|
+
## [0.43.1] - 2020-11-04
|
39
|
+
### Fixed
|
40
|
+
- Tagged version 0.43.0 got pushed without commmit due to new master branch
|
41
|
+
protections in github. No, code changes here just making sure tags align with
|
42
|
+
commits.
|
43
|
+
|
9
44
|
## [0.43.0] - 2020-11-04
|
10
45
|
### Added
|
11
46
|
- Add pagination to list groups endpoint
|
@@ -19,17 +54,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
19
54
|
## [0.41.0] - 2020-06-17
|
20
55
|
### Added
|
21
56
|
- Add basic auth support
|
22
|
-
|
23
57
|
### Fixed
|
24
58
|
- Fix SSO custom field prefixes
|
25
|
-
|
26
59
|
### Removed
|
27
60
|
- Obsolete api key endpoints
|
28
61
|
|
29
62
|
## [0.40.0] - 2020-05-07
|
30
63
|
### Fixed
|
31
64
|
- Add missing attributes to `sync_sso`
|
32
|
-
|
33
65
|
### Added
|
34
66
|
- Add delete category method
|
35
67
|
|
@@ -51,7 +83,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
51
83
|
- Allow more options parameters when creating a category
|
52
84
|
- Don't require topic slug when updating topic status
|
53
85
|
- Example files now read config.yml file when present for client settings
|
54
|
-
|
55
86
|
### Fixed
|
56
87
|
- Issue with `topic_posts` and frozen strings
|
57
88
|
- Fixed some topic and category methods
|
@@ -303,5 +334,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
303
334
|
- `client.category_latest_posts("category-slug")` endpoint
|
304
335
|
|
305
336
|
## [0.1.2] - 2014-05-11
|
306
|
-
|
307
337
|
- Release
|
data/discourse_api.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.
|
21
|
+
spec.add_runtime_dependency 'faraday', '~> 1.0'
|
22
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 1.0'
|
23
|
+
spec.add_runtime_dependency 'rack', '>= 1.6'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
26
26
|
spec.add_development_dependency 'guard', '~> 2.14'
|
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'rb-inotify', '~> 0.9'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
31
|
spec.add_development_dependency 'simplecov', '~> 0.11'
|
32
|
-
spec.add_development_dependency 'webmock', '~>
|
33
|
-
spec.add_development_dependency 'rubocop-discourse'
|
32
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'rubocop-discourse', '~> 2.4.1'
|
34
34
|
|
35
|
-
spec.required_ruby_version = '>= 2.
|
35
|
+
spec.required_ruby_version = '>= 2.5.0'
|
36
36
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
4
|
+
|
5
|
+
config = DiscourseApi::ExampleHelper.load_yml
|
6
|
+
|
7
|
+
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
|
8
|
+
client.api_key = config['api_key'] || "YOUR_API_KEY"
|
9
|
+
client.api_username = config['api_username'] || "YOUR_USERNAME"
|
10
|
+
|
11
|
+
# Bookmark topic
|
12
|
+
puts client.bookmark_topic(1418)
|
13
|
+
|
14
|
+
# Remove bookmark from topic
|
15
|
+
puts client.remove_topic_bookmark(1418)
|
data/examples/category.rb
CHANGED
@@ -14,6 +14,9 @@ puts client.categories()
|
|
14
14
|
# get sub categories for parent category with id 2
|
15
15
|
puts client.categories(parent_category_id: 2)
|
16
16
|
|
17
|
+
# get the full categories response
|
18
|
+
puts client.categories_full()
|
19
|
+
|
17
20
|
# List topics in a category
|
18
21
|
category_topics = client.category_latest_topics(category_slug: "test-category")
|
19
22
|
puts category_topics
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
4
|
+
|
5
|
+
config = DiscourseApi::ExampleHelper.load_yml
|
6
|
+
|
7
|
+
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
|
8
|
+
client.api_key = config['api_key'] || "YOUR_API_KEY"
|
9
|
+
client.api_username = config['api_username'] || "YOUR_USERNAME"
|
10
|
+
|
11
|
+
# generate user api key
|
12
|
+
response = client.create_api_key(
|
13
|
+
key: {
|
14
|
+
description: "Key to The Batmobile",
|
15
|
+
username: "batman"
|
16
|
+
}
|
17
|
+
)
|
18
|
+
|
19
|
+
api_key_id = response["key"]["id"]
|
20
|
+
|
21
|
+
puts response
|
22
|
+
# sample output: {"key"=>{"id"=>13, "key"=>"abc", "description"=>"Key to the Batmobile"}}
|
23
|
+
|
24
|
+
response = client.revoke_api_key(api_key_id)
|
25
|
+
|
26
|
+
puts response
|
27
|
+
# sample output: {"key"=>{"id"=>13, "key"=>"abc", "description"=>"Key to the Batmobile", "revoked_at"=>"2021-01-01T00:00:00.000Z"}}
|
28
|
+
|
29
|
+
response = client.undo_revoke_api_key(api_key_id)
|
30
|
+
|
31
|
+
puts response
|
32
|
+
# sample output: {"key"=>{"id"=>13, "key"=>"abc", "description"=>"Key to the Batmobile", "revoked_at"=>nil}}
|
33
|
+
|
34
|
+
response = client.list_api_keys
|
35
|
+
|
36
|
+
puts response
|
37
|
+
# sample output: {"keys"=>[{"id"=>13, "key"=>"abc", "description"=>"Key to the Batmobile"}]}
|
38
|
+
|
39
|
+
response = client.delete_api_key(api_key_id)
|
40
|
+
|
41
|
+
puts response
|
42
|
+
# sample output: {"success"=>"OK"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
4
|
+
|
5
|
+
config = DiscourseApi::ExampleHelper.load_yml
|
6
|
+
|
7
|
+
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
|
8
|
+
client.api_key = config['api_key'] || "YOUR_API_KEY"
|
9
|
+
client.api_username = config['api_username'] || "YOUR_USERNAME"
|
10
|
+
|
11
|
+
# watch an entire category
|
12
|
+
client.category_set_user_notification_level(1, notification_level: 3)
|
13
|
+
|
14
|
+
# mute a topic
|
15
|
+
client.topic_set_user_notification_level(1, notification_level: 0)
|
data/examples/topic_lists.rb
CHANGED
@@ -11,6 +11,9 @@ client.api_username = config['api_username'] || "YOUR_USERNAME"
|
|
11
11
|
# get latest topics
|
12
12
|
puts client.latest_topics({})
|
13
13
|
|
14
|
+
# get top topics
|
15
|
+
puts client.top_topics
|
16
|
+
|
14
17
|
# recategorize topic
|
15
18
|
puts client.recategorize_topic(topic_id: 108, category_id: 5)
|
16
19
|
|
@@ -2,22 +2,28 @@
|
|
2
2
|
module DiscourseApi
|
3
3
|
module API
|
4
4
|
module ApiKey
|
5
|
-
def
|
6
|
-
response = get("/admin/api
|
7
|
-
response
|
5
|
+
def list_api_keys
|
6
|
+
response = get("/admin/api/keys")
|
7
|
+
response[:body]
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def create_api_key(args)
|
11
|
+
args = API.params(args)
|
12
|
+
.required(:key)
|
13
|
+
.to_h
|
14
|
+
post("/admin/api/keys", args)
|
12
15
|
end
|
13
16
|
|
14
17
|
def revoke_api_key(id)
|
15
|
-
|
18
|
+
post("/admin/api/keys/#{id}/revoke")
|
16
19
|
end
|
17
20
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
+
def undo_revoke_api_key(id)
|
22
|
+
post("/admin/api/keys/#{id}/undo-revoke")
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_api_key(id)
|
26
|
+
delete("/admin/api/keys/#{id}")
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
@@ -10,7 +10,8 @@ module DiscourseApi
|
|
10
10
|
.required(:name, :color, :text_color)
|
11
11
|
.optional(:slug, :permissions, :auto_close_hours, :auto_close_based_on_last_post, :position, :email_in,
|
12
12
|
:email_in_allow_strangers, :logo_url, :background_url, :allow_badges, :topic_template, :custom_fields, :description,
|
13
|
-
:reviewable_by_group_name, :show_subcategory_list, :subcategory_list_style
|
13
|
+
:reviewable_by_group_name, :show_subcategory_list, :subcategory_list_style,
|
14
|
+
:allowed_tags, :allowed_tag_groups, :required_tag_group_name)
|
14
15
|
.default(parent_category_id: nil)
|
15
16
|
response = post("/categories", args)
|
16
17
|
response['category']
|
@@ -22,7 +23,8 @@ module DiscourseApi
|
|
22
23
|
.required(:id, :name, :color, :text_color)
|
23
24
|
.optional(:slug, :permissions, :auto_close_hours, :auto_close_based_on_last_post, :position, :email_in,
|
24
25
|
:email_in_allow_strangers, :logo_url, :background_url, :allow_badges, :topic_template, :custom_fields, :description,
|
25
|
-
:reviewable_by_group_name, :show_subcategory_list, :subcategory_list_style
|
26
|
+
:reviewable_by_group_name, :show_subcategory_list, :subcategory_list_style,
|
27
|
+
:allowed_tags, :allowed_tag_groups, :required_tag_group_name)
|
26
28
|
.default(parent_category_id: nil)
|
27
29
|
response = put("/categories/#{category_id}", args)
|
28
30
|
response['body']['category'] if response['body']
|
@@ -34,11 +36,24 @@ module DiscourseApi
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def categories(params = {})
|
39
|
+
categories_full(params)['category_list']['categories']
|
40
|
+
end
|
41
|
+
|
42
|
+
def categories_full(params = {})
|
37
43
|
response = get('/categories.json', params)
|
38
|
-
response[:body]
|
44
|
+
response[:body]
|
39
45
|
end
|
40
46
|
|
41
47
|
def category_latest_topics(args = {})
|
48
|
+
response = category_latest_topics_full(args)
|
49
|
+
if response['errors']
|
50
|
+
response['errors']
|
51
|
+
else
|
52
|
+
response['topic_list']['topics']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def category_latest_topics_full(args = {})
|
42
57
|
params = API.params(args)
|
43
58
|
.required(:category_slug)
|
44
59
|
.optional(:page).to_h
|
@@ -47,25 +62,31 @@ module DiscourseApi
|
|
47
62
|
url = "#{url}?page=#{params[:page]}"
|
48
63
|
end
|
49
64
|
response = get(url)
|
50
|
-
|
51
|
-
response[:body]['errors']
|
52
|
-
else
|
53
|
-
response[:body]['topic_list']['topics']
|
54
|
-
end
|
65
|
+
response[:body]
|
55
66
|
end
|
56
67
|
|
57
68
|
def category_top_topics(category_slug)
|
58
|
-
response =
|
59
|
-
if response[
|
60
|
-
response[
|
69
|
+
response = category_top_topics_full(category_slug)
|
70
|
+
if response['errors']
|
71
|
+
response['errors']
|
61
72
|
else
|
62
|
-
response[
|
73
|
+
response['topic_list']['topics']
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
77
|
+
def category_top_topics_full(category_slug)
|
78
|
+
response = get("/c/#{category_slug}/l/top.json")
|
79
|
+
response[:body]
|
80
|
+
end
|
81
|
+
|
66
82
|
def category_new_topics(category_slug)
|
83
|
+
response = category_new_topics_full(category_slug)
|
84
|
+
response['topic_list']['topics']
|
85
|
+
end
|
86
|
+
|
87
|
+
def category_new_topics_full(category_slug)
|
67
88
|
response = get("/c/#{category_slug}/l/new.json")
|
68
|
-
response[:body]
|
89
|
+
response[:body]
|
69
90
|
end
|
70
91
|
|
71
92
|
def category(id)
|
@@ -73,12 +94,19 @@ module DiscourseApi
|
|
73
94
|
response[:body]['category']
|
74
95
|
end
|
75
96
|
|
97
|
+
# TODO: Deprecated. Remove after 20210727
|
76
98
|
def category_set_user_notification(args = {})
|
77
99
|
category_id = args[:id]
|
78
100
|
args = API.params(args)
|
79
101
|
.required(:notification_level)
|
80
102
|
post("/category/#{category_id}/notifications", args)
|
81
103
|
end
|
104
|
+
|
105
|
+
def category_set_user_notification_level(category_id, params)
|
106
|
+
params = API.params(params)
|
107
|
+
.required(:notification_level)
|
108
|
+
post("/category/#{category_id}/notifications", params)
|
109
|
+
end
|
82
110
|
end
|
83
111
|
end
|
84
112
|
end
|
@@ -12,7 +12,7 @@ module DiscourseApi
|
|
12
12
|
raise ArgumentError.new("#{term} is required but not specified") unless term
|
13
13
|
raise ArgumentError.new("#{term} is required but not specified") unless !term.empty?
|
14
14
|
|
15
|
-
response = get('/search
|
15
|
+
response = get('/search', options.merge(q: term))
|
16
16
|
response[:body]
|
17
17
|
end
|
18
18
|
end
|