Sha256: de230e9dff7bdb5036a68cbfe473c0d08033ab6d86a125629a4cc6ff65ec8613

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Mihari
  module Clients
    #
    # PulseDive API client
    #
    class PulseDive < Base
      # @return [String]
      attr_reader :api_key

      #
      # @param [String] base_url
      # @param [String, nil] api_key
      # @param [Hash] headers
      # @param [Integer, nil] timeout
      #
      def initialize(base_url = "https://pulsedive.com", api_key:, headers: {}, timeout: nil)
        raise(ArgumentError, "api_key is required") unless api_key

        @api_key = api_key

        super(base_url, headers: headers, timeout: timeout)
      end

      #
      # @param [String] ip_or_domain
      #
      # @return [Hash]
      #
      def get_indicator(ip_or_domain)
        _get "/api/info.php", params: { indicator: ip_or_domain }
      end

      #
      # @param [String] indicator_id
      #
      # @return [Hash]
      #
      def get_properties(indicator_id)
        _get "/api/info.php", params: { iid: indicator_id, get: "properties" }
      end

      private

      #
      # @param [String] path
      # @param [Hash] params
      #
      # @return [Hash]
      #
      def _get(path, params: {})
        params["key"] = api_key

        res = get(path, params: params)
        JSON.parse res.body.to_s
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mihari-5.7.1 lib/mihari/clients/publsedive.rb
mihari-5.7.0 lib/mihari/clients/publsedive.rb