Class: Mihari::Clients::Onyphe
- Defined in:
- lib/mihari/clients/onyphe.rb
Overview
Onyphe API client
Constant Summary collapse
- PAGE_SIZE =
10
Instance Attribute Summary collapse
- #api_key ⇒ String readonly
Attributes inherited from Base
#base_url, #headers, #pagination_interval, #timeout
Instance Method Summary collapse
- #datascan(query, page: 1) ⇒ Mihari::Structs::Onyphe::Response
- #datascan_with_pagination(query, pagination_limit: Mihari.config.pagination_limit) ⇒ Enumerable<Mihari::Structs::Onyphe::Response>
-
#initialize(base_url = "https://www.onyphe.io", api_key:, headers: {}, pagination_interval: Mihari.config.pagination_interval, timeout: nil) ⇒ Onyphe
constructor
A new instance of Onyphe.
Constructor Details
#initialize(base_url = "https://www.onyphe.io", api_key:, headers: {}, pagination_interval: Mihari.config.pagination_interval, timeout: nil) ⇒ Onyphe
Returns a new instance of Onyphe.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mihari/clients/onyphe.rb', line 21 def initialize( base_url = "https://www.onyphe.io", api_key:, headers: {}, pagination_interval: Mihari.config.pagination_interval, timeout: nil ) raise(ArgumentError, "api_key is required") if api_key.nil? super(base_url, headers:, pagination_interval:, timeout:) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ String (readonly)
12 13 14 |
# File 'lib/mihari/clients/onyphe.rb', line 12 def api_key @api_key end |
Instance Method Details
#datascan(query, page: 1) ⇒ Mihari::Structs::Onyphe::Response
41 42 43 44 |
# File 'lib/mihari/clients/onyphe.rb', line 41 def datascan(query, page: 1) params = {page:, apikey: api_key} Structs::Onyphe::Response.from_dynamic! get_json("/api/v2/simple/datascan/#{query}", params:) end |
#datascan_with_pagination(query, pagination_limit: Mihari.config.pagination_limit) ⇒ Enumerable<Mihari::Structs::Onyphe::Response>
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mihari/clients/onyphe.rb', line 52 def datascan_with_pagination(query, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| res = datascan(query, page:) y.yield res break if res.total <= page * PAGE_SIZE sleep_pagination_interval end end end |