module Ammitto
Constants
- DATA_PROCESSED_ENDPOINT
- DATA_SOURCE_ENDPOINT
- VERSION
Public Class Methods
search(term)
click to toggle source
# File lib/ammitto.rb, line 19 def search(term) warn "[amitto] fetching for: \"#{term}\" ..." response = Net::HTTP.get_response URI(DATA_PROCESSED_ENDPOINT) doc = Nokogiri::HTML(response.body) data_sources = doc.xpath('//a[contains(text(), "sanctions_list.yaml")]').map(&:text) results = [] data_sources.each do |ds| warn "[amitto] searching in #{ds.sub('.yaml', '').gsub("_", " ")}" resp = Net::HTTP.get_response URI("#{DATA_SOURCE_ENDPOINT}#{ds}") data = YAML::safe_load(resp.body) res = data.find_all { |d| d["names"].join(" ").downcase.index(term.downcase) } warn "[amitto] found match: #{res.length}" results << res end results = SanctionItemCollection.new(results.flatten) warn "[amitto] found total match : #{results.length}" results rescue SocketError, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Net::ReadTimeout, Errno::ETIMEDOUT => e raise Ammitto::RequestError, "Could not access data source due to : #{e.message}" end