discourse_api 0.11.0 → 0.12.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/.gitignore +21 -21
- data/.travis.yml +5 -5
- data/CHANGELOG.md +105 -99
- data/Gemfile +4 -4
- data/Guardfile +5 -5
- data/LICENSE.txt +22 -22
- data/README.md +73 -73
- data/Rakefile +7 -7
- data/discourse_api.gemspec +35 -35
- data/examples/backups.rb +18 -18
- data/examples/category.rb +21 -21
- data/examples/change_topic_status.rb +33 -33
- data/examples/create_topic.rb +23 -23
- data/examples/create_user.rb +14 -14
- data/examples/dashboard.rb +13 -13
- data/examples/disposable_invite_tokens.rb +18 -18
- data/examples/example.rb +9 -9
- data/examples/groups.rb +25 -25
- data/examples/invite_users.rb +15 -15
- data/examples/post_action.rb +25 -25
- data/examples/search.rb +9 -9
- data/examples/sso.rb +14 -14
- data/examples/topic_lists.rb +15 -15
- data/examples/update_user.rb +22 -22
- data/lib/discourse_api.rb +5 -5
- data/lib/discourse_api/api/api_key.rb +31 -31
- data/lib/discourse_api/api/backups.rb +24 -24
- data/lib/discourse_api/api/badges.rb +28 -28
- data/lib/discourse_api/api/categories.rb +57 -57
- data/lib/discourse_api/api/dashboard.rb +24 -24
- data/lib/discourse_api/api/email.rb +15 -15
- data/lib/discourse_api/api/groups.rb +52 -52
- data/lib/discourse_api/api/invite.rb +17 -17
- data/lib/discourse_api/api/notifications.rb +9 -9
- data/lib/discourse_api/api/params.rb +55 -55
- data/lib/discourse_api/api/posts.rb +41 -41
- data/lib/discourse_api/api/private_messages.rb +10 -10
- data/lib/discourse_api/api/search.rb +19 -19
- data/lib/discourse_api/api/sso.rb +22 -22
- data/lib/discourse_api/api/tags.rb +10 -10
- data/lib/discourse_api/api/topics.rb +78 -78
- data/lib/discourse_api/api/users.rb +93 -85
- data/lib/discourse_api/client.rb +133 -133
- data/lib/discourse_api/error.rb +17 -17
- data/lib/discourse_api/single_sign_on.rb +110 -110
- data/lib/discourse_api/version.rb +3 -3
- data/routes.txt +203 -203
- data/spec/discourse_api/api/api_key_spec.rb +121 -121
- data/spec/discourse_api/api/backups_spec.rb +23 -23
- data/spec/discourse_api/api/badges_spec.rb +40 -40
- data/spec/discourse_api/api/categories_spec.rb +87 -87
- data/spec/discourse_api/api/email_spec.rb +39 -39
- data/spec/discourse_api/api/groups_spec.rb +94 -94
- data/spec/discourse_api/api/notifications_spec.rb +24 -24
- data/spec/discourse_api/api/params_spec.rb +32 -32
- data/spec/discourse_api/api/posts_spec.rb +41 -41
- data/spec/discourse_api/api/private_messages_spec.rb +22 -22
- data/spec/discourse_api/api/search_spec.rb +30 -30
- data/spec/discourse_api/api/sso_spec.rb +16 -16
- data/spec/discourse_api/api/topics_spec.rb +113 -113
- data/spec/discourse_api/api/users_spec.rb +255 -227
- data/spec/discourse_api/client_spec.rb +115 -115
- data/spec/fixtures/api.json +12 -12
- data/spec/fixtures/backups.json +12 -12
- data/spec/fixtures/badges.json +569 -569
- data/spec/fixtures/categories.json +72 -72
- data/spec/fixtures/category_latest_topics.json +92 -92
- data/spec/fixtures/category_topics.json +91 -91
- data/spec/fixtures/email_list_all.json +749 -749
- data/spec/fixtures/email_settings.json +13 -13
- data/spec/fixtures/generate_api_key.json +12 -12
- data/spec/fixtures/generate_master_key.json +7 -7
- data/spec/fixtures/groups.json +18 -18
- data/spec/fixtures/hot.json +113 -113
- data/spec/fixtures/latest.json +115 -115
- data/spec/fixtures/members_0.json +403 -403
- data/spec/fixtures/members_1.json +363 -363
- data/spec/fixtures/new.json +113 -113
- data/spec/fixtures/notifications.json +16 -16
- data/spec/fixtures/post.json +94 -94
- data/spec/fixtures/post_action_users.json +18 -18
- data/spec/fixtures/private_messages.json +69 -69
- data/spec/fixtures/regenerate_api_key.json +7 -7
- data/spec/fixtures/search.json +24 -24
- data/spec/fixtures/topic.json +739 -739
- data/spec/fixtures/topic_invite_user.json +3 -3
- data/spec/fixtures/topics_created_by.json +49 -49
- data/spec/fixtures/update_trust_level.json +37 -37
- data/spec/fixtures/upload_avatar.json +13 -13
- data/spec/fixtures/user.json +65 -65
- data/spec/fixtures/user_activate_success.json +3 -3
- data/spec/fixtures/user_badges.json +170 -170
- data/spec/fixtures/user_create_success.json +5 -5
- data/spec/fixtures/user_grant_admin.json +37 -37
- data/spec/fixtures/user_list.json +583 -583
- data/spec/fixtures/user_log_out_success.json +3 -3
- data/spec/fixtures/user_update_avatar_success.json +3 -3
- data/spec/fixtures/user_update_user.json +3 -3
- data/spec/fixtures/user_update_username.json +4 -4
- data/spec/spec_helper.rb +61 -61
- metadata +2 -2
data/Rakefile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require "bundler/gem_tasks"
|
|
2
|
-
|
|
3
|
-
require 'rspec/core/rake_task'
|
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
-
|
|
6
|
-
task test: :spec
|
|
7
|
-
task default: :spec
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
+
|
|
6
|
+
task test: :spec
|
|
7
|
+
task default: :spec
|
data/discourse_api.gemspec
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'discourse_api/version'
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name = "discourse_api"
|
|
8
|
-
spec.version = DiscourseApi::VERSION
|
|
9
|
-
spec.authors = ["Sam Saffron", "John Paul Ashenfelter", "Michael Herold", "Blake Erickson"]
|
|
10
|
-
spec.email = ["sam.saffron@gmail.com", "john@ashenfelter.com", "michael.j.herold@gmail.com", "o.blakeerickson@gmail.com"]
|
|
11
|
-
spec.description = %q{Discourse API}
|
|
12
|
-
spec.summary = %q{Allows access to the Discourse API}
|
|
13
|
-
spec.homepage = "http://github.com/discourse/discourse_api"
|
|
14
|
-
spec.license = "MIT"
|
|
15
|
-
|
|
16
|
-
spec.files = `git ls-files`.split($/)
|
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
-
spec.require_paths = ["lib"]
|
|
20
|
-
|
|
21
|
-
spec.add_dependency "faraday", "~> 0.9"
|
|
22
|
-
spec.add_dependency "faraday_middleware", "~> 0.10"
|
|
23
|
-
spec.add_dependency "rack", "~> 1.6"
|
|
24
|
-
|
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.12"
|
|
26
|
-
spec.add_development_dependency "rake", "~> 11.1"
|
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.4"
|
|
28
|
-
spec.add_development_dependency "webmock", "~> 2.0"
|
|
29
|
-
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
|
30
|
-
spec.add_development_dependency "guard", "~> 2.14"
|
|
31
|
-
spec.add_development_dependency "rb-inotify", "~> 0.9"
|
|
32
|
-
spec.add_development_dependency "simplecov", "~> 0.11"
|
|
33
|
-
|
|
34
|
-
spec.required_ruby_version = '>= 2.2.3'
|
|
35
|
-
end
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'discourse_api/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "discourse_api"
|
|
8
|
+
spec.version = DiscourseApi::VERSION
|
|
9
|
+
spec.authors = ["Sam Saffron", "John Paul Ashenfelter", "Michael Herold", "Blake Erickson"]
|
|
10
|
+
spec.email = ["sam.saffron@gmail.com", "john@ashenfelter.com", "michael.j.herold@gmail.com", "o.blakeerickson@gmail.com"]
|
|
11
|
+
spec.description = %q{Discourse API}
|
|
12
|
+
spec.summary = %q{Allows access to the Discourse API}
|
|
13
|
+
spec.homepage = "http://github.com/discourse/discourse_api"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency "faraday", "~> 0.9"
|
|
22
|
+
spec.add_dependency "faraday_middleware", "~> 0.10"
|
|
23
|
+
spec.add_dependency "rack", "~> 1.6"
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
|
26
|
+
spec.add_development_dependency "rake", "~> 11.1"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
|
28
|
+
spec.add_development_dependency "webmock", "~> 2.0"
|
|
29
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
|
30
|
+
spec.add_development_dependency "guard", "~> 2.14"
|
|
31
|
+
spec.add_development_dependency "rb-inotify", "~> 0.9"
|
|
32
|
+
spec.add_development_dependency "simplecov", "~> 0.11"
|
|
33
|
+
|
|
34
|
+
spec.required_ruby_version = '>= 2.2.3'
|
|
35
|
+
end
|
data/examples/backups.rb
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# get list of backup files
|
|
9
|
-
puts client.backups()
|
|
10
|
-
|
|
11
|
-
# create backup
|
|
12
|
-
puts client.create_backup()
|
|
13
|
-
|
|
14
|
-
# restore backup
|
|
15
|
-
puts client.restore_backup("backup_file_name.tar.gz")
|
|
16
|
-
|
|
17
|
-
# download backup
|
|
18
|
-
puts client.download_backup("backup_file_name.tar.gz", "/tmp/")
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# get list of backup files
|
|
9
|
+
puts client.backups()
|
|
10
|
+
|
|
11
|
+
# create backup
|
|
12
|
+
puts client.create_backup()
|
|
13
|
+
|
|
14
|
+
# restore backup
|
|
15
|
+
puts client.restore_backup("backup_file_name.tar.gz")
|
|
16
|
+
|
|
17
|
+
# download backup
|
|
18
|
+
puts client.download_backup("backup_file_name.tar.gz", "/tmp/")
|
data/examples/category.rb
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# get categories
|
|
9
|
-
puts client.categories()
|
|
10
|
-
|
|
11
|
-
# get sub categories for parent category with id 2
|
|
12
|
-
puts client.categories(parent_category_id: 2)
|
|
13
|
-
|
|
14
|
-
# List topics in a category
|
|
15
|
-
category_topics = client.category_latest_topics(category_slug: "test-category")
|
|
16
|
-
puts category_topics
|
|
17
|
-
|
|
18
|
-
# List topics in a category paged
|
|
19
|
-
category_topics_paged = client.category_latest_topics(category_slug: "test-category", page: "5")
|
|
20
|
-
puts category_topics_paged
|
|
21
|
-
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# get categories
|
|
9
|
+
puts client.categories()
|
|
10
|
+
|
|
11
|
+
# get sub categories for parent category with id 2
|
|
12
|
+
puts client.categories(parent_category_id: 2)
|
|
13
|
+
|
|
14
|
+
# List topics in a category
|
|
15
|
+
category_topics = client.category_latest_topics(category_slug: "test-category")
|
|
16
|
+
puts category_topics
|
|
17
|
+
|
|
18
|
+
# List topics in a category paged
|
|
19
|
+
category_topics_paged = client.category_latest_topics(category_slug: "test-category", page: "5")
|
|
20
|
+
puts category_topics_paged
|
|
21
|
+
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
response = client.create_topic(
|
|
9
|
-
category: "Boing Boing",
|
|
10
|
-
skip_validations: true,
|
|
11
|
-
auto_track: false,
|
|
12
|
-
title: "Concert Master: A new way to choose",
|
|
13
|
-
raw: "This is the raw markdown for my post"
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
# get topic_id and topic_slug from response
|
|
17
|
-
topic_id = response['topic_id']
|
|
18
|
-
topic_slug = response['topic_slug']
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
##
|
|
22
|
-
# available options (guessing from reading discourse source)
|
|
23
|
-
# status can be: ['autoclose', 'closed', 'archived', 'disabled', 'visible']
|
|
24
|
-
# enabled can be: [true, false]
|
|
25
|
-
##
|
|
26
|
-
|
|
27
|
-
# lock topic (note: api_username determines user that is performing action)
|
|
28
|
-
params = {status: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME"}
|
|
29
|
-
client.change_topic_status(topic_slug, topic_id, params)
|
|
30
|
-
|
|
31
|
-
# unlock topic (note: api_username determines user that is performing action)
|
|
32
|
-
params = {status: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME"}
|
|
33
|
-
client.change_topic_status(topic_slug, topic_id, params)
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
response = client.create_topic(
|
|
9
|
+
category: "Boing Boing",
|
|
10
|
+
skip_validations: true,
|
|
11
|
+
auto_track: false,
|
|
12
|
+
title: "Concert Master: A new way to choose",
|
|
13
|
+
raw: "This is the raw markdown for my post"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# get topic_id and topic_slug from response
|
|
17
|
+
topic_id = response['topic_id']
|
|
18
|
+
topic_slug = response['topic_slug']
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# available options (guessing from reading discourse source)
|
|
23
|
+
# status can be: ['autoclose', 'closed', 'archived', 'disabled', 'visible']
|
|
24
|
+
# enabled can be: [true, false]
|
|
25
|
+
##
|
|
26
|
+
|
|
27
|
+
# lock topic (note: api_username determines user that is performing action)
|
|
28
|
+
params = {status: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME"}
|
|
29
|
+
client.change_topic_status(topic_slug, topic_id, params)
|
|
30
|
+
|
|
31
|
+
# unlock topic (note: api_username determines user that is performing action)
|
|
32
|
+
params = {status: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME"}
|
|
33
|
+
client.change_topic_status(topic_slug, topic_id, params)
|
data/examples/create_topic.rb
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
client.create_topic(
|
|
9
|
-
category: "Boing Boing",
|
|
10
|
-
skip_validations: true,
|
|
11
|
-
auto_track: false,
|
|
12
|
-
title: "Concert Master: A new way to choose",
|
|
13
|
-
raw: "This is the raw markdown for my post"
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
# create Poll topic
|
|
17
|
-
client.create_topic(
|
|
18
|
-
category: "general",
|
|
19
|
-
skip_validations: false,
|
|
20
|
-
auto_track: false,
|
|
21
|
-
title: "Your Favorite Color?",
|
|
22
|
-
raw: "[poll name=color]\n- Green\n- Blue\n- Red\n[/poll]"
|
|
23
|
-
)
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
client.create_topic(
|
|
9
|
+
category: "Boing Boing",
|
|
10
|
+
skip_validations: true,
|
|
11
|
+
auto_track: false,
|
|
12
|
+
title: "Concert Master: A new way to choose",
|
|
13
|
+
raw: "This is the raw markdown for my post"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# create Poll topic
|
|
17
|
+
client.create_topic(
|
|
18
|
+
category: "general",
|
|
19
|
+
skip_validations: false,
|
|
20
|
+
auto_track: false,
|
|
21
|
+
title: "Your Favorite Color?",
|
|
22
|
+
raw: "[poll name=color]\n- Green\n- Blue\n- Red\n[/poll]"
|
|
23
|
+
)
|
data/examples/create_user.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# create user
|
|
9
|
-
client.create_user(
|
|
10
|
-
name: "Bruce Wayne",
|
|
11
|
-
email: "bruce@wayne.com",
|
|
12
|
-
username: "batman",
|
|
13
|
-
password: "WhySoSerious"
|
|
14
|
-
)
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# create user
|
|
9
|
+
client.create_user(
|
|
10
|
+
name: "Bruce Wayne",
|
|
11
|
+
email: "bruce@wayne.com",
|
|
12
|
+
username: "batman",
|
|
13
|
+
password: "WhySoSerious"
|
|
14
|
+
)
|
data/examples/dashboard.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# get all dashboard status as json
|
|
9
|
-
puts client.get_dashboard_stats
|
|
10
|
-
|
|
11
|
-
# get hash of some dashboard total value
|
|
12
|
-
puts client.get_dashboard_stats_totals
|
|
13
|
-
# sample output: {"users"=>9, "topics"=>230, "posts"=>441}
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# get all dashboard status as json
|
|
9
|
+
puts client.get_dashboard_stats
|
|
10
|
+
|
|
11
|
+
# get hash of some dashboard total value
|
|
12
|
+
puts client.get_dashboard_stats_totals
|
|
13
|
+
# sample output: {"users"=>9, "topics"=>230, "posts"=>441}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
require 'csv'
|
|
2
|
-
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
4
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
5
|
-
|
|
6
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
7
|
-
client.api_key = "YOUR_API_KEY"
|
|
8
|
-
client.api_username = "YOUR_USERNAME"
|
|
9
|
-
|
|
10
|
-
# fetch email-less invite tokens
|
|
11
|
-
invite_tokens = client.disposable_tokens(username: "eviltrout", quantity: 5, group_names: "security,support")
|
|
12
|
-
|
|
13
|
-
# write to CSV file
|
|
14
|
-
CSV.open(File.expand_path("../invite_tokens.csv", __FILE__), "w") do |csv|
|
|
15
|
-
invite_tokens.each do |value|
|
|
16
|
-
csv << [value]
|
|
17
|
-
end
|
|
18
|
-
end
|
|
1
|
+
require 'csv'
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
4
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
5
|
+
|
|
6
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
7
|
+
client.api_key = "YOUR_API_KEY"
|
|
8
|
+
client.api_username = "YOUR_USERNAME"
|
|
9
|
+
|
|
10
|
+
# fetch email-less invite tokens
|
|
11
|
+
invite_tokens = client.disposable_tokens(username: "eviltrout", quantity: 5, group_names: "security,support")
|
|
12
|
+
|
|
13
|
+
# write to CSV file
|
|
14
|
+
CSV.open(File.expand_path("../invite_tokens.csv", __FILE__), "w") do |csv|
|
|
15
|
+
invite_tokens.each do |value|
|
|
16
|
+
csv << [value]
|
|
17
|
+
end
|
|
18
|
+
end
|
data/examples/example.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
# get latest topics
|
|
9
|
-
puts client.latest_topics
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
# get latest topics
|
|
9
|
+
puts client.latest_topics
|
data/examples/groups.rb
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
-
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
-
|
|
4
|
-
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
-
client.api_key = "YOUR_API_KEY"
|
|
6
|
-
client.api_username = "YOUR_USERNAME"
|
|
7
|
-
|
|
8
|
-
response = client.create_group(name: "engineering_team")
|
|
9
|
-
group_id = response["basic_group"]["id"]
|
|
10
|
-
|
|
11
|
-
client.group_add(group_id, username: "sam")
|
|
12
|
-
client.group_add(group_id, username: "jeff")
|
|
13
|
-
client.group_add(group_id, usernames: ["neil", "dan"])
|
|
14
|
-
client.group_add(group_id, user_id: 123)
|
|
15
|
-
client.group_add(group_id, user_ids: [123, 456])
|
|
16
|
-
|
|
17
|
-
client.group_remove(group_id, username: "neil")
|
|
18
|
-
client.group_remove(group_id, user_id: 123)
|
|
19
|
-
|
|
20
|
-
client.delete_group(group_id)
|
|
21
|
-
|
|
22
|
-
## List users of a group
|
|
23
|
-
|
|
24
|
-
members = client.group_members('trust_level_0')
|
|
25
|
-
puts members
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
|
3
|
+
|
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
|
7
|
+
|
|
8
|
+
response = client.create_group(name: "engineering_team")
|
|
9
|
+
group_id = response["basic_group"]["id"]
|
|
10
|
+
|
|
11
|
+
client.group_add(group_id, username: "sam")
|
|
12
|
+
client.group_add(group_id, username: "jeff")
|
|
13
|
+
client.group_add(group_id, usernames: ["neil", "dan"])
|
|
14
|
+
client.group_add(group_id, user_id: 123)
|
|
15
|
+
client.group_add(group_id, user_ids: [123, 456])
|
|
16
|
+
|
|
17
|
+
client.group_remove(group_id, username: "neil")
|
|
18
|
+
client.group_remove(group_id, user_id: 123)
|
|
19
|
+
|
|
20
|
+
client.delete_group(group_id)
|
|
21
|
+
|
|
22
|
+
## List users of a group
|
|
23
|
+
|
|
24
|
+
members = client.group_members('trust_level_0')
|
|
25
|
+
puts members
|