breacan 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/breacan/error.rb +23 -18
- data/lib/breacan/response/custom.rb +7 -4
- data/lib/breacan/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 866f53e65dc0fa0ae9c7a169826f9526f1ca7e1d
|
4
|
+
data.tar.gz: 2373e47e6cc067ef3066a120d216e6701c365005
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9274790635979a54746753d15cb54a51b776a2be37dd9176dad7419971e74d2e5209353b5589a8d7e10b259ccd506d54719e74bccc55f03acdfcca27ac086f0a
|
7
|
+
data.tar.gz: 943f4c3d3a5ebb6a2385133ea40e2762b22c650431e19f488f211b1cea834152b40ab41664a8b6995e53c2df6a801fc8ecca5cc9f7f59735b79320f520141908
|
data/lib/breacan/error.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
module Breacan
|
2
2
|
class Error < StandardError
|
3
|
-
def self.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
def self.from_response(response)
|
4
|
+
status = response[:status].to_i
|
5
|
+
if klass = case status
|
6
|
+
when 400 then Breacan::BadRequest
|
7
|
+
when 401 then Breacan::Unauthorized
|
8
|
+
when 403 then Breacan::Forbidden
|
9
|
+
when 404 then Breacan::NotFound
|
10
|
+
when 406 then Breacan::NotAcceptable
|
11
|
+
when 409 then Breacan::Conflict
|
12
|
+
when 415 then Breacan::UnsupportedMediaType
|
13
|
+
when 422 then Breacan::UnprocessableEntity
|
14
|
+
when 400..499 then Breacan::ClientError
|
15
|
+
when 500 then Breacan::InternalServerError
|
16
|
+
when 501 then Breacan::NotImplemented
|
17
|
+
when 502 then Breacan::BadGateway
|
18
|
+
when 503 then Breacan::ServiceUnavailable
|
19
|
+
when 500..599 then Breacan::ServerError
|
20
|
+
end
|
20
21
|
klass.new(response)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
25
|
+
def self.from_body(response, body)
|
26
|
+
Breacan::BadRequest.new(response) unless body[:ok]
|
27
|
+
end
|
28
|
+
|
24
29
|
def initialize(response = nil)
|
25
30
|
@response = response
|
26
31
|
super(build_error_message)
|
@@ -77,7 +82,7 @@ module Breacan
|
|
77
82
|
end
|
78
83
|
|
79
84
|
def redact_url(url_string)
|
80
|
-
%w[client_secret access_token].each do |token|
|
85
|
+
%w[token client_secret access_token].each do |token|
|
81
86
|
url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") if url_string.include? token
|
82
87
|
end
|
83
88
|
url_string
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'breacan/error'
|
3
|
-
require 'json'
|
4
3
|
|
5
4
|
module Breacan
|
6
5
|
module Response
|
@@ -8,16 +7,20 @@ module Breacan
|
|
8
7
|
private
|
9
8
|
|
10
9
|
def on_complete(res)
|
11
|
-
if error = Breacan::Error.
|
10
|
+
if error = Breacan::Error.from_response(res)
|
12
11
|
raise error
|
13
12
|
end
|
14
13
|
|
15
14
|
return if res[:body].empty?
|
16
15
|
|
17
|
-
body =
|
18
|
-
if body[
|
16
|
+
body = Sawyer::Agent.serializer.decode(res[:body])
|
17
|
+
if body[:ok]
|
19
18
|
res[:body].gsub!('"ok":true,', '')
|
20
19
|
end
|
20
|
+
|
21
|
+
if error = Breacan::Error.from_body(res, body)
|
22
|
+
raise error
|
23
|
+
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
data/lib/breacan/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breacan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- linyows
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sawyer
|