discourse_api 0.44.0 → 0.47.0

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