lib/housecanary/response_parser.rb in housecanary-ruby-0.1.0 vs lib/housecanary/response_parser.rb in housecanary-ruby-0.1.1
- old
+ new
@@ -5,14 +5,26 @@
module Housecanary
class ResponseParser #:nodoc:
class << self
def perform(response)
- response_body = response.body.empty? ? '' : utils.deep_symbolize_keys(response.parse(:json))
- api_error_filter(response.code, response_body)
+ response_body = parse_body(response)
+ code = parse_code(response.code, response_body)
+ api_error_filter(code, response_body)
end
private
+
+ def parse_body(response)
+ response.body.empty? ? '' : utils.deep_symbolize_keys(response.parse(:json))
+ end
+
+ def parse_code(code, body = {})
+ return code unless code.to_s.to_i == 200
+ api_code = body.dig(:api_code) if body.is_a?(Hash)
+ return api_code unless api_code.to_s.to_i.zero?
+ code
+ end
def utils
Housecanary::Utils
end