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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/censys/search/response.rb', line 36 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.
19 20 21 |
# File 'lib/censys/search/response.rb', line 19 def @metadata end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
21 22 23 |
# File 'lib/censys/search/response.rb', line 21 def results @results end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
17 18 19 |
# File 'lib/censys/search/response.rb', line 17 def status @status end |
Instance Method Details
#each {|result| ... } ⇒ Enumerator
Enumerates over all results in the response.
74 75 76 |
# File 'lib/censys/search/response.rb', line 74 def each(&block) @results.each(&block) end |
#each_page {|page| ... } ⇒ Enumerator
Enumerates through each page of results.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/censys/search/response.rb', line 102 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.
84 85 86 |
# File 'lib/censys/search/response.rb', line 84 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
.
58 59 60 |
# File 'lib/censys/search/response.rb', line 58 def ok? @status == 'ok' end |
#pages ⇒ Enumerator
Provides access to additional pages.
119 120 121 |
# File 'lib/censys/search/response.rb', line 119 def pages enum_for(:each_page) end |