discourse_api 0.34.0 → 0.35.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +10 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -0
- data/Guardfile +2 -1
- data/Rakefile +7 -2
- data/discourse_api.gemspec +23 -22
- data/examples/backups.rb +1 -0
- data/examples/badges.rb +1 -0
- data/examples/category.rb +1 -0
- data/examples/change_topic_status.rb +3 -3
- data/examples/create_private_message.rb +1 -0
- data/examples/create_topic.rb +1 -0
- data/examples/create_update_category.rb +1 -1
- data/examples/create_user.rb +1 -0
- data/examples/dashboard.rb +3 -2
- data/examples/disposable_invite_tokens.rb +1 -0
- data/examples/example.rb +1 -0
- data/examples/group_set_user_notification_level.rb +1 -1
- data/examples/groups.rb +1 -0
- data/examples/invite_users.rb +1 -0
- data/examples/post_action.rb +1 -0
- data/examples/search.rb +1 -0
- data/examples/sent_private_messages.rb +1 -0
- data/examples/sso.rb +1 -0
- data/examples/topic_lists.rb +1 -0
- data/examples/update_user.rb +1 -0
- data/examples/upload_file.rb +1 -0
- data/lib/discourse_api.rb +1 -0
- data/lib/discourse_api/api/api_key.rb +3 -2
- data/lib/discourse_api/api/backups.rb +1 -0
- data/lib/discourse_api/api/badges.rb +5 -4
- data/lib/discourse_api/api/categories.rb +16 -15
- data/lib/discourse_api/api/dashboard.rb +7 -6
- data/lib/discourse_api/api/email.rb +1 -0
- data/lib/discourse_api/api/groups.rb +11 -10
- data/lib/discourse_api/api/invite.rb +4 -3
- data/lib/discourse_api/api/notifications.rb +2 -1
- data/lib/discourse_api/api/params.rb +3 -2
- data/lib/discourse_api/api/posts.rb +7 -6
- data/lib/discourse_api/api/private_messages.rb +4 -3
- data/lib/discourse_api/api/search.rb +2 -1
- data/lib/discourse_api/api/site_settings.rb +3 -2
- data/lib/discourse_api/api/sso.rb +3 -2
- data/lib/discourse_api/api/tags.rb +1 -0
- data/lib/discourse_api/api/topics.rb +17 -16
- data/lib/discourse_api/api/uploads.rb +4 -3
- data/lib/discourse_api/api/user_actions.rb +3 -2
- data/lib/discourse_api/api/users.rb +23 -20
- data/lib/discourse_api/client.rb +8 -7
- data/lib/discourse_api/error.rb +2 -1
- data/lib/discourse_api/single_sign_on.rb +1 -0
- data/lib/discourse_api/version.rb +2 -1
- data/spec/discourse_api/api/users_spec.rb +13 -13
- metadata +38 -25
- data/routes.txt +0 -203
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c528dfd53262df7af997ea5f9da09b4ea423e9425dc98d18c944af293f15ef94
|
4
|
+
data.tar.gz: e0df934c4e39a5eed50f080bf6d02be0aec29aa3b21ddd21875782ad456867eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf4d4859413e6c923bd0c0162b13997133536e6d9d176ba8220364ed7cdbb58962e3a4ce27940bc5c5d96bd2e39fe601accc27fe813eabd1aabb209913351fe4
|
7
|
+
data.tar.gz: 46117b013a50ccc7fc3e6bd7f1fa4f117b1166cb846e34f76821db62ef66eeb4d7a87b21cbc6273494bcece664c1b6520639c016b430b0a47d970556df8b9ea9
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.35.0] - 2019-04-02
|
6
|
+
### Added
|
7
|
+
- Added `custom_fields` param to create/update category
|
8
|
+
- Added `frozen_string_literal: true` to all the files
|
9
|
+
- Added rubocop and all the changes that went along with it
|
10
|
+
### Fixed
|
11
|
+
- Allow `api_username` to be changed for an initialized client
|
12
|
+
- Update many of the `/users` routes to use the `/u` route
|
13
|
+
### Changed
|
14
|
+
- Changed `update_trust_level` to follow consistent method param syntax where
|
15
|
+
you specify the id first followed by params
|
16
|
+
|
5
17
|
## [0.34.0] - 2019-04-02
|
6
18
|
### Added
|
7
19
|
- Header based authentication
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'bundler/gem_tasks'
|
2
3
|
|
3
4
|
require 'rspec/core/rake_task'
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
RuboCop::RakeTask.new(:rubocop)
|
9
|
+
|
6
10
|
task test: :spec
|
7
|
-
task
|
11
|
+
task lint: :rubocop
|
12
|
+
task default: [:spec, :lint]
|
data/discourse_api.gemspec
CHANGED
@@ -1,35 +1,36 @@
|
|
1
|
-
#
|
2
|
-
lib = File.expand_path('
|
1
|
+
# frozen_string_literal: true
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'discourse_api/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'discourse_api'
|
8
8
|
spec.version = DiscourseApi::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Sam Saffron', 'John Paul Ashenfelter', 'Michael Herold', 'Blake Erickson']
|
10
|
+
spec.email = ['sam.saffron@gmail.com', 'john@ashenfelter.com', 'michael.j.herold@gmail.com', 'o.blakeerickson@gmail.com']
|
11
|
+
spec.description = 'Discourse API'
|
12
|
+
spec.summary = 'Allows access to the Discourse API'
|
13
|
+
spec.homepage = 'http://github.com/discourse/discourse_api'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'faraday', '~> 0.9'
|
22
|
+
spec.add_dependency 'faraday_middleware', '~> 0.10'
|
23
|
+
spec.add_dependency 'rack', '>= 1.6'
|
24
24
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
26
|
+
spec.add_development_dependency 'guard', '~> 2.14'
|
27
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
28
|
+
spec.add_development_dependency 'rake', '~> 11.1'
|
29
|
+
spec.add_development_dependency 'rb-inotify', '~> 0.9'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.67.2'
|
32
|
+
spec.add_development_dependency 'simplecov', '~> 0.11'
|
33
|
+
spec.add_development_dependency 'webmock', '~> 2.0'
|
33
34
|
|
34
35
|
spec.required_ruby_version = '>= 2.2.3'
|
35
36
|
end
|
data/examples/backups.rb
CHANGED
data/examples/badges.rb
CHANGED
data/examples/category.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
3
|
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
4
|
|
@@ -17,7 +18,6 @@ response = client.create_topic(
|
|
17
18
|
topic_id = response['topic_id']
|
18
19
|
topic_slug = response['topic_slug']
|
19
20
|
|
20
|
-
|
21
21
|
##
|
22
22
|
# available options (guessing from reading discourse source)
|
23
23
|
# status can be: ['autoclose', 'closed', 'archived', 'disabled', 'visible']
|
@@ -25,9 +25,9 @@ topic_slug = response['topic_slug']
|
|
25
25
|
##
|
26
26
|
|
27
27
|
# lock topic (note: api_username determines user that is performing action)
|
28
|
-
params = {status: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME"}
|
28
|
+
params = { status: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME" }
|
29
29
|
client.change_topic_status(topic_slug, topic_id, params)
|
30
30
|
|
31
31
|
# unlock topic (note: api_username determines user that is performing action)
|
32
|
-
params = {status: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME"}
|
32
|
+
params = { status: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME" }
|
33
33
|
client.change_topic_status(topic_slug, topic_id, params)
|
data/examples/create_topic.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
3
|
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
4
|
|
@@ -18,7 +19,6 @@ client.api_username = "system"
|
|
18
19
|
# :email_in_allow_strangers, :logo_url, :background_url, :allow_badges, :topic_template
|
19
20
|
###
|
20
21
|
|
21
|
-
|
22
22
|
# Create category
|
23
23
|
new_category = client.create_category(
|
24
24
|
name: "Test Category",
|
data/examples/create_user.rb
CHANGED
data/examples/dashboard.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
3
|
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
4
|
|
@@ -5,9 +6,9 @@ client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
6
|
client.api_key = "YOUR_API_KEY"
|
6
7
|
client.api_username = "YOUR_USERNAME"
|
7
8
|
|
8
|
-
# get all dashboard status as json
|
9
|
+
# get all dashboard status as json
|
9
10
|
puts client.get_dashboard_stats
|
10
11
|
|
11
|
-
# get hash of some dashboard total value
|
12
|
+
# get hash of some dashboard total value
|
12
13
|
puts client.get_dashboard_stats_totals
|
13
14
|
# sample output: {"users"=>9, "topics"=>230, "posts"=>441}
|
data/examples/example.rb
CHANGED
data/examples/groups.rb
CHANGED
data/examples/invite_users.rb
CHANGED
data/examples/post_action.rb
CHANGED
data/examples/search.rb
CHANGED
data/examples/sso.rb
CHANGED
data/examples/topic_lists.rb
CHANGED
data/examples/update_user.rb
CHANGED
data/examples/upload_file.rb
CHANGED
data/lib/discourse_api.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module ApiKey
|
@@ -19,11 +20,11 @@ module DiscourseApi
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def revoke_api_key(id)
|
22
|
-
response = delete("/admin/api/key",
|
23
|
+
response = delete("/admin/api/key", id: id)
|
23
24
|
end
|
24
25
|
|
25
26
|
def regenerate_api_key(id)
|
26
|
-
response = put("/admin/api/key",
|
27
|
+
response = put("/admin/api/key", id: id)
|
27
28
|
response.body
|
28
29
|
end
|
29
30
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Badges
|
@@ -11,14 +12,14 @@ module DiscourseApi
|
|
11
12
|
response.body['badges']
|
12
13
|
end
|
13
14
|
|
14
|
-
def grant_user_badge(params={})
|
15
|
+
def grant_user_badge(params = {})
|
15
16
|
post("/user_badges", params)
|
16
17
|
end
|
17
18
|
|
18
|
-
def create_badge(params={})
|
19
|
+
def create_badge(params = {})
|
19
20
|
args = API.params(params)
|
20
|
-
|
21
|
-
|
21
|
+
.required(:name, :badge_type_id)
|
22
|
+
.optional(:description, :allow_title, :multiple_grant, :icon, :listable,
|
22
23
|
:target_posts, :query, :enabled, :auto_revoke, :badge_grouping_id,
|
23
24
|
:trigger, :show_posts, :image, :long_description)
|
24
25
|
post("/admin/badges.json", args)
|
@@ -1,38 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Categories
|
4
5
|
# :color and :text_color are RGB hexadecimal strings
|
5
6
|
# :permissions is a hash with the group name and permission_type which is
|
6
7
|
# an integer 1 = Full 2 = Create Post 3 = Read Only
|
7
|
-
def create_category(args={})
|
8
|
+
def create_category(args = {})
|
8
9
|
args = API.params(args)
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
.required(:name, :color, :text_color)
|
11
|
+
.optional(:description, :permissions, :custom_fields)
|
12
|
+
.default(parent_category_id: nil)
|
12
13
|
response = post("/categories", args)
|
13
14
|
response['category']
|
14
15
|
end
|
15
16
|
|
16
|
-
def update_category(args={})
|
17
|
+
def update_category(args = {})
|
17
18
|
category_id = args[:id]
|
18
19
|
args = API.params(args)
|
19
|
-
|
20
|
-
|
21
|
-
:email_in_allow_strangers, :logo_url, :background_url, :allow_badges, :topic_template)
|
22
|
-
|
20
|
+
.required(:id, :name, :color, :text_color)
|
21
|
+
.optional(:slug, :permissions, :auto_close_hours, :auto_close_based_on_last_post, :position, :email_in,
|
22
|
+
:email_in_allow_strangers, :logo_url, :background_url, :allow_badges, :topic_template, :custom_fields)
|
23
|
+
.default(parent_category_id: nil)
|
23
24
|
response = put("/categories/#{category_id}", args)
|
24
25
|
response['body']['category'] if response['body']
|
25
26
|
end
|
26
27
|
|
27
|
-
def categories(params={})
|
28
|
+
def categories(params = {})
|
28
29
|
response = get('/categories.json', params)
|
29
30
|
response[:body]['category_list']['categories']
|
30
31
|
end
|
31
32
|
|
32
|
-
def category_latest_topics(args={})
|
33
|
+
def category_latest_topics(args = {})
|
33
34
|
params = API.params(args)
|
34
|
-
|
35
|
-
|
35
|
+
.required(:category_slug)
|
36
|
+
.optional(:page).to_h
|
36
37
|
url = "/c/#{params[:category_slug]}/l/latest.json"
|
37
38
|
if params.include?(:page)
|
38
39
|
url = "#{url}?page=#{params[:page]}"
|
@@ -64,10 +65,10 @@ module DiscourseApi
|
|
64
65
|
response[:body]['category']
|
65
66
|
end
|
66
67
|
|
67
|
-
def category_set_user_notification(args={})
|
68
|
+
def category_set_user_notification(args = {})
|
68
69
|
category_id = args[:id]
|
69
70
|
args = API.params(args)
|
70
|
-
|
71
|
+
.required(:notification_level)
|
71
72
|
post("/category/#{category_id}/notifications", args)
|
72
73
|
end
|
73
74
|
end
|
@@ -1,22 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DiscourseApi
|
2
3
|
module API
|
3
4
|
module Dashboard
|
4
5
|
def get_dashboard_stats
|
5
6
|
response = get("admin/dashboard.json")
|
6
7
|
response[:body]
|
7
|
-
end
|
8
|
-
|
8
|
+
end
|
9
|
+
|
9
10
|
def get_dashboard_stats_totals
|
10
11
|
stats = get_dashboard_stats
|
11
|
-
global_reports = stats['global_reports']
|
12
|
+
global_reports = stats['global_reports']
|
12
13
|
users = global_reports[1]
|
13
14
|
topics = global_reports[3]
|
14
15
|
posts = global_reports[4]
|
15
|
-
|
16
|
+
|
16
17
|
totals = {
|
17
|
-
'users'
|
18
|
+
'users' => users['total'],
|
18
19
|
'topics' => topics['total'],
|
19
|
-
'posts'
|
20
|
+
'posts' => posts['total']
|
20
21
|
}
|
21
22
|
end
|
22
23
|
end
|