discourse_api 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/examples/category.rb +9 -0
- data/examples/groups.rb +5 -1
- data/examples/search.rb +9 -0
- data/examples/update_user.rb +4 -1
- data/lib/discourse_api/api/badges.rb +9 -0
- data/lib/discourse_api/api/categories.rb +14 -4
- data/lib/discourse_api/api/groups.rb +4 -0
- data/lib/discourse_api/api/params.rb +1 -0
- data/lib/discourse_api/api/topics.rb +1 -1
- data/lib/discourse_api/api/users.rb +5 -4
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/categories_spec.rb +21 -3
- data/spec/discourse_api/api/users_spec.rb +2 -2
- data/spec/fixtures/upload_avatar.json +14 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eac07223361b0ddc7428468198b3a764d602560a
|
4
|
+
data.tar.gz: be2c419474dd915e32a76eca7f7c5d1757ea761c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc02e2ac5803e71f44f505071e8ea6564f2c606db45c2a6253464efd43d980d864b643b402a3d96b0922e1991d74a44495bfcb529c97e3ef66e3b22d23787d73
|
7
|
+
data.tar.gz: 5656c1a6228a091101c92536829fc40472807595e701f26b8ed3a8e810f1671d42f4587c5d2c8def889c4e34b7b4e32a2202af2fc77817976161f9e0315393dc
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/examples/category.rb
CHANGED
@@ -10,3 +10,12 @@ puts client.categories()
|
|
10
10
|
|
11
11
|
# get sub categories for parent category with id 2
|
12
12
|
puts client.categories(parent_category_id: 2)
|
13
|
+
|
14
|
+
# List topics in a category
|
15
|
+
category_topics = client.category_latest_topics(category_slug: "test-category")
|
16
|
+
puts category_topics
|
17
|
+
|
18
|
+
# List topics in a category paged
|
19
|
+
category_topics_paged = client.category_latest_topics(category_slug: "test-category", page: "5")
|
20
|
+
puts category_topics_paged
|
21
|
+
|
data/examples/groups.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
2
|
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
3
|
|
4
|
-
client = DiscourseApi::Client.new
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
5
7
|
|
6
8
|
response = client.create_group(name: "engineering_team")
|
7
9
|
group_id = response["basic_group"]["id"]
|
@@ -14,3 +16,5 @@ client.group_add(group_id, user_ids: [123, 456])
|
|
14
16
|
|
15
17
|
client.group_remove(group_id, username: "neil")
|
16
18
|
client.group_remove(group_id, user_id: 123)
|
19
|
+
|
20
|
+
client.delete_group(group_id)
|
data/examples/search.rb
ADDED
@@ -0,0 +1,9 @@
|
|
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
|
+
# search for term
|
9
|
+
puts client.search("discourse")
|
data/examples/update_user.rb
CHANGED
@@ -12,8 +12,11 @@ puts client.update_user("batman", name: "Bruce Wayne")
|
|
12
12
|
# update email of user whose username is "batman"
|
13
13
|
puts client.update_email("batman", "batman@gotham.com")
|
14
14
|
# update avatar of user whose username is "batman"
|
15
|
-
puts client.update_avatar("batman", "http://meta-discourse.r.worldssl.net/uploads/default/2497/724a6ef2e79d2bc7.png")
|
15
|
+
puts client.update_avatar(username: "batman", url: "http://meta-discourse.r.worldssl.net/uploads/default/2497/724a6ef2e79d2bc7.png")
|
16
16
|
# update trust level of user whose id is "102"
|
17
17
|
puts client.update_trust_level(user_id: 102, level: 2)
|
18
|
+
# update user bio, location or website
|
19
|
+
puts client.update_user("batman", bio_raw: "I am Batman.", location: "Gotham", website: "https://en.wikipedia.org/wiki/Batman")
|
20
|
+
|
18
21
|
# log out everywhere and refresh browser of user whose id is "2"
|
19
22
|
puts client.log_out(2)
|
@@ -14,6 +14,15 @@ module DiscourseApi
|
|
14
14
|
def grant_user_badge(params={})
|
15
15
|
post("/user_badges", params)
|
16
16
|
end
|
17
|
+
|
18
|
+
def create_badge(params={})
|
19
|
+
args = API.params(params)
|
20
|
+
.required(:name, :badge_type_id)
|
21
|
+
.optional(:description, :allow_title, :multiple_grant, :icon, :listable,
|
22
|
+
:target_posts, :query, :enabled, :auto_revoke, :badge_grouping_id,
|
23
|
+
:trigger, :show_posts, :image, :long_description)
|
24
|
+
post("/admin/badges.json", args)
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
@@ -2,10 +2,12 @@ module DiscourseApi
|
|
2
2
|
module API
|
3
3
|
module Categories
|
4
4
|
# :color and :text_color are RGB hexadecimal strings
|
5
|
-
|
5
|
+
# :permissions is a hash with the group name and permission_type which is
|
6
|
+
# an integer 1 = Full 2 = Create Post 3 = Read Only
|
7
|
+
def create_category(args={})
|
6
8
|
args = API.params(args)
|
7
9
|
.required(:name, :color, :text_color)
|
8
|
-
.optional(:description)
|
10
|
+
.optional(:description, :permissions)
|
9
11
|
.default(parent_category_id: nil)
|
10
12
|
response = post("/categories", args)
|
11
13
|
response['category']
|
@@ -16,8 +18,16 @@ module DiscourseApi
|
|
16
18
|
response[:body]['category_list']['categories']
|
17
19
|
end
|
18
20
|
|
19
|
-
def category_latest_topics(
|
20
|
-
|
21
|
+
def category_latest_topics(args={})
|
22
|
+
params = API.params(args)
|
23
|
+
.required(:category_slug)
|
24
|
+
.optional(:page).to_h
|
25
|
+
url = "/c/#{params[:category_slug]}/l/latest.json"
|
26
|
+
if params.include?(:page)
|
27
|
+
puts params[:page]
|
28
|
+
url = "#{url}?page=#{params[:page]}"
|
29
|
+
end
|
30
|
+
response = get(url)
|
21
31
|
response[:body]['topic_list']['topics']
|
22
32
|
end
|
23
33
|
|
@@ -4,7 +4,7 @@ module DiscourseApi
|
|
4
4
|
# :category OPTIONAL name of category, not ID
|
5
5
|
# :skip_validations OPTIONAL boolean
|
6
6
|
# :auto_track OPTIONAL boolean
|
7
|
-
def create_topic(args)
|
7
|
+
def create_topic(args={})
|
8
8
|
args = API.params(args)
|
9
9
|
.required(:title, :raw)
|
10
10
|
.optional(:skip_validations, :category, :auto_track)
|
@@ -17,11 +17,12 @@ module DiscourseApi
|
|
17
17
|
|
18
18
|
def update_avatar(args)
|
19
19
|
args = API.params(args)
|
20
|
-
.required(:username
|
21
|
-
.
|
20
|
+
.required(:username)
|
21
|
+
.optional(:file, :url)
|
22
|
+
.default(type: 'avatar', synchronous: true)
|
22
23
|
.to_h
|
23
|
-
upload_response = post("/
|
24
|
-
put("/users/#{args[:username]}/preferences/avatar/pick", { upload_id: upload_response['
|
24
|
+
upload_response = post("/uploads", args)
|
25
|
+
put("/users/#{args[:username]}/preferences/avatar/pick", { upload_id: upload_response['id'] })
|
25
26
|
end
|
26
27
|
|
27
28
|
def update_email(username, email)
|
@@ -5,7 +5,8 @@ describe DiscourseApi::API::Categories do
|
|
5
5
|
|
6
6
|
describe "#categories" do
|
7
7
|
before do
|
8
|
-
stub_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user")
|
8
|
+
stub_get("http://localhost:3000/categories.json?api_key=test_d7fd0429940&api_username=test_user")
|
9
|
+
.to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
|
9
10
|
end
|
10
11
|
|
11
12
|
it "requests the correct resource" do
|
@@ -28,11 +29,12 @@ describe DiscourseApi::API::Categories do
|
|
28
29
|
|
29
30
|
describe '#category_latest_topics' do
|
30
31
|
before do
|
31
|
-
stub_get("http://localhost:3000/
|
32
|
+
stub_get("http://localhost:3000/c/category-slug/l/latest.json?api_key=test_d7fd0429940&api_username=test_user")
|
33
|
+
.to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
|
32
34
|
end
|
33
35
|
|
34
36
|
it "returns the latest topics in a category" do
|
35
|
-
latest_topics = subject.category_latest_topics('category-slug')
|
37
|
+
latest_topics = subject.category_latest_topics(category_slug: 'category-slug')
|
36
38
|
expect(latest_topics).to be_an Array
|
37
39
|
end
|
38
40
|
end
|
@@ -66,4 +68,20 @@ describe DiscourseApi::API::Categories do
|
|
66
68
|
expect(topics).to be_an Array
|
67
69
|
end
|
68
70
|
end
|
71
|
+
|
72
|
+
describe '#category_new_category' do
|
73
|
+
before do
|
74
|
+
stub_post("http://localhost:3000/categories?api_key=test_d7fd0429940&api_username=test_user")
|
75
|
+
subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
|
76
|
+
description: "This is a description",
|
77
|
+
permissions: {"group_1" => 1, "admins" => 1})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "makes a create category request" do
|
81
|
+
expect(a_post("http://localhost:3000/categories?api_key=test_d7fd0429940&api_username=test_user").with(body:
|
82
|
+
"color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF")
|
83
|
+
).to have_been_made
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
69
87
|
end
|
@@ -26,13 +26,13 @@ describe DiscourseApi::API::Users do
|
|
26
26
|
|
27
27
|
describe "#update_avatar" do
|
28
28
|
before do
|
29
|
-
stub_post("http://localhost:3000/
|
29
|
+
stub_post("http://localhost:3000/uploads?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("upload_avatar.json"), headers: { content_type: "application/json" })
|
30
30
|
stub_put("http://localhost:3000/users/test_user/preferences/avatar/pick?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("user_update_avatar_success.json"), headers: { content_type: "application/json" })
|
31
31
|
end
|
32
32
|
|
33
33
|
it "uploads an image" do
|
34
34
|
sam = "https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
35
|
-
args = { username: 'test_user',
|
35
|
+
args = { username: 'test_user', url: sam }
|
36
36
|
response = subject.update_avatar(args)
|
37
37
|
expect(response[:body]['success']).to eq('OK')
|
38
38
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"id": 11,
|
3
|
+
"user_id": 1,
|
4
|
+
"original_filename": "avatar.jpg",
|
5
|
+
"filesize": 86900,
|
6
|
+
"width": 360,
|
7
|
+
"height": 360,
|
8
|
+
"url": "/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg",
|
9
|
+
"created_at": "2015-06-21T12:35:45.182Z",
|
10
|
+
"updated_at": "2015-06-21T12:35:45.195Z",
|
11
|
+
"sha1": "417e624d2453925e6c68748b9aa67637c284b5aa",
|
12
|
+
"origin": null,
|
13
|
+
"retain_hours": null
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-11-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- examples/example.rb
|
193
193
|
- examples/groups.rb
|
194
194
|
- examples/invite_users.rb
|
195
|
+
- examples/search.rb
|
195
196
|
- examples/sso.rb
|
196
197
|
- examples/topic_lists.rb
|
197
198
|
- examples/update_user.rb
|
@@ -255,6 +256,7 @@ files:
|
|
255
256
|
- spec/fixtures/topic_invite_user.json
|
256
257
|
- spec/fixtures/topics_created_by.json
|
257
258
|
- spec/fixtures/update_trust_level.json
|
259
|
+
- spec/fixtures/upload_avatar.json
|
258
260
|
- spec/fixtures/user.json
|
259
261
|
- spec/fixtures/user_activate_success.json
|
260
262
|
- spec/fixtures/user_badges.json
|
@@ -286,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
288
|
version: '0'
|
287
289
|
requirements: []
|
288
290
|
rubyforge_project:
|
289
|
-
rubygems_version: 2.
|
291
|
+
rubygems_version: 2.5.0
|
290
292
|
signing_key:
|
291
293
|
specification_version: 4
|
292
294
|
summary: Allows access to the Discourse API
|
@@ -329,6 +331,7 @@ test_files:
|
|
329
331
|
- spec/fixtures/topic_invite_user.json
|
330
332
|
- spec/fixtures/topics_created_by.json
|
331
333
|
- spec/fixtures/update_trust_level.json
|
334
|
+
- spec/fixtures/upload_avatar.json
|
332
335
|
- spec/fixtures/user.json
|
333
336
|
- spec/fixtures/user_activate_success.json
|
334
337
|
- spec/fixtures/user_badges.json
|