Class: Papertrail::SearchQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/papertrail/search_query.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, query = nil, options = {}) ⇒ SearchQuery

Returns a new instance of SearchQuery.


20
21
22
23
24
# File 'lib/papertrail/search_query.rb', line 20

def initialize(connection, query = nil, options = {})
  @connection = connection
  @query      = query
  @options    = options
end

Instance Attribute Details

#max_idObject

Returns the value of attribute max_id


26
27
28
# File 'lib/papertrail/search_query.rb', line 26

def max_id
  @max_id
end

#subsequent_requestObject

Returns the value of attribute subsequent_request


26
27
28
# File 'lib/papertrail/search_query.rb', line 26

def subsequent_request
  @subsequent_request
end

Class Method Details

.api_urlObject


8
9
10
# File 'lib/papertrail/search_query.rb', line 8

def self.api_url
  '/api/v1/events/search.json'
end

.initial_search_limitObject


12
13
14
# File 'lib/papertrail/search_query.rb', line 12

def self.initial_search_limit
  100
end

.subsequent_search_limitObject


16
17
18
# File 'lib/papertrail/search_query.rb', line 16

def self.subsequent_search_limit
  1000
end

Instance Method Details

#default_request_limitObject


39
40
41
42
43
44
45
46
# File 'lib/papertrail/search_query.rb', line 39

def default_request_limit
  if subsequent_request
    self.class.subsequent_search_limit
  else
    @subsequent_request = true
    self.class.initial_search_limit
  end
end

#next_results_pageObject


28
29
30
31
32
33
34
35
36
37
# File 'lib/papertrail/search_query.rb', line 28

def next_results_page
  params = @options.dup
  params[:q] = @query if @query
  params[:min_id] = @max_id if @max_id
  params[:limit] ||= default_request_limit

  response = @connection.get(self.class.api_url, params)
  @max_id = response.body['max_id']
  Papertrail::SearchResult.new(response.body)
end