Class: Censys::Search::Response
- Inherits:
-
Object
- Object
- Censys::Search::Response
- Includes:
- Enumerable
- Defined in:
- lib/censys/search/response.rb
Constant Summary collapse
- RESULTS =
{ ipv4: IPv4, websites: Website, certificates: Certificate }.freeze
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#each {|result| ... } ⇒ Enumerator
Enumerates over all results in the response.
-
#each_page {|page| ... } ⇒ Enumerator
Enumerates through each page of results.
-
#initialize(api, result_type, params, response) ⇒ Response
constructor
A new instance of Response.
-
#next_page ⇒ Search::Response?
(also: #next)
Queries the next page of results.
-
#ok? ⇒ Boolean
Determines if the response has status of
ok
. -
#pages ⇒ Enumerator
Provides access to additional pages.
Constructor Details
#initialize(api, result_type, params, response) ⇒ Response
Returns a new instance of Response.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/censys/search/response.rb', line 38 def initialize(api, result_type, params, response) @api = api @result_type = result_type @params = params @status = response['status'] @metadata = Metadata.new(response['metadata']) unless (result_class = RESULTS[@result_type]) raise(ArgumentError, "invalid result type: #{@result_type}") end @results = response['results'].map do |result| result_class.new(result, @api) end end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/censys/search/response.rb', line 21 def @metadata end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
23 24 25 |
# File 'lib/censys/search/response.rb', line 23 def results @results end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
19 20 21 |
# File 'lib/censys/search/response.rb', line 19 def status @status end |
Instance Method Details
#each {|result| ... } ⇒ Enumerator
Enumerates over all results in the response.
76 77 78 |
# File 'lib/censys/search/response.rb', line 76 def each(&block) @results.each(&block) end |
#each_page {|page| ... } ⇒ Enumerator
Enumerates through each page of results.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/censys/search/response.rb', line 104 def each_page return enum_for(__method__) unless block_given? page = self while page yield page page = page.next_page end end |
#next_page ⇒ Search::Response? Also known as: next
Queries the next page of results.
86 87 88 |
# File 'lib/censys/search/response.rb', line 86 def next_page @api.search(@result_type, @params.merge(page: @metadata.page + 1)) if @metadata.page < @metadata.pages end |
#ok? ⇒ Boolean
Determines if the response has status of ok
.
60 61 62 |
# File 'lib/censys/search/response.rb', line 60 def ok? @status == 'ok' end |
#pages ⇒ Enumerator
Provides access to additional pages.
121 122 123 |
# File 'lib/censys/search/response.rb', line 121 def pages enum_for(:each_page) end |