Class: Mihari::Clients::GreyNoise

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

Instance Attribute Summary

Attributes inherited from Base

#base_url, #headers

Instance Method Summary collapse

Constructor Details

#initialize(base_url = "https://api.greynoise.io", api_key:, headers: {}) ⇒ GreyNoise

Returns a new instance of GreyNoise.

Parameters:

  • base_url (String) (defaults to: "https://api.greynoise.io")
  • api_key (String, nil)
  • headers (Hash) (defaults to: {})

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/mihari/clients/greynoise.rb', line 11

def initialize(base_url = "https://api.greynoise.io", api_key:, headers: {})
  raise(ArgumentError, "'api_key' argument is required") unless api_key

  headers["key"] = api_key
  super(base_url, headers: headers)
end

Instance Method Details

#gnql_search(query, size: nil, scroll: nil) ⇒ Hash

GNQL (GreyNoise Query Language) is a domain-specific query language that uses Lucene deep under the hood

Parameters:

  • query (String)

    GNQL query string

  • size (Integer, nil) (defaults to: nil)

    Maximum amount of results to grab

  • scroll (Integer, nil) (defaults to: nil)

    Scroll token to paginate through results

Returns:

  • (Hash)


27
28
29
30
31
# File 'lib/mihari/clients/greynoise.rb', line 27

def gnql_search(query, size: nil, scroll: nil)
  params = { query: query, size: size, scroll: scroll }.compact
  res = get("/v2/experimental/gnql", params: params)
  Structs::GreyNoise::Response.from_dynamic! JSON.parse(res.body.to_s)
end