Sha256: ae806652f44a36b8295647a338998b29684eb7c0cd4314ff3e2664133ea2211f

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Mihari
  module Clients
    class VirusTotal < Base
      #
      # @param [String] base_url
      # @param [String] id
      # @param [String] secret
      # @param [Hash] headers
      #
      def initialize(base_url = "https://www.virustotal.com", api_key:, headers: {})
        raise(ArgumentError, "'api_key' argument is required") if api_key.nil?

        headers["x-apikey"] = api_key

        super(base_url, headers: headers)
      end

      #
      # @param [String] query
      #
      def domain_search(query)
        _get("/api/v3/domains/#{query}/resolutions")
      end

      #
      # @param [String] query
      #
      def ip_search(query)
        _get("/api/v3/ip_addresses/#{query}/resolutions")
      end

      #
      # @param [String] query
      # @param [String, nil] cursor
      #
      def intel_search(query, cursor: nil)
        params = { query: query, cursor: cursor }.compact
        _get("/api/v3/intelligence/search", params: params)
      end

      private

      #
      #
      # @param [String] path
      # @param [Hash] params
      #
      def _get(path, params: {})
        res = get(path, params: params)
        JSON.parse(res.body.to_s)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mihari-5.1.1 lib/mihari/clients/virustotal.rb