discourse_api 0.3.0 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG.md +16 -2
- data/README.md +2 -0
- data/examples/category.rb +12 -0
- data/lib/discourse_api/api/api_admin.rb +10 -0
- data/lib/discourse_api/api/backups.rb +10 -0
- data/lib/discourse_api/api/badges.rb +15 -0
- data/lib/discourse_api/api/categories.rb +13 -7
- data/lib/discourse_api/api/email.rb +15 -0
- data/lib/discourse_api/api/groups.rb +5 -6
- data/lib/discourse_api/api/params.rb +1 -1
- data/lib/discourse_api/api/posts.rb +15 -1
- data/lib/discourse_api/api/topics.rb +8 -8
- data/lib/discourse_api/api/users.rb +20 -14
- data/lib/discourse_api/client.rb +17 -5
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_admin_spec.rb +23 -0
- data/spec/discourse_api/api/backups_spec.rb +23 -0
- data/spec/discourse_api/api/badges_spec.rb +40 -0
- data/spec/discourse_api/api/categories_spec.rb +6 -0
- data/spec/discourse_api/api/email_spec.rb +39 -0
- data/spec/discourse_api/api/params_spec.rb +20 -0
- data/spec/discourse_api/api/posts_spec.rb +29 -0
- data/spec/discourse_api/api/topics_spec.rb +6 -0
- data/spec/discourse_api/api/users_spec.rb +78 -8
- data/spec/fixtures/api.json +12 -0
- data/spec/fixtures/backups.json +12 -0
- data/spec/fixtures/badges.json +569 -0
- data/spec/fixtures/email_list_all.json +749 -0
- data/spec/fixtures/email_settings.json +13 -0
- data/spec/fixtures/post.json +94 -0
- data/spec/fixtures/user_activate_success.json +3 -0
- data/spec/fixtures/user_badges.json +170 -0
- data/spec/fixtures/user_list.json +583 -0
- data/spec/fixtures/user_log_out_success.json +3 -0
- data/spec/fixtures/user_update_avatar_success.json +3 -0
- data/spec/fixtures/user_update_username.json +2 -1
- metadata +66 -28
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDkwMWZjYTQ0MzkwZDY3ODNkMjdlNjFkOTZiMTUzOTMzMmQ5YzIyMQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10a7f2e9839bfeea9edbb43a4f2fe535723e237e
|
4
|
+
data.tar.gz: d8de8c9500231bd8ba26593e2ac7b266e4be067c
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MDllNzlkNmJkNjA5MjEzMzY1MDg5MTNlM2E1YWQxNTU1YmMxMzE0MjRlNTQz
|
11
|
-
YjdkZTNlMzEwYjQ3OTk2MzRhZjQ0ZWRmN2JlZWQ5YzBiMjc1NjE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NmFhYzQyYTAwYjdjMzRiNzgxYmQ3OWM4NzE5MWVlOTkzZmFlNWQxYzI2NzBi
|
14
|
-
ZWY3ODNlODZmNzFjNGY1ZmZlN2I1NDY0MDBhODUzYjJiOTBiOTA0NGFhYjE2
|
15
|
-
ZWJjMDdiZTU4NWU4ODliOGQ4NWRiMjdiZmQ4Y2M3NGYwYjk3NjA=
|
6
|
+
metadata.gz: 14b552567338b8f699eeb77efa4de86e334052989a5cdbf6007ecfde4e1a128e9d03ae1d9d9c2c5a501fe1f3da2f76572122b26472f60c462c909bbf2107aaa4
|
7
|
+
data.tar.gz: 61ac275015ae01fef9b9e0b6434e2c175a1f17b7dab3bd291418b53284063e7da45373affab2a741e4f74eaf4f3de6b5748c5683258307411feee37e2a8ee442
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,22 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
-
|
5
|
+
- Added `client.category_latest_posts("category-slug")` endpoint
|
6
6
|
|
7
7
|
## 0.1.2
|
8
8
|
|
9
|
-
|
9
|
+
- Release
|
10
|
+
|
11
|
+
## 0.3.5
|
12
|
+
|
13
|
+
- Can now get a list of users by type: active, new, staff, etc.
|
14
|
+
|
15
|
+
## 0.3.6
|
16
|
+
|
17
|
+
- list badges
|
18
|
+
- view email settings
|
19
|
+
- list emails sent
|
20
|
+
- list badges by user
|
21
|
+
- be able to specify SSL connection settings
|
22
|
+
- list api keys generated
|
23
|
+
- list backups created
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ client = DiscourseApi::Client.new("http://try.discourse.org")
|
|
32
32
|
client.api_key = "YOUR_API_KEY"
|
33
33
|
client.api_username = "YOUR_USERNAME"
|
34
34
|
|
35
|
+
client.ssl(...) #=> specify SSL connection settings if needed
|
36
|
+
|
35
37
|
# Topic endpoints
|
36
38
|
client.latest_topics #=> Gets a list of the latest topics
|
37
39
|
client.hot_topics #=> Gets a list of hot topics
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
|
+
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
7
|
+
|
8
|
+
# get categories
|
9
|
+
puts client.categories()
|
10
|
+
|
11
|
+
# get sub categories for parent category with id 2
|
12
|
+
puts client.categories(parent_category_id: 2)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Badges
|
4
|
+
def badges
|
5
|
+
response = get("/admin/badges.json")
|
6
|
+
response.body
|
7
|
+
end
|
8
|
+
|
9
|
+
def user_badges(username)
|
10
|
+
response = get("/users/#{username}/activity/badges.json")
|
11
|
+
response.body['badges']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -3,15 +3,16 @@ module DiscourseApi
|
|
3
3
|
module Categories
|
4
4
|
# :color and :text_color are RGB hexadecimal strings
|
5
5
|
def create_category(args)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
params = API.params(args)
|
7
|
+
.required(:name, :color, :text_color)
|
8
|
+
.optional(:description)
|
9
|
+
.default(parent_category_id: nil)
|
10
|
+
response = (post "/categories", params)
|
11
|
+
response['category']
|
11
12
|
end
|
12
13
|
|
13
|
-
def categories(
|
14
|
-
response = get('/categories.json',
|
14
|
+
def categories(params={})
|
15
|
+
response = get('/categories.json', params)
|
15
16
|
response[:body]['category_list']['categories']
|
16
17
|
end
|
17
18
|
|
@@ -19,6 +20,11 @@ module DiscourseApi
|
|
19
20
|
response = get("/category/#{category_slug}/l/latest.json")
|
20
21
|
response[:body]['topic_list']['topics']
|
21
22
|
end
|
23
|
+
|
24
|
+
def category(id)
|
25
|
+
response = get("/c/#{id}/show")
|
26
|
+
response.body['category']
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -2,12 +2,11 @@ module DiscourseApi
|
|
2
2
|
module API
|
3
3
|
module Groups
|
4
4
|
def create_group(args)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
)
|
5
|
+
params = API.params(args)
|
6
|
+
.required(:name)
|
7
|
+
.default(visible: true)
|
8
|
+
.to_h
|
9
|
+
post("/admin/groups", group: params)
|
11
10
|
end
|
12
11
|
|
13
12
|
def groups
|
@@ -3,7 +3,21 @@ module DiscourseApi
|
|
3
3
|
module Posts
|
4
4
|
def create_post(args)
|
5
5
|
post("/posts", API.params(args)
|
6
|
-
|
6
|
+
.required(:topic_id, :raw))
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_post(id, args = {})
|
10
|
+
response = get("/posts/#{id}.json", API.params(args)
|
11
|
+
.optional(:version))
|
12
|
+
response[:body]
|
13
|
+
end
|
14
|
+
|
15
|
+
def wikify_post(id)
|
16
|
+
put("/posts/#{id}/wiki", wiki: true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def edit_post(id, raw)
|
20
|
+
put("/posts/#{id}", post: {raw: raw})
|
7
21
|
end
|
8
22
|
end
|
9
23
|
end
|
@@ -14,13 +14,13 @@ module DiscourseApi
|
|
14
14
|
post("/posts", args.to_h)
|
15
15
|
end
|
16
16
|
|
17
|
-
def latest_topics(
|
18
|
-
response = get('/latest.json',
|
17
|
+
def latest_topics(params={})
|
18
|
+
response = get('/latest.json', params)
|
19
19
|
response[:body]['topic_list']['topics']
|
20
20
|
end
|
21
21
|
|
22
|
-
def new_topics(
|
23
|
-
response = get("/new.json",
|
22
|
+
def new_topics(params={})
|
23
|
+
response = get("/new.json", params)
|
24
24
|
response[:body]['topic_list']['topics']
|
25
25
|
end
|
26
26
|
|
@@ -32,13 +32,13 @@ module DiscourseApi
|
|
32
32
|
put("/t/#{topic_id}.json", { topic_id: topic_id, category_id: category_id })
|
33
33
|
end
|
34
34
|
|
35
|
-
def topic(id,
|
36
|
-
response = get("/t/#{id}.json",
|
35
|
+
def topic(id, params={})
|
36
|
+
response = get("/t/#{id}.json", params)
|
37
37
|
response[:body]
|
38
38
|
end
|
39
39
|
|
40
|
-
def topics_by(username,
|
41
|
-
response = get("/topics/created-by/#{username}.json",
|
40
|
+
def topics_by(username, params={})
|
41
|
+
response = get("/topics/created-by/#{username}.json", params)
|
42
42
|
response[:body]['topic_list']['topics']
|
43
43
|
end
|
44
44
|
|
@@ -5,13 +5,18 @@ module DiscourseApi
|
|
5
5
|
put "/admin/users/#{id}/activate", api_key: api_key, api_username: api_username
|
6
6
|
end
|
7
7
|
|
8
|
-
def user(username,
|
9
|
-
response = get("/users/#{username}.json",
|
8
|
+
def user(username, params={})
|
9
|
+
response = get("/users/#{username}.json", params)
|
10
10
|
response[:body]['user']
|
11
11
|
end
|
12
12
|
|
13
|
-
def update_avatar(
|
14
|
-
|
13
|
+
def update_avatar(args)
|
14
|
+
params = API.params(args)
|
15
|
+
.required(:username, :file)
|
16
|
+
.default(image_type: 'avatar')
|
17
|
+
.to_h
|
18
|
+
upload_response = post("/users/#{args[:username]}/preferences/user_image", params)
|
19
|
+
put("/users/#{args[:username]}/preferences/avatar/pick", { upload_id: upload_response['upload_id'] })
|
15
20
|
end
|
16
21
|
|
17
22
|
def update_email(username, email)
|
@@ -26,16 +31,12 @@ module DiscourseApi
|
|
26
31
|
put("/users/#{username}/preferences/username", { new_username: new_username, api_key: api_key })
|
27
32
|
end
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
args[:challenge] = response[:body]['challenge'].reverse
|
36
|
-
|
37
|
-
# POST the args
|
38
|
-
post("/users", args)
|
34
|
+
def create_user(args)
|
35
|
+
params = API.params(args)
|
36
|
+
.required(:name, :email, :password, :username)
|
37
|
+
.optional(:active)
|
38
|
+
.to_h
|
39
|
+
post("/users", params)
|
39
40
|
end
|
40
41
|
|
41
42
|
def log_out(id)
|
@@ -45,6 +46,11 @@ module DiscourseApi
|
|
45
46
|
def invite_admin(args={})
|
46
47
|
post("/admin/users/invite_admin", args)
|
47
48
|
end
|
49
|
+
|
50
|
+
def list_users(type)
|
51
|
+
response = get("admin/users/list/#{type}.json")
|
52
|
+
response[:body]
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
data/lib/discourse_api/client.rb
CHANGED
@@ -13,6 +13,10 @@ require 'discourse_api/api/groups'
|
|
13
13
|
require 'discourse_api/api/invite'
|
14
14
|
require 'discourse_api/api/private_messages'
|
15
15
|
require 'discourse_api/api/notifications'
|
16
|
+
require 'discourse_api/api/badges'
|
17
|
+
require 'discourse_api/api/email'
|
18
|
+
require 'discourse_api/api/api_admin'
|
19
|
+
require 'discourse_api/api/backups'
|
16
20
|
|
17
21
|
module DiscourseApi
|
18
22
|
class Client
|
@@ -29,6 +33,10 @@ module DiscourseApi
|
|
29
33
|
include DiscourseApi::API::Invite
|
30
34
|
include DiscourseApi::API::PrivateMessages
|
31
35
|
include DiscourseApi::API::Notifications
|
36
|
+
include DiscourseApi::API::Badges
|
37
|
+
include DiscourseApi::API::Email
|
38
|
+
include DiscourseApi::API::ApiAdmin
|
39
|
+
include DiscourseApi::API::Backups
|
32
40
|
|
33
41
|
def initialize(host = ENV["DISCOURSE_URL"],
|
34
42
|
api_key = ENV["DISCOURSE_API_KEY"],
|
@@ -41,14 +49,18 @@ module DiscourseApi
|
|
41
49
|
|
42
50
|
def connection_options
|
43
51
|
@connection_options ||= {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
url: @host,
|
53
|
+
headers: {
|
54
|
+
accept: 'application/json',
|
55
|
+
user_agent: user_agent,
|
56
|
+
}
|
49
57
|
}
|
50
58
|
end
|
51
59
|
|
60
|
+
def ssl(options)
|
61
|
+
connection_options[:ssl] = options
|
62
|
+
end
|
63
|
+
|
52
64
|
def delete(path, params={})
|
53
65
|
request(:delete, path, params)
|
54
66
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::ApiAdmin do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
+
|
6
|
+
describe "#api" do
|
7
|
+
before do
|
8
|
+
stub_get("http://localhost:3000/admin/api.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("api.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.api
|
13
|
+
expect(a_get("http://localhost:3000/admin/api.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the requested api keys" do
|
17
|
+
api = subject.api
|
18
|
+
expect(api).to be_an Array
|
19
|
+
expect(api.first).to be_a Hash
|
20
|
+
expect(api.first).to have_key('key')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Backups do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
+
|
6
|
+
describe "#backups" do
|
7
|
+
before do
|
8
|
+
stub_get("http://localhost:3000/admin/backups.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.backups
|
13
|
+
expect(a_get("http://localhost:3000/admin/backups.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the requested backups" do
|
17
|
+
backups = subject.backups
|
18
|
+
expect(backups).to be_an Array
|
19
|
+
expect(backups.first).to be_a Hash
|
20
|
+
expect(backups.first).to have_key('filename')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Badges do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
+
|
6
|
+
describe "#badges" do
|
7
|
+
before do
|
8
|
+
stub_get("http://localhost:3000/admin/badges.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.badges
|
13
|
+
expect(a_get("http://localhost:3000/admin/badges.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the requested badges" do
|
17
|
+
badges = subject.badges
|
18
|
+
expect(badges).to be_a Hash
|
19
|
+
expect(badges['badges']).to be_an Array
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#user_badges" do
|
24
|
+
before do
|
25
|
+
stub_get("http://localhost:3000/users/test_user/activity/badges.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
|
26
|
+
end
|
27
|
+
|
28
|
+
it "requests the correct resource" do
|
29
|
+
subject.user_badges('test_user')
|
30
|
+
expect(a_get("http://localhost:3000/users/test_user/activity/badges.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns the requested user badges" do
|
34
|
+
badges = subject.user_badges('test_user')
|
35
|
+
expect(badges).to be_an Array
|
36
|
+
expect(badges.first).to be_a Hash
|
37
|
+
expect(badges.first).to have_key('badge_type_id')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|