discourse_api 0.2.4 → 0.2.5
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/.gitignore +1 -0
- data/discourse_api.gemspec +3 -0
- data/examples/update_user.rb +3 -1
- data/lib/discourse_api/api/categories.rb +9 -0
- data/lib/discourse_api/api/groups.rb +14 -0
- data/lib/discourse_api/api/posts.rb +9 -0
- data/lib/discourse_api/api/topics.rb +10 -2
- data/lib/discourse_api/api/users.rb +4 -0
- data/lib/discourse_api/client.rb +18 -2
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/topics_spec.rb +2 -1
- data/spec/discourse_api/api/users_spec.rb +2 -1
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 831e6a472cbcaff97004039ba2eea26f3a21fd75
|
4
|
+
data.tar.gz: afcaa7863e713f022e40bc5b4677d69334870800
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60dfe37fc068b570befdd131e3ccc58f458a362e565e17b6d12371b7340abda526c3dd63c52a58d69a742ad8c10e566a5402c6945e0cf39d3013e700ba93c3d7
|
7
|
+
data.tar.gz: 4df138687be5cb12299ac0f66bce1b7bce60d51f086894cbc0411ee756c1d7ebea76b94bbe002079be1ed8037cda2f9ba0f5ae3a308c0524a269843f08c6fae2
|
data/.gitignore
CHANGED
data/discourse_api.gemspec
CHANGED
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "faraday", "0.9.0"
|
22
22
|
spec.add_dependency "faraday_middleware", "~> 0.9"
|
23
|
+
spec.add_dependency "rack", "~> 1.5"
|
24
|
+
spec.add_dependency "dotenv", "~> 1.0"
|
25
|
+
|
23
26
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
27
|
spec.add_development_dependency "rake", "10.3.2"
|
25
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
data/examples/update_user.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
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("localhost"
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
5
5
|
client.api_key = "YOUR_API_KEY"
|
6
6
|
client.api_username = "YOUR_USERNAME"
|
7
7
|
|
@@ -13,3 +13,5 @@ puts client.update_user("batman", name: "Bruce Wayne")
|
|
13
13
|
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
|
+
# log out everywhere and refresh browser of user whose id is "2"
|
17
|
+
puts client.log_out_and_refresh_browser(2)
|
@@ -1,6 +1,15 @@
|
|
1
1
|
module DiscourseApi
|
2
2
|
module API
|
3
3
|
module Categories
|
4
|
+
# :color and :text_color are RGB hexadecimal strings
|
5
|
+
def create_category(name:, color:, text_color:, parent_category_id: nil)
|
6
|
+
post("/categories",
|
7
|
+
name: name,
|
8
|
+
color: color,
|
9
|
+
text_color: text_color,
|
10
|
+
parent_category_id: parent_category_id)
|
11
|
+
end
|
12
|
+
|
4
13
|
def categories(*args)
|
5
14
|
response = get('/categories.json', args)
|
6
15
|
response[:body]['category_list']['categories']
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DiscourseApi
|
2
|
+
module API
|
3
|
+
module Groups
|
4
|
+
def create_group(name:, visible: false)
|
5
|
+
post("/admin/groups", group: {name: name, visible: visible.to_s})
|
6
|
+
end
|
7
|
+
|
8
|
+
def groups
|
9
|
+
response = get("/admin/groups")
|
10
|
+
response.body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,8 +1,16 @@
|
|
1
1
|
module DiscourseApi
|
2
2
|
module API
|
3
3
|
module Topics
|
4
|
-
|
5
|
-
|
4
|
+
# :category OPTIONAL name of category, not ID
|
5
|
+
# :skip_validations OPTIONAL boolean
|
6
|
+
# :auto_track OPTIONAL boolean
|
7
|
+
def create_topic(title:, raw:, category: nil, skip_validations: nil, auto_track: nil)
|
8
|
+
post("/posts",
|
9
|
+
title: title,
|
10
|
+
raw: raw,
|
11
|
+
category: category,
|
12
|
+
skip_validations: skip_validations,
|
13
|
+
auto_track: auto_track)
|
6
14
|
end
|
7
15
|
|
8
16
|
def latest_topics(*args)
|
data/lib/discourse_api/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'dotenv'
|
1
2
|
require 'faraday'
|
2
3
|
require 'faraday_middleware'
|
3
4
|
require 'json'
|
@@ -6,7 +7,9 @@ require 'discourse_api/api/categories'
|
|
6
7
|
require 'discourse_api/api/search'
|
7
8
|
require 'discourse_api/api/sso'
|
8
9
|
require 'discourse_api/api/topics'
|
10
|
+
require 'discourse_api/api/posts'
|
9
11
|
require 'discourse_api/api/users'
|
12
|
+
require 'discourse_api/api/groups'
|
10
13
|
require 'discourse_api/api/invite'
|
11
14
|
require 'discourse_api/api/private_messages'
|
12
15
|
require 'discourse_api/api/notifications'
|
@@ -20,12 +23,17 @@ module DiscourseApi
|
|
20
23
|
include DiscourseApi::API::Search
|
21
24
|
include DiscourseApi::API::SSO
|
22
25
|
include DiscourseApi::API::Topics
|
26
|
+
include DiscourseApi::API::Posts
|
23
27
|
include DiscourseApi::API::Users
|
28
|
+
include DiscourseApi::API::Groups
|
24
29
|
include DiscourseApi::API::Invite
|
25
30
|
include DiscourseApi::API::PrivateMessages
|
26
31
|
include DiscourseApi::API::Notifications
|
27
32
|
|
28
|
-
def initialize(host
|
33
|
+
def initialize(host = ENV["DISCOURSE_URL"],
|
34
|
+
api_key = ENV["DISCOURSE_API_KEY"],
|
35
|
+
api_username = ENV["DISCOURSE_USERNAME"])
|
36
|
+
raise ArgumentError, 'host needs to be defined' if host.nil? || host.empty?
|
29
37
|
@host = host
|
30
38
|
@api_key = api_key
|
31
39
|
@api_username = api_username
|
@@ -50,7 +58,13 @@ module DiscourseApi
|
|
50
58
|
end
|
51
59
|
|
52
60
|
def post(path, params={})
|
53
|
-
request(:post, path, params)
|
61
|
+
response = request(:post, path, params)
|
62
|
+
case response.status
|
63
|
+
when 200
|
64
|
+
response.body
|
65
|
+
else
|
66
|
+
raise ApiError, response.body
|
67
|
+
end
|
54
68
|
end
|
55
69
|
|
56
70
|
def put(path, params={})
|
@@ -86,4 +100,6 @@ module DiscourseApi
|
|
86
100
|
raise DiscourseApi::Error
|
87
101
|
end
|
88
102
|
end
|
103
|
+
|
104
|
+
class ApiError < Exception; end
|
89
105
|
end
|
@@ -15,7 +15,8 @@ describe DiscourseApi::API::Topics do
|
|
15
15
|
|
16
16
|
it "returns success" do
|
17
17
|
response = subject.invite_user_to_topic(email: "fake_user@example.com", topic_id: 12)
|
18
|
-
expect(response
|
18
|
+
expect(response).to be_a Hash
|
19
|
+
expect(response['success']).to be_truthy
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -92,7 +92,8 @@ describe DiscourseApi::API::Users do
|
|
92
92
|
|
93
93
|
it "returns success" do
|
94
94
|
response = subject.create_user :name => "Test User", :email => "test2@example.com", :password => "P@ssword", :username => "test2"
|
95
|
-
expect(response
|
95
|
+
expect(response).to be_a Hash
|
96
|
+
expect(response['success']).to be_truthy
|
96
97
|
end
|
97
98
|
end
|
98
99
|
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.2.
|
4
|
+
version: 0.2.5
|
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-
|
13
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -40,6 +40,34 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0.9'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rack
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.5'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.5'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: dotenv
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.0'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '1.0'
|
43
71
|
- !ruby/object:Gem::Dependency
|
44
72
|
name: bundler
|
45
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,8 +207,10 @@ files:
|
|
179
207
|
- examples/update_user.rb
|
180
208
|
- lib/discourse_api.rb
|
181
209
|
- lib/discourse_api/api/categories.rb
|
210
|
+
- lib/discourse_api/api/groups.rb
|
182
211
|
- lib/discourse_api/api/invite.rb
|
183
212
|
- lib/discourse_api/api/notifications.rb
|
213
|
+
- lib/discourse_api/api/posts.rb
|
184
214
|
- lib/discourse_api/api/private_messages.rb
|
185
215
|
- lib/discourse_api/api/search.rb
|
186
216
|
- lib/discourse_api/api/sso.rb
|