Class: Mihari::Clients::Fofa
- Inherits:
-
Base
- Object
- Base
- Mihari::Clients::Fofa
show all
- Defined in:
- lib/mihari/clients/fofa.rb
Overview
Constant Summary
collapse
- PAGE_SIZE =
10_000
Instance Attribute Summary collapse
Attributes inherited from Base
#base_url, #headers, #pagination_interval, #timeout
Instance Method Summary
collapse
Constructor Details
#initialize(base_url = "https://fofa.info", api_key:, email:, headers: {}, pagination_interval: Mihari.config.pagination_interval, timeout: nil) ⇒ Fofa
Returns a new instance of Fofa.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/mihari/clients/fofa.rb', line 28
def initialize(
base_url = "https://fofa.info",
api_key:,
email:,
headers: {},
pagination_interval: Mihari.config.,
timeout: nil
)
raise(ArgumentError, "api_key is required") unless api_key
raise(ArgumentError, "email is required") unless email
@api_key = api_key
@email = email
super(base_url, headers:, pagination_interval:, timeout:)
end
|
Instance Attribute Details
#api_key ⇒ String
14
15
16
|
# File 'lib/mihari/clients/fofa.rb', line 14
def api_key
@api_key
end
|
#email ⇒ String
17
18
19
|
# File 'lib/mihari/clients/fofa.rb', line 17
def email
@email
end
|
Instance Method Details
52
53
54
55
56
57
58
59
|
# File 'lib/mihari/clients/fofa.rb', line 52
def search(query, page:, size: PAGE_SIZE)
qbase64 = Base64.urlsafe_encode64(query)
params = {qbase64:, size:, page:, email:, key: api_key}.compact
res = Structs::Fofa::Response.from_dynamic!(get_json("/api/v1/search/all", params:))
raise ResponseError, res.errmsg if res.error
res
end
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/mihari/clients/fofa.rb', line 68
def (query, size: PAGE_SIZE, pagination_limit: Mihari.config.)
Enumerator.new do |y|
(1..).each do |page|
res = search(query, page:, size:)
y.yield res
break if res.error
break if (res.results || []).length < size
end
end
end
|