Class: TINCheck::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tincheck/response.rb

Constant Summary collapse

APIError =
Class.new(RuntimeError)
ConfigError =
Class.new(RuntimeError)
HTTPError =
Class.new(RuntimeError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, parser:) ⇒ Response



30
31
32
# File 'lib/tincheck/response.rb', line 30

def initialize(xml, parser:)
  @to_h = merge_results(parser.(xml).values)
end

Class Method Details

.with_http_response(http_response, parser:) ⇒ Object



14
15
16
17
# 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

Instance Method Details

#[](key) ⇒ Object



34
35
36
# File 'lib/tincheck/response.rb', line 34

def [](key)
  @to_h[key]
end

#calls_remainingObject



38
39
40
# File 'lib/tincheck/response.rb', line 38

def calls_remaining
  self['CallsRemaining'] == 'No Limit' ? nil : self['CallsRemaining'].to_i
end

#death_record?Boolean



42
43
44
# File 'lib/tincheck/response.rb', line 42

def death_record?
  self['DMF_CODE'] == '1'
end

#each(*args, &blk) ⇒ Object



46
47
48
# File 'lib/tincheck/response.rb', line 46

def each(*args, &blk)
  @to_h.each(*args, &blk)
end

#merge_results(results) ⇒ Object



50
51
52
# File 'lib/tincheck/response.rb', line 50

def merge_results(results)
  results.reduce({}) { |h, rs| h.merge(rs) }
end

#name_and_tin_match?Boolean



54
55
56
# File 'lib/tincheck/response.rb', line 54

def name_and_tin_match?
  %w[1 6 7 8].include?(self['TINNAME_CODE'])
end

#to_hObject Also known as: to_hash



58
59
60
# File 'lib/tincheck/response.rb', line 58

def to_h
  @to_h.dup
end

#watch_lists?Boolean



63
64
65
# File 'lib/tincheck/response.rb', line 63

def watch_lists?
  self['LISTSMATCH_CODE'] == '1'
end