class URLhausMonitor::Monitor

Attributes

cache[R]
checker[R]

Public Class Methods

new() click to toggle source
# File lib/urlhaus_monitor/monitor.rb, line 10
def initialize
  @checker = Checker.new
  @cache = Lightly.new(dir: "/tmp/urlhause_monitor", life: "180d")
end

Public Instance Methods

lookup_by_asn(asn) click to toggle source
# File lib/urlhaus_monitor/monitor.rb, line 25
def lookup_by_asn(asn)
  entries = checker.lookup_by_asn(asn)
  process entries
end
lookup_by_country(country) click to toggle source
# File lib/urlhaus_monitor/monitor.rb, line 15
def lookup_by_country(country)
  entries = checker.lookup_by_country(country)
  process entries
end
lookup_by_tld(tld) click to toggle source
# File lib/urlhaus_monitor/monitor.rb, line 20
def lookup_by_tld(tld)
  entries = checker.lookup_by_tld(tld)
  process entries
end
process(entries) click to toggle source
# File lib/urlhaus_monitor/monitor.rb, line 30
def process(entries)
  return nil unless entries

  entries.each do |entry|
    next if cache.cached? entry.url

    Notifier.notify entry.title, entry.to_attachements
    cache.save entry.url, true
  end
end