Class: Mihari::Clients::ZoomEye
- Defined in:
- lib/mihari/clients/zoomeye.rb
Overview
ZoomEye API client
Constant Summary collapse
- PAGE_SIZE =
10
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Attributes inherited from Base
#base_url, #headers, #pagination_interval, #timeout
Instance Method Summary collapse
-
#host_search(query, page: nil, facets: nil) ⇒ Hash
Search the Host devices.
- #host_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) ⇒ Enumerable<Hash>
- #http ⇒ ::HTTP::Client
-
#initialize(base_url = "https://api.zoomeye.org", api_key:, headers: {}, pagination_interval: Mihari.config.pagination_interval, timeout: nil) ⇒ ZoomEye
constructor
A new instance of ZoomEye.
-
#web_search(query, page: nil, facets: nil) ⇒ Hash
Search the Web technologies.
- #web_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) ⇒ Enumerable<Hash>
Constructor Details
#initialize(base_url = "https://api.zoomeye.org", api_key:, headers: {}, pagination_interval: Mihari.config.pagination_interval, timeout: nil) ⇒ ZoomEye
Returns a new instance of ZoomEye.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mihari/clients/zoomeye.rb', line 20 def initialize( base_url = "https://api.zoomeye.org", api_key:, headers: {}, pagination_interval: Mihari.config.pagination_interval, timeout: nil ) raise(ArgumentError, "api_key is required") unless api_key headers["api-key"] = api_key super(base_url, headers:, pagination_interval:, timeout:) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/mihari/clients/zoomeye.rb', line 11 def api_key @api_key end |
Instance Method Details
#host_search(query, page: nil, facets: nil) ⇒ Hash
Search the Host devices
49 50 51 52 53 54 55 56 |
# File 'lib/mihari/clients/zoomeye.rb', line 49 def host_search(query, page: nil, facets: nil) params = { query:, page:, facets: }.compact get_json "/host/search", params: end |
#host_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) ⇒ Enumerable<Hash>
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mihari/clients/zoomeye.rb', line 65 def host_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| res = host_search(query, facets:, page:) break if res.nil? y.yield res total = res["total"].to_i break if total <= page * PAGE_SIZE sleep_pagination_interval end end end |
#http ⇒ ::HTTP::Client
36 37 38 |
# File 'lib/mihari/clients/zoomeye.rb', line 36 def http @http ||= HTTP::Factory.build(headers:, timeout:, raise_exception: false) end |
#web_search(query, page: nil, facets: nil) ⇒ Hash
Search the Web technologies
91 92 93 94 95 96 97 98 |
# File 'lib/mihari/clients/zoomeye.rb', line 91 def web_search(query, page: nil, facets: nil) params = { query:, page:, facets: }.compact get_json "/web/search", params: end |
#web_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) ⇒ Enumerable<Hash>
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mihari/clients/zoomeye.rb', line 107 def web_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| res = web_search(query, facets:, page:) break if res.nil? y.yield res total = res["total"].to_i break if total <= page * PAGE_SIZE sleep_pagination_interval end end end |