discourse_api 1.0.0 → 2.0.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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +23 -10
  3. data/.rubocop.yml +1 -1
  4. data/.streerc +2 -0
  5. data/CHANGELOG.md +10 -0
  6. data/Gemfile +1 -1
  7. data/README.md +0 -4
  8. data/discourse_api.gemspec +7 -4
  9. data/examples/backups.rb +5 -5
  10. data/examples/badges.rb +5 -5
  11. data/examples/bookmark_topic.rb +5 -5
  12. data/examples/category.rb +10 -6
  13. data/examples/change_topic_status.rb +12 -11
  14. data/examples/create_private_message.rb +6 -6
  15. data/examples/create_topic.rb +9 -9
  16. data/examples/create_update_category.rb +13 -16
  17. data/examples/create_user.rb +12 -11
  18. data/examples/dashboard.rb +5 -5
  19. data/examples/disposable_invite_tokens.rb +9 -10
  20. data/examples/example.rb +5 -5
  21. data/examples/group_set_user_notification_level.rb +18 -19
  22. data/examples/groups.rb +7 -7
  23. data/examples/invite_users.rb +5 -5
  24. data/examples/manage_api_keys.rb +6 -11
  25. data/examples/notifications.rb +6 -6
  26. data/examples/polls.rb +12 -12
  27. data/examples/post_action.rb +5 -5
  28. data/examples/search.rb +5 -5
  29. data/examples/sent_private_messages.rb +6 -6
  30. data/examples/sso.rb +6 -6
  31. data/examples/topic_lists.rb +5 -5
  32. data/examples/update_user.rb +15 -7
  33. data/examples/upload_file.rb +7 -7
  34. data/lib/discourse_api/api/api_key.rb +1 -3
  35. data/lib/discourse_api/api/backups.rb +1 -1
  36. data/lib/discourse_api/api/badges.rb +21 -6
  37. data/lib/discourse_api/api/categories.rb +69 -37
  38. data/lib/discourse_api/api/dashboard.rb +2 -6
  39. data/lib/discourse_api/api/groups.rb +68 -73
  40. data/lib/discourse_api/api/invite.rb +30 -30
  41. data/lib/discourse_api/api/notifications.rb +2 -3
  42. data/lib/discourse_api/api/params.rb +4 -14
  43. data/lib/discourse_api/api/polls.rb +9 -12
  44. data/lib/discourse_api/api/posts.rb +5 -8
  45. data/lib/discourse_api/api/private_messages.rb +9 -8
  46. data/lib/discourse_api/api/search.rb +2 -2
  47. data/lib/discourse_api/api/topics.rb +20 -22
  48. data/lib/discourse_api/api/uploads.rb +7 -5
  49. data/lib/discourse_api/api/user_actions.rb +2 -2
  50. data/lib/discourse_api/api/users.rb +31 -19
  51. data/lib/discourse_api/client.rb +58 -56
  52. data/lib/discourse_api/example_helper.rb +2 -4
  53. data/lib/discourse_api/single_sign_on.rb +56 -57
  54. data/lib/discourse_api/version.rb +1 -1
  55. data/spec/discourse_api/api/api_key_spec.rb +39 -25
  56. data/spec/discourse_api/api/backups_spec.rb +8 -3
  57. data/spec/discourse_api/api/badges_spec.rb +17 -7
  58. data/spec/discourse_api/api/categories_spec.rb +95 -53
  59. data/spec/discourse_api/api/email_spec.rb +17 -7
  60. data/spec/discourse_api/api/groups_spec.rb +71 -52
  61. data/spec/discourse_api/api/invite_spec.rb +41 -21
  62. data/spec/discourse_api/api/notifications_spec.rb +8 -4
  63. data/spec/discourse_api/api/params_spec.rb +5 -3
  64. data/spec/discourse_api/api/polls_spec.rb +53 -44
  65. data/spec/discourse_api/api/posts_spec.rb +33 -16
  66. data/spec/discourse_api/api/private_messages_spec.rb +25 -12
  67. data/spec/discourse_api/api/search_spec.rb +8 -3
  68. data/spec/discourse_api/api/site_settings_spec.rb +2 -3
  69. data/spec/discourse_api/api/sso_spec.rb +29 -25
  70. data/spec/discourse_api/api/topics_spec.rb +100 -31
  71. data/spec/discourse_api/api/uploads_spec.rb +16 -7
  72. data/spec/discourse_api/api/user_actions_spec.rb +13 -3
  73. data/spec/discourse_api/api/users_spec.rb +137 -55
  74. data/spec/discourse_api/client_spec.rb +32 -32
  75. data/spec/discourse_api/single_sign_on_spec.rb +43 -0
  76. data/spec/fixtures/categories.json +1 -1
  77. data/spec/spec_helper.rb +10 -15
  78. metadata +57 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 730d29945a35c74f70e468ae35c3079b68019bd3eed8ae578e30658c1dbc638a
4
- data.tar.gz: '0728d384637cfd505efe9c86a895b9915e6638f6576f3907d06f34eac816fa53'
3
+ metadata.gz: 72fb97a4c52606e5839c8749c6108312686530417bfd5dd5b9a2a0af3786dd43
4
+ data.tar.gz: 670e5bca1055f0bb7b76c936d7e40f643106d1a6cb3f4aa366f9a6d472702bbb
5
5
  SHA512:
6
- metadata.gz: a32c491fd381e24e5c11c3e73fc1ecfabe014c31e4d14cdc5975869d73663eb35cd0711fa77cf74c65ecd91b3d657e28a413edcceb3d0f7230b0ece0ba7598a4
7
- data.tar.gz: 78099bb35c97d711fbf9c574148230d5e79d0dd45b3f384aeb335a7354faaa89267c4f40673a08e7a07e1cadbbc051990f392742176fa436748ebcb676b0c1db
6
+ metadata.gz: 721d458fc214443c3c07c01b7e19faf1ca7dc71c5a47b542ee1a6786dff8b43537e941cfdac19fd7e904d42a4b3e867595b6ee0d0f587a3d7b1021629eed071a
7
+ data.tar.gz: 96f568076b20018c1a04894b94464c38aea655224f36f4efd358e6405071869f96f8ca6401632e2cb54daf616de7e5f5ab4be807930d3fd09a12d0b2353eea0c
@@ -7,16 +7,32 @@ on:
7
7
  - main
8
8
 
9
9
  jobs:
10
- build:
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: build
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: default.yml
2
+ rubocop-discourse: stree-compat.yml
data/.streerc ADDED
@@ -0,0 +1,2 @@
1
+ --print-width=100
2
+ --plugins=plugin/trailing_comma,disable_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.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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- source 'https://rubygems.org'
2
+ source "https://rubygems.org"
3
3
 
4
4
  # Specify your gem's dependencies in discourse_api.gemspec
5
5
  gemspec
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
@@ -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', '~> 1.0'
22
- spec.add_runtime_dependency 'faraday_middleware', '~> 1.0'
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.5.0'
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.6.0'
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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 = client.category_set_user_notification(id: "test-id", notification_level: "test-notification-level")
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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 = client.create_topic(
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['topic_id']
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: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME" }
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: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME" }
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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
  )
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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: ['asdf', 'fdsa']
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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
- name: "Test Category",
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 = client.update_category(
29
- id: new_category['id'],
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 'Updated category: ' + response.to_s
30
+ text_color: "000000",
31
+ )
32
+ puts "Updated category: " + response.to_s
@@ -1,20 +1,21 @@
1
1
  # frozen_string_literal: true
2
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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 = client.create_user(
13
- name: "Bruce Wayne",
14
- email: "bruce@wayne.com",
15
- username: "batman",
16
- password: "WhySoSerious"
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"])
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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 'csv'
4
+ require "csv"
5
5
 
6
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
7
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
12
- client.api_key = config['api_key'] || "YOUR_API_KEY"
13
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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 = client.disposable_tokens(username: "eviltrout", quantity: 5, group_names: "security,support")
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 do |value|
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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 = # YOUR NUMERIC 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['groups'].each do |group|
18
- if group['id'] == @target_group_id
19
- @group_name = group['name']
20
- @default_level = group['default_notification_level']
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['group_users'].each do |users_group|
26
- if users_group['group_id'] == @target_group_id
27
- @notification_level = users_group['notification_level']
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['id'], @default_level)
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)['group_users']
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['group_id'] == @target_group_id
35
- puts "Updated ID:#{@target_group_id} #{@group_name} Notification Level: #{users_group_second_pass['notification_level']} Default: #{@default_level}"
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('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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: ["neil", "dan"])
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('trust_level_0')
27
+ members = client.group_members("trust_level_0")
28
28
  puts members
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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")
@@ -1,20 +1,15 @@
1
1
  # frozen_string_literal: true
2
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require File.expand_path('../../lib/discourse_api', __FILE__)
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['host'] || 'http://localhost:3000')
8
- client.api_key = config['api_key'] || "YOUR_API_KEY"
9
- client.api_username = config['api_username'] || "YOUR_USERNAME"
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