discourse_api 0.44.0 → 0.45.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: 13cfa5b25dbe59e809cdcdb924406f9e680f1e029a5666fff9a0febbd75d5bf0
4
- data.tar.gz: d68c096a8ae91dea4a70b60f9d412954712297544e49b891fc228f11d63ca4d6
3
+ metadata.gz: 82cd748487d5d986f8327b702088ea4ea22c43cae311c2634dfa5d9cf4c4059f
4
+ data.tar.gz: a4fd68101134895f5071443f221a2327e9fe9e4a0a79df0d53a620c7e08d685d
5
5
  SHA512:
6
- metadata.gz: c942a353d95a144daa1939d448c949ad56a00e0999a0166c112e403e0ce5529941e8883d7456b029a173cdc79ebf7ffc08e84cc7e2e63956434ab00a6a60abf0
7
- data.tar.gz: 909bb8f30f2ae412c93d1e0a9777786b8cae01c4bd15474f5ea980c0485bb91ca82f5eb62a81773f76a05b8eeb97bde076411a0dbe61e4407c0ca2204ac5484e
6
+ metadata.gz: 42546f17e134cd1e4ac6be81c8fdb53cf82461d60a73859dd757c2ec69e1128127f33a131e45dfec3d910012702256a173a7a1afd2a9873dc3d8a3e220c4af1a
7
+ data.tar.gz: 990fc89fd2a4935704e1512b858872b41ed7a6b7ba3ef28f583ad272e0675daff74f61b9a441632a8dc92c76892b8c507e53afce356317403c7c67f31a4fab18
@@ -6,16 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.45.0] - 2021-01-15
10
+ ### Added
11
+ - Tag configuration in create_category/update_category
12
+ - Topic#change_owner
13
+ - Support passing approved to #create_user
14
+ ### Changed
15
+ - API key methods use the latest endpoints
16
+
9
17
  ## [0.44.0] - 2020-11-13
10
18
  ### Fixed
11
19
  - Updated `show_tag` method to use new route
12
-
13
20
  ### Removed
14
21
  - Support for Ruby 2.3 and 2.4
15
22
 
16
23
  ## [0.43.1] - 2020-11-04
17
24
  ### Fixed
18
- - tagged verion 0.43.0 got pushed without commmit due to new master branch
25
+ - Tagged version 0.43.0 got pushed without commmit due to new master branch
19
26
  protections in github. No, code changes here just making sure tags align with
20
27
  commits.
21
28
 
@@ -32,17 +39,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
39
  ## [0.41.0] - 2020-06-17
33
40
  ### Added
34
41
  - Add basic auth support
35
-
36
42
  ### Fixed
37
43
  - Fix SSO custom field prefixes
38
-
39
44
  ### Removed
40
45
  - Obsolete api key endpoints
41
46
 
42
47
  ## [0.40.0] - 2020-05-07
43
48
  ### Fixed
44
49
  - Add missing attributes to `sync_sso`
45
-
46
50
  ### Added
47
51
  - Add delete category method
48
52
 
@@ -64,7 +68,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
64
68
  - Allow more options parameters when creating a category
65
69
  - Don't require topic slug when updating topic status
66
70
  - Example files now read config.yml file when present for client settings
67
-
68
71
  ### Fixed
69
72
  - Issue with `topic_posts` and frozen strings
70
73
  - Fixed some topic and category methods
@@ -316,5 +319,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
316
319
  - `client.category_latest_posts("category-slug")` endpoint
317
320
 
318
321
  ## [0.1.2] - 2014-05-11
319
-
320
322
  - Release
@@ -29,7 +29,7 @@ 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'
32
+ spec.add_development_dependency 'webmock', '~> 3.0'
33
33
  spec.add_development_dependency 'rubocop-discourse'
34
34
 
35
35
  spec.required_ruby_version = '>= 2.5.0'
@@ -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"}
@@ -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']
@@ -78,6 +78,13 @@ module DiscourseApi
78
78
  response = get(url.join)
79
79
  response[:body]
80
80
  end
81
+
82
+ def change_owner(topic_id, params = {})
83
+ params = API.params(params)
84
+ .required(:username, :post_ids)
85
+
86
+ post("/t/#{topic_id}/change-owner.json", params)
87
+ end
81
88
  end
82
89
  end
83
90
  end
@@ -52,7 +52,7 @@ module DiscourseApi
52
52
  def create_user(args)
53
53
  args = API.params(args)
54
54
  .required(:name, :email, :password, :username)
55
- .optional(:active, :staged, :user_fields)
55
+ .optional(:active, :approved, :staged, :user_fields)
56
56
  .to_h
57
57
  post("/users", args)
58
58
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseApi
3
- VERSION = "0.44.0"
3
+ VERSION = "0.45.0"
4
4
  end
@@ -10,77 +10,101 @@ describe DiscourseApi::API::ApiKey do
10
10
  )
11
11
  }
12
12
 
13
- describe "#api" do
13
+ describe "#list_api_keys" do
14
14
  before do
15
- url = "#{host}/admin/api.json"
16
- stub_get(url).to_return(body: fixture("api.json"),
15
+ url = "#{host}/admin/api/keys"
16
+ stub_get(url).to_return(body: fixture("list_api_keys.json"),
17
17
  headers: { content_type: "application/json" })
18
18
  end
19
19
 
20
20
  it "requests the correct resource" do
21
- subject.api
22
- url = "#{host}/admin/api.json"
21
+ subject.list_api_keys
22
+ url = "#{host}/admin/api/keys"
23
23
  expect(a_get(url)).to have_been_made
24
24
  end
25
25
 
26
26
  it "returns the requested api keys" do
27
- api = subject.api
28
- expect(api).to be_an Array
29
- expect(api.first).to be_a Hash
30
- expect(api.first).to have_key('key')
27
+ keys = subject.list_api_keys
28
+ expect(keys["keys"]).to be_an Array
29
+ expect(keys["keys"].first).to be_a Hash
30
+ expect(keys["keys"].first).to have_key('key')
31
31
  end
32
32
  end
33
33
 
34
- describe "#generate_master_key" do
34
+ describe "#create_api_key" do
35
35
  before do
36
- url = "#{host}/admin/api/key"
37
- stub_post(url).to_return(body: fixture("generate_master_key.json"),
36
+ url = "#{host}/admin/api/keys"
37
+ stub_post(url).to_return(body: fixture("api_key.json"),
38
38
  headers: { content_type: "application/json" })
39
39
  end
40
40
 
41
- it "returns the generated master key" do
42
- master_key = subject.generate_master_key
43
- expect(master_key).to be_a Hash
44
- expect(master_key['api_key']).to have_key('key')
45
- expect(master_key['api_key']['user']).to eq(nil)
41
+ it "requests the correct resource" do
42
+ subject.create_api_key(key: { username: 'robin' })
43
+ url = "#{host}/admin/api/keys"
44
+ expect(a_post(url)).to have_been_made
45
+ end
46
+
47
+ it "returns the generated api key" do
48
+ api_key = subject.create_api_key(key: { username: 'robin' })
49
+ expect(api_key).to be_a Hash
50
+ expect(api_key['key']).to have_key('key')
46
51
  end
47
52
  end
48
53
 
49
54
  describe "#revoke_api_key" do
50
55
  before do
51
- url = "#{host}/admin/api/key?id=10"
52
- stub_delete(url).to_return(body: "",
53
- headers: { content_type: "application/json" })
56
+ url = "#{host}/admin/api/keys/10/revoke"
57
+ stub_post(url).to_return(body: fixture("api_key.json"),
58
+ headers: { content_type: "application/json" })
54
59
  end
55
60
 
56
61
  it "requests the correct resource" do
57
62
  subject.revoke_api_key(10)
58
- url = "#{host}/admin/api/key?id=10"
59
- expect(a_delete(url)).to have_been_made
63
+ url = "#{host}/admin/api/keys/10/revoke"
64
+ expect(a_post(url)).to have_been_made
60
65
  end
61
66
 
62
- it "returns 200" do
63
- response = subject.revoke_api_key(10)
64
- expect(response['status']).to eq(200)
67
+ it "returns the api key" do
68
+ api_key = subject.revoke_api_key(10)
69
+ expect(api_key['key']).to have_key('key')
65
70
  end
66
71
  end
67
72
 
68
- describe "#regenerate_api_key" do
73
+ describe "#undo_revoke_api_key" do
69
74
  before do
70
- url = "#{host}/admin/api/key"
71
- stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
72
- headers: { content_type: "application/json" })
75
+ url = "#{host}/admin/api/keys/10/undo-revoke"
76
+ stub_post(url).to_return(body: fixture("api_key.json"),
77
+ headers: { content_type: "application/json" })
73
78
  end
74
79
 
75
80
  it "requests the correct resource" do
76
- subject.regenerate_api_key(10)
77
- url = "#{host}/admin/api/key"
78
- expect(a_put(url)).to have_been_made
81
+ subject.undo_revoke_api_key(10)
82
+ url = "#{host}/admin/api/keys/10/undo-revoke"
83
+ expect(a_post(url)).to have_been_made
79
84
  end
80
85
 
81
- it "returns the regenerated api key" do
82
- key = subject.regenerate_api_key(10)
83
- expect(key['api_key']).to have_key('key')
86
+ it "returns the api key" do
87
+ api_key = subject.undo_revoke_api_key(10)
88
+ expect(api_key['key']).to have_key('key')
89
+ end
90
+ end
91
+
92
+ describe "#delete_api_key" do
93
+ before do
94
+ url = "#{host}/admin/api/keys/10"
95
+ stub_delete(url).to_return(body: '{"success": "OK"}',
96
+ headers: { content_type: "application/json" })
97
+ end
98
+
99
+ it "requests the correct resource" do
100
+ subject.delete_api_key(10)
101
+ url = "#{host}/admin/api/keys/10"
102
+ expect(a_delete(url)).to have_been_made
103
+ end
104
+
105
+ it "returns 200" do
106
+ response = subject.delete_api_key(10)
107
+ expect(response['status']).to eq(200)
84
108
  end
85
109
  end
86
110
  end
@@ -0,0 +1,12 @@
1
+ {
2
+ "key": {
3
+ "id": 5,
4
+ "key": "e722e04df8cf6d097d565ca04eea1ff8e9e8f09beb405bae6f0c79852916f334",
5
+ "user": {
6
+ "id": 2,
7
+ "username": "robin",
8
+ "uploaded_avatar_id": 3,
9
+ "avatar_template": "/user_avatar/localhost/robin/{size}/3.png"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "keys": [
3
+ {
4
+ "id": 1,
5
+ "key": "test_d7fd0429940",
6
+ "user": {
7
+ "id": 1,
8
+ "username": "test_user",
9
+ "uploaded_avatar_id": 7,
10
+ "avatar_template": "/user_avatar/localhost/test_user/{size}/7.png"
11
+ }
12
+ }
13
+ ]
14
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.0
4
+ version: 0.45.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-11-13 00:00:00.000000000 Z
14
+ date: 2021-01-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faraday
@@ -159,14 +159,14 @@ dependencies:
159
159
  requirements:
160
160
  - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: '2.0'
162
+ version: '3.0'
163
163
  type: :development
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
167
167
  - - "~>"
168
168
  - !ruby/object:Gem::Version
169
- version: '2.0'
169
+ version: '3.0'
170
170
  - !ruby/object:Gem::Dependency
171
171
  name: rubocop-discourse
172
172
  requirement: !ruby/object:Gem::Requirement
@@ -216,6 +216,7 @@ files:
216
216
  - examples/group_set_user_notification_level.rb
217
217
  - examples/groups.rb
218
218
  - examples/invite_users.rb
219
+ - examples/manage_api_keys.rb
219
220
  - examples/polls.rb
220
221
  - examples/post_action.rb
221
222
  - examples/search.rb
@@ -271,7 +272,7 @@ files:
271
272
  - spec/discourse_api/api/users_spec.rb
272
273
  - spec/discourse_api/client_spec.rb
273
274
  - spec/fixtures/admin_user.json
274
- - spec/fixtures/api.json
275
+ - spec/fixtures/api_key.json
275
276
  - spec/fixtures/backups.json
276
277
  - spec/fixtures/badges.json
277
278
  - spec/fixtures/categories.json
@@ -280,11 +281,11 @@ files:
280
281
  - spec/fixtures/create_topic_with_tags.json
281
282
  - spec/fixtures/email_list_all.json
282
283
  - spec/fixtures/email_settings.json
283
- - spec/fixtures/generate_master_key.json
284
284
  - spec/fixtures/group.json
285
285
  - spec/fixtures/groups.json
286
286
  - spec/fixtures/hot.json
287
287
  - spec/fixtures/latest.json
288
+ - spec/fixtures/list_api_keys.json
288
289
  - spec/fixtures/members_0.json
289
290
  - spec/fixtures/members_1.json
290
291
  - spec/fixtures/members_2.json
@@ -365,7 +366,7 @@ test_files:
365
366
  - spec/discourse_api/api/users_spec.rb
366
367
  - spec/discourse_api/client_spec.rb
367
368
  - spec/fixtures/admin_user.json
368
- - spec/fixtures/api.json
369
+ - spec/fixtures/api_key.json
369
370
  - spec/fixtures/backups.json
370
371
  - spec/fixtures/badges.json
371
372
  - spec/fixtures/categories.json
@@ -374,11 +375,11 @@ test_files:
374
375
  - spec/fixtures/create_topic_with_tags.json
375
376
  - spec/fixtures/email_list_all.json
376
377
  - spec/fixtures/email_settings.json
377
- - spec/fixtures/generate_master_key.json
378
378
  - spec/fixtures/group.json
379
379
  - spec/fixtures/groups.json
380
380
  - spec/fixtures/hot.json
381
381
  - spec/fixtures/latest.json
382
+ - spec/fixtures/list_api_keys.json
382
383
  - spec/fixtures/members_0.json
383
384
  - spec/fixtures/members_1.json
384
385
  - spec/fixtures/members_2.json
@@ -1,12 +0,0 @@
1
- [
2
- {
3
- "id": 1,
4
- "key": "test_d7fd0429940",
5
- "user": {
6
- "id": 1,
7
- "username": "test_user",
8
- "uploaded_avatar_id": 7,
9
- "avatar_template": "/user_avatar/localhost/test_user/{size}/7.png"
10
- }
11
- }
12
- ]
@@ -1,7 +0,0 @@
1
- {
2
- "api_key": {
3
- "id": 10,
4
- "key": "c999afe41d3a6ed0798a13ef69f90c4cc7d38120818c4a098e402bc5e5ef2085",
5
- "user": null
6
- }
7
- }