Sha256: d20410b2416ef4b30d863ebcb46b31dc61053f6a33a591c638f7ca9a51d8cd51

Contents?: true

Size: 1.32 KB

Versions: 14

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Mihari
  module Clients
    class VirusTotal < Base
      #
      # @param [String] base_url
      # @param [String, nil] api_key
      # @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
      #
      # @return [Hash]
      #
      def domain_search(query)
        _get("/api/v3/domains/#{query}/resolutions")
      end

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

      #
      # @param [String] query
      # @param [String, nil] cursor
      #
      # @return [Hash]
      #
      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
      #
      # @return [Hash]
      #
      def _get(path, params: {})
        res = get(path, params: params)
        JSON.parse(res.body.to_s)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mihari-5.4.2 lib/mihari/clients/virustotal.rb
mihari-5.4.1 lib/mihari/clients/virustotal.rb
mihari-5.4.0 lib/mihari/clients/virustotal.rb
mihari-5.3.2 lib/mihari/clients/virustotal.rb
mihari-5.3.1 lib/mihari/clients/virustotal.rb
mihari-5.3.0 lib/mihari/clients/virustotal.rb
mihari-5.2.4 lib/mihari/clients/virustotal.rb
mihari-5.2.3 lib/mihari/clients/virustotal.rb
mihari-5.2.2 lib/mihari/clients/virustotal.rb
mihari-5.2.1 lib/mihari/clients/virustotal.rb
mihari-5.2.0 lib/mihari/clients/virustotal.rb
mihari-5.1.4 lib/mihari/clients/virustotal.rb
mihari-5.1.3 lib/mihari/clients/virustotal.rb
mihari-5.1.2 lib/mihari/clients/virustotal.rb