discourse_api 0.2.5 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/groups.rb +14 -0
- data/examples/update_user.rb +1 -1
- data/lib/discourse_api/api/groups.rb +10 -2
- data/lib/discourse_api/api/users.rb +7 -2
- data/lib/discourse_api/client.rb +4 -0
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/groups_spec.rb +46 -0
- data/spec/fixtures/groups.json +18 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f21e1da09f27385b726a7a6da00b6fd67a73bdb
|
4
|
+
data.tar.gz: b637a2ef55860b8024718f0b74453b1a1ff71f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 425557b85eb7f8b55607297b10b1ff2429004ba0b3de9956c983b273661a9a16f24a17574d2157b0abe2ba162f131a5288233d062584b213f1d86969bdc14c77
|
7
|
+
data.tar.gz: a0bec4403e81185fe7a990c0bf585e30f02381283bd567bda29ad9b79b26bb633bce7ffd5a79e2e7d935e82137e6e05aaf9b790a3d9d52548aeed342e564faac
|
data/examples/groups.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
|
+
|
4
|
+
Dotenv.load
|
5
|
+
client = DiscourseApi::Client.new
|
6
|
+
|
7
|
+
response = client.create_group(name: "engineering_team")
|
8
|
+
group_id = response["basic_group"]["id"]
|
9
|
+
|
10
|
+
client.group_add(group_id, "sam")
|
11
|
+
client.group_add(group_id, "jeff")
|
12
|
+
client.group_add(group_id, "neil")
|
13
|
+
|
14
|
+
client.group_remove(group_id, "neil")
|
data/examples/update_user.rb
CHANGED
@@ -14,4 +14,4 @@ puts client.update_email("batman", "batman@gotham.com")
|
|
14
14
|
# update avatar of user whose username is "batman"
|
15
15
|
puts client.update_avatar("batman", "http://meta-discourse.r.worldssl.net/uploads/default/2497/724a6ef2e79d2bc7.png")
|
16
16
|
# log out everywhere and refresh browser of user whose id is "2"
|
17
|
-
puts client.
|
17
|
+
puts client.log_out(2)
|
@@ -1,14 +1,22 @@
|
|
1
1
|
module DiscourseApi
|
2
2
|
module API
|
3
3
|
module Groups
|
4
|
-
def create_group(name:, visible:
|
4
|
+
def create_group(name:, visible: true)
|
5
5
|
post("/admin/groups", group: {name: name, visible: visible.to_s})
|
6
6
|
end
|
7
7
|
|
8
8
|
def groups
|
9
|
-
response = get("/admin/groups")
|
9
|
+
response = get("/admin/groups.json")
|
10
10
|
response.body
|
11
11
|
end
|
12
|
+
|
13
|
+
def group_add(group_id, *usernames)
|
14
|
+
patch("/admin/groups/#{group_id}", changes: {add: usernames})
|
15
|
+
end
|
16
|
+
|
17
|
+
def group_remove(group_id, *usernames)
|
18
|
+
patch("/admin/groups/#{group_id}", changes: {delete: usernames})
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|
@@ -29,6 +29,7 @@ module DiscourseApi
|
|
29
29
|
# Create a user
|
30
30
|
def create_user(args={})
|
31
31
|
# First retrieve the honeypot values
|
32
|
+
# TODO, none of this should be needed via API
|
32
33
|
response = get("/users/hp.json")
|
33
34
|
args[:password_confirmation] = response[:body]['value']
|
34
35
|
args[:challenge] = response[:body]['challenge'].reverse
|
@@ -37,8 +38,12 @@ module DiscourseApi
|
|
37
38
|
post("/users", args)
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
-
post("/admin/users/#{id}/
|
41
|
+
def log_out(id)
|
42
|
+
post("/admin/users/#{id}/log_out")
|
43
|
+
end
|
44
|
+
|
45
|
+
def invite_admin(args={})
|
46
|
+
post("/admin/users/invite_admin", args)
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
data/lib/discourse_api/client.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Groups do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
+
|
6
|
+
describe "#groups" do
|
7
|
+
before do
|
8
|
+
stub_get("http://localhost:3000/admin/groups.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("groups.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "requests the correct resource" do
|
12
|
+
subject.groups
|
13
|
+
expect(a_get("http://localhost:3000/admin/groups.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the requested groups" do
|
17
|
+
groups = subject.groups
|
18
|
+
expect(groups).to be_an Array
|
19
|
+
groups.each { |g| expect(g).to be_a Hash }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "create new groups" do
|
23
|
+
stub_post("http://localhost:3000/admin/groups?api_key=test_d7fd0429940&api_username=test_user")
|
24
|
+
subject.create_group(name: "test_group")
|
25
|
+
expect(a_post("http://localhost:3000/admin/groups?api_key=test_d7fd0429940&api_username=test_user").
|
26
|
+
with(body: {group: {name: "test_group", visible: "true"}})
|
27
|
+
).to have_been_made
|
28
|
+
end
|
29
|
+
|
30
|
+
it "adds members" do
|
31
|
+
stub_request(:patch, "http://localhost:3000/admin/groups/123?api_key=test_d7fd0429940&api_username=test_user")
|
32
|
+
subject.group_add(123, "sam")
|
33
|
+
expect(a_request(:patch, "http://localhost:3000/admin/groups/123?api_key=test_d7fd0429940&api_username=test_user").
|
34
|
+
with(body: {changes: {add: [ "sam" ]}})
|
35
|
+
).to have_been_made
|
36
|
+
end
|
37
|
+
|
38
|
+
it "removes members" do
|
39
|
+
stub_request(:patch, "http://localhost:3000/admin/groups/123?api_key=test_d7fd0429940&api_username=test_user")
|
40
|
+
subject.group_remove(123, "sam")
|
41
|
+
expect(a_request(:patch, "http://localhost:3000/admin/groups/123?api_key=test_d7fd0429940&api_username=test_user").
|
42
|
+
with(body: {changes: {delete: [ "sam" ]}})
|
43
|
+
).to have_been_made
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": 101,
|
4
|
+
"name": "group_1",
|
5
|
+
"user_count": 17,
|
6
|
+
"automatic": false,
|
7
|
+
"alias_level": 0,
|
8
|
+
"visible": true
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"id": 102,
|
12
|
+
"name": "group_2",
|
13
|
+
"user_count": 4,
|
14
|
+
"automatic": false,
|
15
|
+
"alias_level": 0,
|
16
|
+
"visible": true
|
17
|
+
}
|
18
|
+
]
|
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.2.
|
4
|
+
version: 0.2.7
|
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: 2014-11-
|
13
|
+
date: 2014-11-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- examples/create_topic.rb
|
202
202
|
- examples/disposable_invite_tokens.rb
|
203
203
|
- examples/example.rb
|
204
|
+
- examples/groups.rb
|
204
205
|
- examples/invite_users.rb
|
205
206
|
- examples/sso.rb
|
206
207
|
- examples/topic_lists.rb
|
@@ -222,6 +223,7 @@ files:
|
|
222
223
|
- lib/single_sign_on.rb
|
223
224
|
- routes.txt
|
224
225
|
- spec/discourse_api/api/categories_spec.rb
|
226
|
+
- spec/discourse_api/api/groups_spec.rb
|
225
227
|
- spec/discourse_api/api/notifications_spec.rb
|
226
228
|
- spec/discourse_api/api/private_messages_spec.rb
|
227
229
|
- spec/discourse_api/api/search_spec.rb
|
@@ -230,6 +232,7 @@ files:
|
|
230
232
|
- spec/discourse_api/client_spec.rb
|
231
233
|
- spec/fixtures/categories.json
|
232
234
|
- spec/fixtures/category_latest_topics.json
|
235
|
+
- spec/fixtures/groups.json
|
233
236
|
- spec/fixtures/hot.json
|
234
237
|
- spec/fixtures/latest.json
|
235
238
|
- spec/fixtures/new.json
|
@@ -270,6 +273,7 @@ specification_version: 4
|
|
270
273
|
summary: Allows access to the Discourse API
|
271
274
|
test_files:
|
272
275
|
- spec/discourse_api/api/categories_spec.rb
|
276
|
+
- spec/discourse_api/api/groups_spec.rb
|
273
277
|
- spec/discourse_api/api/notifications_spec.rb
|
274
278
|
- spec/discourse_api/api/private_messages_spec.rb
|
275
279
|
- spec/discourse_api/api/search_spec.rb
|
@@ -278,6 +282,7 @@ test_files:
|
|
278
282
|
- spec/discourse_api/client_spec.rb
|
279
283
|
- spec/fixtures/categories.json
|
280
284
|
- spec/fixtures/category_latest_topics.json
|
285
|
+
- spec/fixtures/groups.json
|
281
286
|
- spec/fixtures/hot.json
|
282
287
|
- spec/fixtures/latest.json
|
283
288
|
- spec/fixtures/new.json
|