discourse_api 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/examples/badges.rb +28 -0
- data/lib/discourse_api/api/posts.rb +4 -0
- data/lib/discourse_api/client.rb +6 -0
- data/lib/discourse_api/error.rb +9 -0
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/posts_spec.rb +11 -0
- data/spec/discourse_api/api/users_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f179ec13fc9566ae7d24d6221d37daa6c25151
|
4
|
+
data.tar.gz: ea37ff2e519badc32e263b0b2e5a735f85f089c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc09d50774412963b6aa4801d4008565b3a925be812a97a226950b8562ebf1c6214651b5b95aab4c2110943994710728aa3f3ee194c34a1646343bd492aac7c0
|
7
|
+
data.tar.gz: 05921ec9da249ba553a0a83b6f9ae64bd83d6f17413fb109114d7cec892bb6303be7964b7398029b3a170f7a7adb852beddfda9cefe1614019569d2bbb5ad17b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
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.14.0] - 2016-10-30
|
6
|
+
### Added
|
7
|
+
- improved error responses by adding `NotFoundError`, `UnprocessableEntity`, and `TooManyRequests`
|
8
|
+
- added `delete_post` method
|
9
|
+
|
5
10
|
## [0.13.0] - 2016-10-09
|
6
11
|
### Added
|
7
12
|
- added `update_category`
|
data/examples/badges.rb
ADDED
@@ -0,0 +1,28 @@
|
|
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 badges
|
9
|
+
puts client.badges
|
10
|
+
|
11
|
+
# get badges for a user
|
12
|
+
puts client.user_badges("test-user")
|
13
|
+
|
14
|
+
# Grants a badge to a user.
|
15
|
+
puts client.grant_user_badge(badge_id: 9, username: "test-user", reason: "Really nice person")
|
16
|
+
|
17
|
+
# Creates a new badge
|
18
|
+
|
19
|
+
###
|
20
|
+
# Required params:
|
21
|
+
# :name, :badge_type_id (gold: 1, bronze: 3, silver: 2)
|
22
|
+
# Optional params:
|
23
|
+
# :description, :allow_title, :multiple_grant, :icon, :listable,
|
24
|
+
# :target_posts, :query, :enabled, :auto_revoke, :badge_grouping_id,
|
25
|
+
# :trigger, :show_posts, :image, :long_description
|
26
|
+
###
|
27
|
+
|
28
|
+
puts client.create_badge(name: "Shiny new badge", badge_type_id: 1)
|
@@ -28,6 +28,10 @@ module DiscourseApi
|
|
28
28
|
put("/posts/#{id}", post: {raw: raw})
|
29
29
|
end
|
30
30
|
|
31
|
+
def delete_post(id)
|
32
|
+
delete("/posts/#{id}.json")
|
33
|
+
end
|
34
|
+
|
31
35
|
def destroy_post_action(post_id, post_action_type_id)
|
32
36
|
delete("/post_actions/#{post_id}.json", post_action_type_id: post_action_type_id)
|
33
37
|
end
|
data/lib/discourse_api/client.rb
CHANGED
@@ -129,6 +129,12 @@ module DiscourseApi
|
|
129
129
|
case response.status
|
130
130
|
when 403
|
131
131
|
raise DiscourseApi::UnauthenticatedError.new(response.env[:body])
|
132
|
+
when 404, 410
|
133
|
+
raise DiscourseApi::NotFoundError.new(response.env[:body])
|
134
|
+
when 422
|
135
|
+
raise DiscourseApi::UnprocessableEntity.new(response.env[:body])
|
136
|
+
when 429
|
137
|
+
raise DiscourseApi::TooManyRequests.new(response.env[:body])
|
132
138
|
end
|
133
139
|
end
|
134
140
|
end
|
data/lib/discourse_api/error.rb
CHANGED
@@ -26,6 +26,17 @@ describe DiscourseApi::API::Posts do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
describe "#delete_post" do
|
30
|
+
before do
|
31
|
+
stub_delete("http://localhost:3000/posts/9999.json?api_key=test_d7fd0429940&api_username=test_user")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "deletes a post" do
|
35
|
+
client.delete_post(9999)
|
36
|
+
expect(a_delete("http://localhost:3000/posts/9999.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
29
40
|
describe "#post_action_users" do
|
30
41
|
before do
|
31
42
|
stub_get("http://localhost:3000/post_action_users.json?api_key=test_d7fd0429940&api_username=test_user&id=11&post_action_type_id=2").to_return(body: fixture("post_action_users.json"), headers: { content_type: "application/json" })
|
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.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-10-
|
14
|
+
date: 2016-10-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- Rakefile
|
188
188
|
- discourse_api.gemspec
|
189
189
|
- examples/backups.rb
|
190
|
+
- examples/badges.rb
|
190
191
|
- examples/category.rb
|
191
192
|
- examples/change_topic_status.rb
|
192
193
|
- examples/create_topic.rb
|