discourse_api 0.43.0 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47b23caec63bf36a246bfa9ce104e32ac5e1d0978e2e469154b976fed097aa91
4
- data.tar.gz: afe90f37b0464d43df29b38884c77f747975f805a5f7d17797fbd82c62fa0d9f
3
+ metadata.gz: 83d6fc91bd7fd472cc3eab0fa06b79d0fbaa5e4cf7a2003bef82eee43f33acf4
4
+ data.tar.gz: c0aef1ea4eee35c3cf3143d100707c2850829e5551c79af3a6d6f76efb3b262c
5
5
  SHA512:
6
- metadata.gz: 04a47e1164ab7b298292a840b5263967e333baff682839fe87ed791412364e4e87b6465d36737761ce98271258544519206484a8e06d9396fd2d9514fd6547c3
7
- data.tar.gz: 895e1c5a9e021eb6b6a8fd12e0aa05e45b9865e11bdf10639d1b05941ce4512d311c71cf427b0e9395c94085a63831531e7903c2cbdb5c5fb79aabbacf438906
6
+ metadata.gz: 4227051151b05bd67b403a9922d0199b4cdaf84ccf5973e4be57fb63af8345053b0d80ca763aa2a9c49c27a1a73a623540bde643a714710298c57e73c4a3a0d3
7
+ data.tar.gz: 5a6dfdc85bf1db5edb7e474ecfa1df038a617ebb4d3bf890611d6e195e3093d441e2dbdb3826ad468cc397e6de420f4d4d295b275ad0febb78fb32ae86dfec8e
@@ -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,6 +6,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.46.0] - 2021-04-12
10
+ ### Added
11
+ - Allow bookmarking topics
12
+ - Add timeout to requests
13
+ - Add params to get_topic_posts
14
+
15
+ ## [0.45.1] - 2021-03-11
16
+ ### Added
17
+ - Fetch global top topics
18
+ - Allow setting topic notifications
19
+ - Return full category response
20
+
21
+ ### Changed
22
+ - Use new search endpoint
23
+
24
+ ## [0.45.0] - 2021-01-15
25
+ ### Added
26
+ - Tag configuration in create_category/update_category
27
+ - Topic#change_owner
28
+ - Support passing approved to #create_user
29
+ ### Changed
30
+ - API key methods use the latest endpoints
31
+
32
+ ## [0.44.0] - 2020-11-13
33
+ ### Fixed
34
+ - Updated `show_tag` method to use new route
35
+ ### Removed
36
+ - Support for Ruby 2.3 and 2.4
37
+
38
+ ## [0.43.1] - 2020-11-04
39
+ ### Fixed
40
+ - Tagged version 0.43.0 got pushed without commmit due to new master branch
41
+ protections in github. No, code changes here just making sure tags align with
42
+ commits.
43
+
9
44
  ## [0.43.0] - 2020-11-04
10
45
  ### Added
11
46
  - Add pagination to list groups endpoint
@@ -19,17 +54,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
54
  ## [0.41.0] - 2020-06-17
20
55
  ### Added
21
56
  - Add basic auth support
22
-
23
57
  ### Fixed
24
58
  - Fix SSO custom field prefixes
25
-
26
59
  ### Removed
27
60
  - Obsolete api key endpoints
28
61
 
29
62
  ## [0.40.0] - 2020-05-07
30
63
  ### Fixed
31
64
  - Add missing attributes to `sync_sso`
32
-
33
65
  ### Added
34
66
  - Add delete category method
35
67
 
@@ -51,7 +83,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
51
83
  - Allow more options parameters when creating a category
52
84
  - Don't require topic slug when updating topic status
53
85
  - Example files now read config.yml file when present for client settings
54
-
55
86
  ### Fixed
56
87
  - Issue with `topic_posts` and frozen strings
57
88
  - Fixed some topic and category methods
@@ -303,5 +334,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
303
334
  - `client.category_latest_posts("category-slug")` endpoint
304
335
 
305
336
  ## [0.1.2] - 2014-05-11
306
-
307
337
  - 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
- spec.required_ruby_version = '>= 2.2.3'
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
@@ -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,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
+ # 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)
@@ -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
@@ -12,7 +12,7 @@ module DiscourseApi
12
12
  raise ArgumentError.new("#{term} is required but not specified") unless term
13
13
  raise ArgumentError.new("#{term} is required but not specified") unless !term.empty?
14
14
 
15
- response = get('/search/query', options.merge(term: term))
15
+ response = get('/search', options.merge(q: term))
16
16
  response[:body]
17
17
  end
18
18
  end