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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89ec389874ba91ad835c4bcf0d06c51a89fa37fa
4
- data.tar.gz: 87369ebf011c3dbaf3de659460b90e9cb4086ed2
3
+ metadata.gz: 02e36949c6315f14c5b13c5da7bb76603cc700c6
4
+ data.tar.gz: f5d740e5a980f117a69ef78b498f77f5460ca7c8
5
5
  SHA512:
6
- metadata.gz: '02829c7246cec460c0c5f4ce61f0d9fe0787f97ba9630a8548e6ec8425ed78c8c709821ff07751e2feee72dbdbd26b0ef6d73488984781f643b3b8d3294343f9'
7
- data.tar.gz: e7b7c02a92175fc295f2070a69dc104373b208d97e54c711492a484bb8a81c63a0afb35ce30b684ca829def72d8ccef9351773f2aaf2cbe6d7dfd3fba8497a06
6
+ metadata.gz: 0b4430fb0f5896a201eca23abdf280808cc9e3a8ab0f9d1094c5b6aa8a68ca46abe3f460dd0a3a3fa932e077024400b2efc2c7d19bd92909edc90c02bf65728b
7
+ data.tar.gz: 73e28bb7e1a9ba16cb507322ae243d573349286bd6dc100ca15a083d03023ddc8c93cb85a9bbfa01f0bb739fde8ecdd6e16a3850835f3f477053f8086adf2822
@@ -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 = response.body.empty? ? '' : utils.deep_symbolize_keys(response.parse(:json))
11
- api_error_filter(response.code, response_body)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Housecanary
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
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.0
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-15 00:00:00.000000000 Z
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