housecanary-ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/housecanary/error.rb +4 -2
- data/lib/housecanary/response_parser.rb +14 -2
- data/lib/housecanary/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: 02e36949c6315f14c5b13c5da7bb76603cc700c6
|
4
|
+
data.tar.gz: f5d740e5a980f117a69ef78b498f77f5460ca7c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b4430fb0f5896a201eca23abdf280808cc9e3a8ab0f9d1094c5b6aa8a68ca46abe3f460dd0a3a3fa932e077024400b2efc2c7d19bd92909edc90c02bf65728b
|
7
|
+
data.tar.gz: 73e28bb7e1a9ba16cb507322ae243d573349286bd6dc100ca15a083d03023ddc8c93cb85a9bbfa01f0bb739fde8ecdd6e16a3850835f3f477053f8086adf2822
|
data/lib/housecanary/error.rb
CHANGED
@@ -4,6 +4,7 @@ module Housecanary
|
|
4
4
|
class Error < StandardError #:nodoc:
|
5
5
|
attr_reader :code
|
6
6
|
|
7
|
+
NoContent = Class.new(self)
|
7
8
|
BadRequest = Class.new(self)
|
8
9
|
Unauthorized = Class.new(self)
|
9
10
|
Forbidden = Class.new(self)
|
@@ -12,6 +13,7 @@ module Housecanary
|
|
12
13
|
TooManyRequests = Class.new(self)
|
13
14
|
|
14
15
|
ERRORS_MAP = {
|
16
|
+
204 => Housecanary::Error::NoContent,
|
15
17
|
400 => Housecanary::Error::BadRequest,
|
16
18
|
401 => Housecanary::Error::Unauthorized,
|
17
19
|
403 => Housecanary::Error::Forbidden,
|
@@ -27,8 +29,8 @@ module Housecanary
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def parse_error(body)
|
30
|
-
message = body.fetch(:message, nil)
|
31
|
-
status = body.fetch(:status, nil)
|
32
|
+
message = body.fetch(:message, nil) || body.fetch(:api_code_description, nil)
|
33
|
+
status = body.fetch(:status, nil) || body.fetch(:api_code, nil)
|
32
34
|
[message, status]
|
33
35
|
end
|
34
36
|
end
|
@@ -7,12 +7,24 @@ module Housecanary
|
|
7
7
|
class ResponseParser #:nodoc:
|
8
8
|
class << self
|
9
9
|
def perform(response)
|
10
|
-
response_body =
|
11
|
-
|
10
|
+
response_body = parse_body(response)
|
11
|
+
code = parse_code(response.code, response_body)
|
12
|
+
api_error_filter(code, response_body)
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
15
16
|
|
17
|
+
def parse_body(response)
|
18
|
+
response.body.empty? ? '' : utils.deep_symbolize_keys(response.parse(:json))
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_code(code, body = {})
|
22
|
+
return code unless code.to_s.to_i == 200
|
23
|
+
api_code = body.dig(:api_code) if body.is_a?(Hash)
|
24
|
+
return api_code unless api_code.to_s.to_i.zero?
|
25
|
+
code
|
26
|
+
end
|
27
|
+
|
16
28
|
def utils
|
17
29
|
Housecanary::Utils
|
18
30
|
end
|
data/lib/housecanary/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: housecanary-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilia Kriachkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-auto_inject
|