Class: Mihari::Clients::TheHive

Inherits:
Base
  • Object
show all
Defined in:
lib/mihari/clients/the_hive.rb

Overview

TheHive API client

Instance Attribute Summary collapse

Attributes inherited from Base

#base_url, #headers, #pagination_interval, #timeout

Instance Method Summary collapse

Constructor Details

#initialize(base_url, api_key:, api_version: "v1", headers: {}, timeout: nil) ⇒ TheHive

Returns a new instance of TheHive.

Parameters:

  • base_url (String)
  • api_key (String, nil)
  • api_version (String) (defaults to: "v1")
  • headers (Hash) (defaults to: {})
  • timeout (Integer, nil) (defaults to: nil)

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
# File 'lib/mihari/clients/the_hive.rb', line 18

def initialize(base_url, api_key:, api_version: "v1", headers: {}, timeout: nil)
  raise(ArgumentError, "api_key is required") unless api_key

  headers["authorization"] = "Bearer #{api_key}"
  super(base_url, headers:, timeout:)

  @api_version = api_version
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



9
10
11
# File 'lib/mihari/clients/the_hive.rb', line 9

def api_version
  @api_version
end

Instance Method Details

#alert(json) ⇒ Hash

Parameters:

  • json (Hash)

Returns:

  • (Hash)


32
33
34
35
# File 'lib/mihari/clients/the_hive.rb', line 32

def alert(json)
  json = json.to_camelback_keys.compact
  post_json("/api/#{api_version}/alert", json:)
end