discourse_api 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
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 +5 -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 -23
  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 +53 -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 +15 -15
  76. data/spec/fixtures/categories.json +1 -1
  77. data/spec/spec_helper.rb +10 -15
  78. metadata +55 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b3a4fa6e58bafa87e83cc91ac1d064ad4a28d5a16b333348e69e5e34616656a
4
- data.tar.gz: bf82b1cdfb447f2233166d7dced4fdcbd79c7aecbdb1e1831a4df4fa085fbdbb
3
+ metadata.gz: 9f47031bfa7dd5d842e604d3c6abbe2e827e2b0426b2a8de7a7a7bcd7c98acae
4
+ data.tar.gz: acd348ad9e5af8713d4250f69590b38e6e25278ce634eca6967562c601f72a25
5
5
  SHA512:
6
- metadata.gz: 3852fbddac9d6fd014683731c3d86fdebb29c2805729a0c82802362c7e0cd6a1904be8b63a514ef26520f23864b2540eae3e78f9a40bf8cf2f6d8f097bc145ff
7
- data.tar.gz: b264bbe0726bc891188318f680425e7512a66ce7e87c5a7d41e4a3010b0c528acae122c3299e687728ec4ea4d0fb24c42802bf73eb1f3b60c3d70b6c1375b008
6
+ metadata.gz: a6b94a3a14a8f7bcbf4d540e0f92bc0afad8acf8a91d46b3ec939565ebe9a13c5f69baf2eafe41eb56be8008904eb08533fc0ce05803f8c9ee0886758ae05b5d
7
+ data.tar.gz: adcd6538209fc97b605aba126364a0ba4c73e404bae21116bd208181618f4ede69315408282e77317087e4c472fd0980dc3c24f33add64299af992611d9a4dba
@@ -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,11 @@ 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
+
9
14
  ## [1.1.0] - 2022-07-05
10
15
  ### Changed
11
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.
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