class Checkability::ExternalApiChecker

Checks if postcode exists in external API

Attributes

check_method[R]
connector[R]
http_verb[R]
path[R]
path_suffix[R]

Public Instance Methods

message(res, str = nil) click to toggle source
# File lib/checkability/external_api_checker.rb, line 37
def message(res, str = nil)
  "#{res}:::#{path}: #{str}"
end
post_initialize(conf = {}) click to toggle source
# File lib/checkability/external_api_checker.rb, line 14
def post_initialize(conf = {})
  @path = conf[:path]
  @http_verb = conf[:http_verb] || :get
  @path_suffix = conf[:path_suffix] || ''
  @check_method = conf[:check_method]
  @connector = conf[:connector] ||
               Checkability::ExternalApiConnector.new(conf[:path])
  @resp = nil
end
resp(check_obj) click to toggle source
# File lib/checkability/external_api_checker.rb, line 30
def resp(check_obj)
  @resp ||= connection
            .send(http_verb,
                  "#{check_obj.value.delete(' ')}#{path_suffix}")
  # .get('SE17QD')
end
result(check_obj) click to toggle source
# File lib/checkability/external_api_checker.rb, line 24
def result(check_obj)
  return false unless resp(check_obj).status == 200

  check_method.call(_parsed(resp(check_obj)))
end

Private Instance Methods

_parsed(resp) click to toggle source
# File lib/checkability/external_api_checker.rb, line 43
def _parsed(resp)
  JSON.parse(resp.body)
end