Sha256: 97317e79102ad640120497e0471ac11af235d3f95beed8b75de24f82a966bb65

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Mihari
  module Analyzers
    class HunterHow < Base
      # @return [String, nil]
      attr_reader :api_key

      # @return [Date]
      attr_reader :start_time

      # @return [Date]
      attr_reader :end_time

      #
      # @param [String] query
      # @param [Hash, nil] options
      # @param [String, nil] api_key
      #
      def initialize(query, start_time:, end_time:, options: nil, api_key: nil)
        super(query, options: options)

        @api_key = api_key || Mihari.config.hunterhow_api_key

        @start_time = start_time
        @end_time = end_time
      end

      #
      # @return [Array<Mihari::Artifact>]
      #
      def artifacts
        artifacts = []

        (1..pagination_limit).each do |page|
          res = client.search(
            query,
            page: page,
            page_size: PAGE_SIZE,
            start_time: start_time.strftime("%Y-%m-%d"),
            end_time: end_time.strftime("%Y-%m-%d")
          )

          artifacts << res.data.artifacts

          break if res.data.list.length < PAGE_SIZE

          sleep_interval
        end

        artifacts.flatten
      end

      def configuration_keys
        %w[hunterhow_api_key]
      end

      private

      # @return [Integer]
      PAGE_SIZE = 100

      def client
        @client ||= Clients::HunterHow.new(api_key: api_key)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mihari-5.4.2 lib/mihari/analyzers/hunterhow.rb
mihari-5.4.1 lib/mihari/analyzers/hunterhow.rb