class TINCheck::Response

Constants

APIError
ConfigError
HTTPError

Public Class Methods

new(xml, parser:) click to toggle source
# File lib/tincheck/response.rb, line 30
def initialize(xml, parser:)
  @to_h = merge_results(parser.(xml).values)
end
with_http_response(http_response, parser:) click to toggle source
# File lib/tincheck/response.rb, line 14
def with_http_response(http_response, parser:)
  http_ok?(http_response)
  new(http_response.body, parser: parser)
end

Private Class Methods

http_error(http_response) click to toggle source
# File lib/tincheck/response.rb, line 21
def http_error(http_response)
  "server responded with #{http_response.code} instead of 200"
end
http_ok?(http_response) click to toggle source
# File lib/tincheck/response.rb, line 25
def http_ok?(http_response)
  raise HTTPError, http_error(http_response) unless http_response.code == '200'
end

Public Instance Methods

[](key) click to toggle source
# File lib/tincheck/response.rb, line 34
def [](key)
  @to_h[key]
end
calls_remaining() click to toggle source
# File lib/tincheck/response.rb, line 38
def calls_remaining
  self['CallsRemaining'] == 'No Limit' ? nil : self['CallsRemaining'].to_i
end
death_record?() click to toggle source
# File lib/tincheck/response.rb, line 42
def death_record?
  self['DMF_CODE'] == '1'
end
each(*args, &blk) click to toggle source
# File lib/tincheck/response.rb, line 46
def each(*args, &blk)
  @to_h.each(*args, &blk)
end
merge_results(results) click to toggle source
# File lib/tincheck/response.rb, line 50
def merge_results(results)
  results.reduce({}) { |h, rs| h.merge(rs) }
end
name_and_tin_match?() click to toggle source
# File lib/tincheck/response.rb, line 54
def name_and_tin_match?
  %w[1 6 7 8].include?(self['TINNAME_CODE'])
end
to_h() click to toggle source
# File lib/tincheck/response.rb, line 58
def to_h
  @to_h.dup
end
Also aliased as: to_hash
to_hash()
Alias for: to_h
watch_lists?() click to toggle source
# File lib/tincheck/response.rb, line 63
def watch_lists?
  self['LISTSMATCH_CODE'] == '1'
end