Sha256: 8c7be6b059c81984ff77843186f9d720143b13b5e6eefb78f9176635b465f05b

Contents?: true

Size: 790 Bytes

Versions: 3

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

require "urlscan"

module Miteru
  class Feeds
    class UrlScan < Feed
      attr_reader :size

      def initialize(size = 100)
        @size = size
        raise ArgumentError, "size must be less than 10,000" if size > 10_000
      end

      def api
        @api ||= ::UrlScan::API.new(Miteru.configuration.urlscan_api_key)
      end

      def urls
        urls_from_community_feed
      rescue ::UrlScan::ResponseError => e
        Miteru.logger.error "Failed to load urlscan.io feed (#{e})"
        []
      end

      private

      def urls_from_community_feed
        res = api.search("task.method:automatic", size: size)

        results = res["results"] || []
        results.map { |result| result.dig("task", "url") }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
miteru-1.2.2 lib/miteru/feeds/urlscan.rb
miteru-1.2.1 lib/miteru/feeds/urlscan.rb
miteru-1.2.0 lib/miteru/feeds/urlscan.rb