discourse_api 0.44.0 → 0.45.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -7
- data/discourse_api.gemspec +1 -1
- data/examples/manage_api_keys.rb +42 -0
- data/lib/discourse_api/api/api_key.rb +15 -9
- data/lib/discourse_api/api/categories.rb +4 -2
- data/lib/discourse_api/api/topics.rb +7 -0
- data/lib/discourse_api/api/users.rb +1 -1
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +59 -35
- data/spec/fixtures/api_key.json +12 -0
- data/spec/fixtures/list_api_keys.json +14 -0
- metadata +9 -8
- data/spec/fixtures/api.json +0 -12
- data/spec/fixtures/generate_master_key.json +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82cd748487d5d986f8327b702088ea4ea22c43cae311c2634dfa5d9cf4c4059f
|
4
|
+
data.tar.gz: a4fd68101134895f5071443f221a2327e9fe9e4a0a79df0d53a620c7e08d685d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42546f17e134cd1e4ac6be81c8fdb53cf82461d60a73859dd757c2ec69e1128127f33a131e45dfec3d910012702256a173a7a1afd2a9873dc3d8a3e220c4af1a
|
7
|
+
data.tar.gz: 990fc89fd2a4935704e1512b858872b41ed7a6b7ba3ef28f583ad272e0675daff74f61b9a441632a8dc92c76892b8c507e53afce356317403c7c67f31a4fab18
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
-
|
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
|
data/discourse_api.gemspec
CHANGED
@@ -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', '~>
|
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
|
6
|
-
response = get("/admin/api
|
7
|
-
response
|
5
|
+
def list_api_keys
|
6
|
+
response = get("/admin/api/keys")
|
7
|
+
response[:body]
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
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
|
-
|
18
|
+
post("/admin/api/keys/#{id}/revoke")
|
16
19
|
end
|
17
20
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
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
|
@@ -10,77 +10,101 @@ describe DiscourseApi::API::ApiKey do
|
|
10
10
|
)
|
11
11
|
}
|
12
12
|
|
13
|
-
describe "#
|
13
|
+
describe "#list_api_keys" do
|
14
14
|
before do
|
15
|
-
url = "#{host}/admin/api
|
16
|
-
stub_get(url).to_return(body: fixture("
|
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.
|
22
|
-
url = "#{host}/admin/api
|
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
|
-
|
28
|
-
expect(
|
29
|
-
expect(
|
30
|
-
expect(
|
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 "#
|
34
|
+
describe "#create_api_key" do
|
35
35
|
before do
|
36
|
-
url = "#{host}/admin/api/
|
37
|
-
stub_post(url).to_return(body: fixture("
|
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 "
|
42
|
-
|
43
|
-
|
44
|
-
expect(
|
45
|
-
|
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/
|
52
|
-
|
53
|
-
|
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/
|
59
|
-
expect(
|
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
|
63
|
-
|
64
|
-
expect(
|
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 "#
|
73
|
+
describe "#undo_revoke_api_key" do
|
69
74
|
before do
|
70
|
-
url = "#{host}/admin/api/
|
71
|
-
|
72
|
-
|
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.
|
77
|
-
url = "#{host}/admin/api/
|
78
|
-
expect(
|
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
|
82
|
-
|
83
|
-
expect(
|
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
|
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.
|
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:
|
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: '
|
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: '
|
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/
|
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/
|
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
|
data/spec/fixtures/api.json
DELETED