Class: Censys::API
- Inherits:
-
Object
- Object
- Censys::API
- Defined in:
- lib/censys/api.rb
Overview
Censys Search v2 API wrapper
Constant Summary collapse
Instance Method Summary collapse
-
#aggregate(query, field, num_buckets: nil) ⇒ Hash
Aggregate current index.
-
#initialize(id = ENV["CENSYS_ID"], secret = ENV["CENSYS_SECRET"]) ⇒ API
constructor
Initializes the API.
-
#search(query, per_page: nil, cursor: nil) ⇒ Hash
Search current index.
-
#view(document_id, at_time: nil) ⇒ Hash
View document from current index.
Constructor Details
#initialize(id = ENV["CENSYS_ID"], secret = ENV["CENSYS_SECRET"]) ⇒ API
Initializes the API.
30 31 32 33 34 35 36 |
# File 'lib/censys/api.rb', line 30 def initialize(id = ENV["CENSYS_ID"], secret = ENV["CENSYS_SECRET"]) raise(ArgumentError, "'id' argument is required") if id.nil? || id.empty? raise(ArgumentError, "'secret' argument is required") if secret.nil? || secret.empty? @id = id @secret = secret end |
Instance Method Details
#aggregate(query, field, num_buckets: nil) ⇒ Hash
Aggregate current index.
Creates a report on the breakdown of the values of a field in a result set. For more details, see our documentation: search.censys.io/api/v2/docs
89 90 91 92 93 94 |
# File 'lib/censys/api.rb', line 89 def aggregate(query, field, num_buckets: nil) params = { q: query, field: field, num_buckets: num_buckets }.compact get("/aggregate", params) do |json| json end end |
#search(query, per_page: nil, cursor: nil) ⇒ Hash
Search current index.
Searches the given index for all records that match the given query. For more details, see our documentation: search.censys.io/api/v2/docs
70 71 72 73 74 75 |
# File 'lib/censys/api.rb', line 70 def search(query, per_page: nil, cursor: nil) params = { q: query, per_page: per_page, cursor: cursor }.compact get("/search", params) do |json| json end end |
#view(document_id, at_time: nil) ⇒ Hash
View document from current index.
View the current structured data we have on a specific document. For more details, see our documentation: search.censys.io/api/v2/docs
49 50 51 52 53 54 55 56 |
# File 'lib/censys/api.rb', line 49 def view(document_id, at_time: nil) at_time = at_time.strftime("%Y-%m-%dT%H:%M:%S.%6NZ") if at_time.is_a?(Time) params = { at_time: at_time }.compact get("/#{document_id}", params) do |json| json end end |