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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72fb97a4c52606e5839c8749c6108312686530417bfd5dd5b9a2a0af3786dd43
|
4
|
+
data.tar.gz: 670e5bca1055f0bb7b76c936d7e40f643106d1a6cb3f4aa366f9a6d472702bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 721d458fc214443c3c07c01b7e19faf1ca7dc71c5a47b542ee1a6786dff8b43537e941cfdac19fd7e904d42a4b3e867595b6ee0d0f587a3d7b1021629eed071a
|
7
|
+
data.tar.gz: 96f568076b20018c1a04894b94464c38aea655224f36f4efd358e6405071869f96f8ca6401632e2cb54daf616de7e5f5ab4be807930d3fd09a12d0b2353eea0c
|
data/.github/workflows/ci.yml
CHANGED
@@ -7,16 +7,32 @@ on:
|
|
7
7
|
- main
|
8
8
|
|
9
9
|
jobs:
|
10
|
-
|
10
|
+
lint:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v3
|
14
|
+
|
15
|
+
- name: Setup ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: '3.2'
|
19
|
+
bundler-cache: true
|
20
|
+
|
21
|
+
- name: Rubocop
|
22
|
+
run: bundle exec rubocop
|
23
|
+
|
24
|
+
- name: syntax_tree
|
25
|
+
if: ${{ !cancelled() }}
|
26
|
+
run: |
|
27
|
+
set -E
|
28
|
+
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
|
29
|
+
|
30
|
+
test:
|
11
31
|
runs-on: ubuntu-latest
|
12
32
|
|
13
33
|
strategy:
|
14
34
|
matrix:
|
15
|
-
ruby:
|
16
|
-
- '2.6'
|
17
|
-
- '2.7'
|
18
|
-
- '3.0'
|
19
|
-
- '3.1'
|
35
|
+
ruby: ['2.7', '3.0', '3.1', '3.2']
|
20
36
|
|
21
37
|
steps:
|
22
38
|
- uses: actions/checkout@v3
|
@@ -27,15 +43,12 @@ jobs:
|
|
27
43
|
ruby-version: ${{ matrix.ruby }}
|
28
44
|
bundler-cache: true
|
29
45
|
|
30
|
-
- name: Lint
|
31
|
-
run: bundle exec rubocop
|
32
|
-
|
33
46
|
- name: Tests
|
34
47
|
run: bundle exec rake test
|
35
48
|
|
36
49
|
publish:
|
37
50
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
38
|
-
needs:
|
51
|
+
needs: [lint, test]
|
39
52
|
runs-on: ubuntu-latest
|
40
53
|
|
41
54
|
steps:
|
data/.rubocop.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
inherit_gem:
|
2
|
-
rubocop-discourse:
|
2
|
+
rubocop-discourse: stree-compat.yml
|
data/.streerc
ADDED
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.0.0] - 2023-05-26
|
10
|
+
### Changed
|
11
|
+
- The package now requires ruby 2.7+
|
12
|
+
- The package now requires faraday 2.7+
|
13
|
+
|
14
|
+
## [1.1.0] - 2022-07-05
|
15
|
+
### Changed
|
16
|
+
- `DiscourseApi::SingleSignOn.parse` now raises `DiscourseApi::SingleSignOn::ParseError` (inherits from `RuntimeError` to preserve backward compatibility) instead of `RuntimeError` when there's a signature mismatch.
|
17
|
+
- `DiscourseApi::SingleSignOn.parse` now raises `DiscourseApi::SingleSignOn::MissingConfigError` (also inherits from `RuntimeError`) if `sso_secret` or `sso_url` are missing.
|
18
|
+
|
9
19
|
## [1.0.0] - 2022-05-01
|
10
20
|
### Changed
|
11
21
|
- The package now requires ruby 2.6+
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# DiscourseApi
|
2
2
|
|
3
|
-
[![Code Climate](https://codeclimate.com/github/discourse/discourse_api.png)][codeclimate]
|
4
|
-
|
5
|
-
[codeclimate]: https://codeclimate.com/github/discourse/discourse_api
|
6
|
-
|
7
3
|
The Discourse API gem allows you to consume the Discourse API
|
8
4
|
|
9
5
|
## Installation
|
data/discourse_api.gemspec
CHANGED
@@ -18,8 +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.add_runtime_dependency 'faraday', '~>
|
22
|
-
spec.add_runtime_dependency '
|
21
|
+
spec.add_runtime_dependency 'faraday', '~> 2.7'
|
22
|
+
spec.add_runtime_dependency 'faraday-follow_redirects'
|
23
|
+
spec.add_runtime_dependency 'faraday-multipart'
|
23
24
|
spec.add_runtime_dependency 'rack', '>= 1.6'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
@@ -30,7 +31,9 @@ Gem::Specification.new do |spec|
|
|
30
31
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
32
|
spec.add_development_dependency 'simplecov', '~> 0.11'
|
32
33
|
spec.add_development_dependency 'webmock', '~> 3.0'
|
33
|
-
spec.add_development_dependency 'rubocop-discourse', '~> 2.
|
34
|
+
spec.add_development_dependency 'rubocop-discourse', '~> 3.2.0'
|
35
|
+
spec.add_development_dependency 'syntax_tree', '~> 6.1.1'
|
36
|
+
spec.add_development_dependency 'syntax_tree-disable_ternary', '~> 1.0.0'
|
34
37
|
|
35
|
-
spec.required_ruby_version = '>= 2.
|
38
|
+
spec.required_ruby_version = '>= 2.7.0'
|
36
39
|
end
|
data/examples/backups.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# get list of backup files
|
12
12
|
puts client.backups()
|
data/examples/badges.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# get badges
|
12
12
|
puts client.badges
|
data/examples/bookmark_topic.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# Bookmark topic
|
12
12
|
puts client.bookmark_topic(1418)
|
data/examples/category.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# get categories
|
12
12
|
puts client.categories()
|
@@ -26,5 +26,9 @@ category_topics_paged = client.category_latest_topics(category_slug: "test-categ
|
|
26
26
|
puts category_topics_paged
|
27
27
|
|
28
28
|
# update category notification_level
|
29
|
-
update_response =
|
29
|
+
update_response =
|
30
|
+
client.category_set_user_notification(
|
31
|
+
id: "test-id",
|
32
|
+
notification_level: "test-notification-level",
|
33
|
+
)
|
30
34
|
puts update_response
|
@@ -1,23 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
|
-
response =
|
11
|
+
response =
|
12
|
+
client.create_topic(
|
12
13
|
category: 1,
|
13
14
|
skip_validations: true,
|
14
15
|
auto_track: false,
|
15
16
|
title: "Concert Master: A new way to choose",
|
16
|
-
raw: "This is the raw markdown for my post"
|
17
|
-
)
|
17
|
+
raw: "This is the raw markdown for my post",
|
18
|
+
)
|
18
19
|
|
19
20
|
# get topic_id from response
|
20
|
-
topic_id = response[
|
21
|
+
topic_id = response["topic_id"]
|
21
22
|
|
22
23
|
##
|
23
24
|
# available options (guessing from reading discourse source)
|
@@ -26,9 +27,9 @@ topic_id = response['topic_id']
|
|
26
27
|
##
|
27
28
|
|
28
29
|
# lock topic (note: api_username determines user that is performing action)
|
29
|
-
params = { status:
|
30
|
+
params = { status: "closed", enabled: true, api_username: "YOUR USERNAME/USERS USERNAME" }
|
30
31
|
client.change_topic_status(topic_id, params)
|
31
32
|
|
32
33
|
# unlock topic (note: api_username determines user that is performing action)
|
33
|
-
params = { status:
|
34
|
+
params = { status: "closed", enabled: false, api_username: "YOUR USERNAME/USERS USERNAME" }
|
34
35
|
client.change_topic_status(topic_id, params)
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
client.create_private_message(
|
12
12
|
title: "Confidential: Hello World!",
|
13
13
|
raw: "This is the raw markdown for my private message",
|
14
|
-
target_usernames: "user1,user2"
|
14
|
+
target_usernames: "user1,user2",
|
15
15
|
)
|
data/examples/create_topic.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
client.create_topic(
|
12
12
|
category: 1,
|
13
13
|
skip_validations: true,
|
14
14
|
auto_track: false,
|
15
15
|
title: "Concert Master: A new way to choose",
|
16
|
-
raw: "This is the raw markdown for my post"
|
16
|
+
raw: "This is the raw markdown for my post",
|
17
17
|
)
|
18
18
|
|
19
19
|
# create Poll topic
|
@@ -22,7 +22,7 @@ client.create_topic(
|
|
22
22
|
skip_validations: false,
|
23
23
|
auto_track: false,
|
24
24
|
title: "Your Favorite Color?",
|
25
|
-
raw: "[poll name=color]\n- Green\n- Blue\n- Red\n[/poll]"
|
25
|
+
raw: "[poll name=color]\n- Green\n- Blue\n- Red\n[/poll]",
|
26
26
|
)
|
27
27
|
|
28
28
|
# Create Topic with Tags
|
@@ -31,6 +31,6 @@ client.create_topic(
|
|
31
31
|
skip_validations: true,
|
32
32
|
auto_track: false,
|
33
33
|
title: "Concert Master: A new way to choose",
|
34
|
-
raw: "This is the raw markdown for my post"
|
35
|
-
tags: [
|
34
|
+
raw: "This is the raw markdown for my post",
|
35
|
+
tags: %w[asdf fdsa],
|
36
36
|
)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
###
|
12
12
|
# Required category params:
|
@@ -17,19 +17,16 @@ client.api_username = config['api_username'] || "YOUR_USERNAME"
|
|
17
17
|
###
|
18
18
|
|
19
19
|
# Create category
|
20
|
-
new_category = client.create_category(
|
21
|
-
|
22
|
-
color: "AB9364",
|
23
|
-
text_color: "FFFFFF"
|
24
|
-
)
|
25
|
-
puts 'Created category: ' + new_category.to_s
|
20
|
+
new_category = client.create_category(name: "Test Category", color: "AB9364", text_color: "FFFFFF")
|
21
|
+
puts "Created category: " + new_category.to_s
|
26
22
|
|
27
23
|
# Update category
|
28
|
-
response =
|
29
|
-
|
24
|
+
response =
|
25
|
+
client.update_category(
|
26
|
+
id: new_category["id"],
|
30
27
|
name: "The Best Test Category",
|
31
28
|
slug: "the-best-test-category",
|
32
29
|
color: "0E76BD",
|
33
|
-
text_color: "000000"
|
34
|
-
)
|
35
|
-
puts
|
30
|
+
text_color: "000000",
|
31
|
+
)
|
32
|
+
puts "Updated category: " + response.to_s
|
data/examples/create_user.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# create user
|
12
|
-
user =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
user =
|
13
|
+
client.create_user(
|
14
|
+
name: "Bruce Wayne",
|
15
|
+
email: "bruce@wayne.com",
|
16
|
+
username: "batman",
|
17
|
+
password: "WhySoSerious",
|
18
|
+
)
|
18
19
|
|
19
20
|
# activate user
|
20
21
|
client.activate(user["user_id"])
|
data/examples/dashboard.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# get all dashboard status as json
|
12
12
|
puts client.get_dashboard_stats
|
@@ -1,23 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# requires this plugin => https://github.com/discourse/discourse-invite-tokens
|
3
3
|
|
4
|
-
require
|
4
|
+
require "csv"
|
5
5
|
|
6
|
-
$LOAD_PATH.unshift File.expand_path(
|
7
|
-
require File.expand_path(
|
6
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
7
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
8
8
|
|
9
9
|
config = DiscourseApi::ExampleHelper.load_yml
|
10
10
|
|
11
|
-
client = DiscourseApi::Client.new(config[
|
12
|
-
client.api_key = config[
|
13
|
-
client.api_username = config[
|
11
|
+
client = DiscourseApi::Client.new(config["host"] || "http://localhost:3000")
|
12
|
+
client.api_key = config["api_key"] || "YOUR_API_KEY"
|
13
|
+
client.api_username = config["api_username"] || "YOUR_USERNAME"
|
14
14
|
|
15
15
|
# fetch email-less invite tokens
|
16
|
-
invite_tokens =
|
16
|
+
invite_tokens =
|
17
|
+
client.disposable_tokens(username: "eviltrout", quantity: 5, group_names: "security,support")
|
17
18
|
|
18
19
|
# write to CSV file
|
19
20
|
CSV.open(File.expand_path("../invite_tokens.csv", __FILE__), "w") do |csv|
|
20
|
-
invite_tokens.each
|
21
|
-
csv << [value]
|
22
|
-
end
|
21
|
+
invite_tokens.each { |value| csv << [value] }
|
23
22
|
end
|
data/examples/example.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# get latest topics
|
12
12
|
puts client.latest_topics
|
@@ -1,38 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
@target_username = "YOUR_TARGET_USERNAME"
|
12
|
-
@target_group_id =
|
13
|
-
|
14
|
-
@user = client.user(@target_username)
|
12
|
+
@target_group_id = # YOUR NUMERIC TARGET GROUP ID
|
13
|
+
@user = client.user(@target_username)
|
15
14
|
|
16
15
|
# each user's group and the group's default notification level are stored under user['groups']
|
17
|
-
@user[
|
18
|
-
if group[
|
19
|
-
@group_name = group[
|
20
|
-
@default_level = group[
|
16
|
+
@user["groups"].each do |group|
|
17
|
+
if group["id"] == @target_group_id
|
18
|
+
@group_name = group["name"]
|
19
|
+
@default_level = group["default_notification_level"]
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
# and the user's notification setting for each group is stored under user['group_users]
|
25
|
-
@user[
|
26
|
-
if users_group[
|
27
|
-
@notification_level = users_group[
|
24
|
+
@user["group_users"].each do |users_group|
|
25
|
+
if users_group["group_id"] == @target_group_id
|
26
|
+
@notification_level = users_group["notification_level"]
|
28
27
|
puts "Group ID:#{@target_group_id} #{@group_name} Current Notification Level: #{@notification_level} Default: #{@default_level}"
|
29
|
-
response = client.group_set_user_notification_level(@group_name, @user[
|
28
|
+
response = client.group_set_user_notification_level(@group_name, @user["id"], @default_level)
|
30
29
|
puts response
|
31
|
-
@users_group_users_after_update = client.user(@target_username)[
|
30
|
+
@users_group_users_after_update = client.user(@target_username)["group_users"]
|
32
31
|
# this just pulls the user from the database again to make sure we updated the user's group notification level
|
33
32
|
@users_group_users_after_update.each do |users_group_second_pass|
|
34
|
-
if users_group_second_pass[
|
35
|
-
puts "Updated ID:#{@target_group_id} #{@group_name} Notification Level: #{users_group_second_pass[
|
33
|
+
if users_group_second_pass["group_id"] == @target_group_id
|
34
|
+
puts "Updated ID:#{@target_group_id} #{@group_name} Notification Level: #{users_group_second_pass["notification_level"]} Default: #{@default_level}"
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
data/examples/groups.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
response = client.create_group(name: "engineering_team")
|
12
12
|
group_id = response["basic_group"]["id"]
|
13
13
|
|
14
14
|
client.group_add(group_id, username: "sam")
|
15
15
|
client.group_add(group_id, username: "jeff")
|
16
|
-
client.group_add(group_id, usernames: [
|
16
|
+
client.group_add(group_id, usernames: %w[neil dan])
|
17
17
|
client.group_add(group_id, user_id: 123)
|
18
18
|
client.group_add(group_id, user_ids: [123, 456])
|
19
19
|
|
@@ -24,5 +24,5 @@ client.delete_group(group_id)
|
|
24
24
|
|
25
25
|
## List users of a group
|
26
26
|
|
27
|
-
members = client.group_members(
|
27
|
+
members = client.group_members("trust_level_0")
|
28
28
|
puts members
|
data/examples/invite_users.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# invite user
|
12
12
|
invite = client.invite_user(email: "name@example.com", group_ids: "41,42")
|
data/examples/manage_api_keys.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
3
|
-
require File.expand_path(
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
require File.expand_path("../../lib/discourse_api", __FILE__)
|
4
4
|
|
5
5
|
config = DiscourseApi::ExampleHelper.load_yml
|
6
6
|
|
7
|
-
client = DiscourseApi::Client.new(config[
|
8
|
-
client.api_key = config[
|
9
|
-
client.api_username = config[
|
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
10
|
|
11
11
|
# generate user api key
|
12
|
-
response = client.create_api_key(
|
13
|
-
key: {
|
14
|
-
description: "Key to The Batmobile",
|
15
|
-
username: "batman"
|
16
|
-
}
|
17
|
-
)
|
12
|
+
response = client.create_api_key(key: { description: "Key to The Batmobile", username: "batman" })
|
18
13
|
|
19
14
|
api_key_id = response["key"]["id"]
|
20
15
|
|