discourse_api 0.24.0 → 0.25.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
- SHA1:
3
- metadata.gz: 7035ac6290f7d29c21b40e4b757be7accf00f8c3
4
- data.tar.gz: e9904cd1909edf0897e408bf39be92e95718cfcd
2
+ SHA256:
3
+ metadata.gz: e90f0e873e3f4704e132a4be3b7bc5982c804bf71536c426f90a6008bcf68765
4
+ data.tar.gz: ab6e8ff566a35424fd5baf81641fef179a73978c7b860fda97dd34c62e597599
5
5
  SHA512:
6
- metadata.gz: 20e661ccc7fb697d732bebc1aad5819086dbc693885c8de0461bc37bfaa2428cc3f2e89258997fe48d0d5548d89fa612bba6c2b78a7daa5f94801fb2f1d23cf5
7
- data.tar.gz: ddda92734e27df622b4633bbe88d99b72744dd52c5c52c904a38fda95c5ae157710bcf4754fd00527476b3e5d26bc535b6cff688d8358ea8e0eaeee23ef821b2
6
+ metadata.gz: ae8f232c209917ece93c461619873da8e9883f333345a7d5000637aa5a548cc32044fea30e3b5d815910748fafd49cde11969f829d09ecb6e9647a3c2290bd91
7
+ data.tar.gz: 9980a0850e4597bbc93cd359d38de90f9b3396eed81d73c14b842e7347d2b65bca4db76c5028e441bff67fedb6ce00cfaf2044da37723624a02d327ebe6a0fc3
@@ -2,6 +2,10 @@
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.25.0] - 2018-08-15
6
+ ### Added
7
+ - Added ability to rescue certain error classes and inspect the response object
8
+
5
9
  ## [0.24.0] - 2018-05-30
6
10
  ### Added
7
11
  - Added support for custom `user_fields` when creating a user
data/README.md CHANGED
@@ -66,6 +66,19 @@ client.create_private_message( #=> Creates a private messages b
66
66
 
67
67
  ```
68
68
 
69
+ You can handle some basic errors by rescuing from certain error classes and inspecting the response object passed to those errors:
70
+
71
+ ```ruby
72
+ begin
73
+ client.create_group({ name: 'NO' })
74
+ rescue DiscourseApi::UnprocessableEntity => error
75
+ # `body` is something like `{ errors: ["Name must be at least 3 characters"] }`
76
+ # This outputs "Name must be at least 3 characters"
77
+ puts error.response.body['errors'].first
78
+ end
79
+ ```
80
+
81
+ Check out [lib/discourse_api/error.rb](lib/discourse_api/error.rb) and [lib/discourse_api/client.rb](lib/discourse_api/client.rb)'s `handle_error` method for the types of errors raised by the API.
69
82
 
70
83
  ## Contributing
71
84
 
@@ -138,13 +138,13 @@ module DiscourseApi
138
138
  def handle_error(response)
139
139
  case response.status
140
140
  when 403
141
- raise DiscourseApi::UnauthenticatedError.new(response.env[:body])
141
+ raise DiscourseApi::UnauthenticatedError.new(response.env[:body], response.env)
142
142
  when 404, 410
143
- raise DiscourseApi::NotFoundError.new(response.env[:body])
143
+ raise DiscourseApi::NotFoundError.new(response.env[:body], response.env)
144
144
  when 422
145
- raise DiscourseApi::UnprocessableEntity.new(response.env[:body])
145
+ raise DiscourseApi::UnprocessableEntity.new(response.env[:body], response.env)
146
146
  when 429
147
- raise DiscourseApi::TooManyRequests.new(response.env[:body])
147
+ raise DiscourseApi::TooManyRequests.new(response.env[:body], response.env)
148
148
  when 500...600
149
149
  raise DiscourseApi::Error.new(response.env[:body])
150
150
  end
@@ -1,5 +1,11 @@
1
1
  module DiscourseApi
2
2
  class DiscourseError < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(message, response = nil)
6
+ super(message)
7
+ @response = response
8
+ end
3
9
  end
4
10
 
5
11
  class Error < DiscourseError
@@ -1,3 +1,3 @@
1
1
  module DiscourseApi
2
- VERSION = "0.24.0"
2
+ VERSION = "0.25.0"
3
3
  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.24.0
4
+ version: 0.25.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: 2018-05-30 00:00:00.000000000 Z
14
+ date: 2018-08-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faraday
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  version: '0'
308
308
  requirements: []
309
309
  rubyforge_project:
310
- rubygems_version: 2.6.13
310
+ rubygems_version: 2.7.7
311
311
  signing_key:
312
312
  specification_version: 4
313
313
  summary: Allows access to the Discourse API