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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5e090466c70d88bfb066f1c386941a3ef8dfef2
4
- data.tar.gz: 5f0d7f3b8ce464254a7d60dcab7f0cf5278da843
3
+ metadata.gz: a2f179ec13fc9566ae7d24d6221d37daa6c25151
4
+ data.tar.gz: ea37ff2e519badc32e263b0b2e5a735f85f089c1
5
5
  SHA512:
6
- metadata.gz: de5bfc7a37df4f79cce7c1ccc357f47e9e7f6335f723b1577ef3743d19e55b503d8c6ccbdfd8beec9989ae31f86dd1d7396df6b2ad21b455a4f3403c65517d10
7
- data.tar.gz: 3a2020987363559ec2bd44080716d4bfe526c81d169cfeeb8ce467f80c83576bed655f6cbe9866c57f8aac93c4373465f5a9d8932636a8c6c5d677599a04aa86
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`
@@ -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
@@ -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
@@ -14,4 +14,13 @@ module DiscourseApi
14
14
 
15
15
  class UnauthenticatedError < StandardError
16
16
  end
17
+
18
+ class NotFoundError < StandardError
19
+ end
20
+
21
+ class UnprocessableEntity < StandardError
22
+ end
23
+
24
+ class TooManyRequests < StandardError
25
+ end
17
26
  end
@@ -1,3 +1,3 @@
1
1
  module DiscourseApi
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -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" })
@@ -146,7 +146,7 @@ describe DiscourseApi::API::Users do
146
146
  end
147
147
 
148
148
  it "Raises API Error" do
149
- expect{subject.log_out(90)}.to raise_error DiscourseApi::Error
149
+ expect{subject.log_out(90)}.to raise_error DiscourseApi::NotFoundError
150
150
  end
151
151
  end
152
152
 
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.13.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-09 00:00:00.000000000 Z
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