Class: Seekr::Occurrence

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/seekr/occurrence.rb

Constant Summary collapse

PER_PAGE =
100

Constants included from Client

Client::BASE_URL

Instance Method Summary collapse

Methods included from Client

#get

Constructor Details

#initialize(monitor_id) ⇒ Occurrence

Returns a new instance of Occurrence.



7
8
9
# File 'lib/seekr/occurrence.rb', line 7

def initialize(monitor_id)
  @monitor_id = monitor_id
end

Instance Method Details

#all(options = {}) ⇒ Object



11
12
13
# File 'lib/seekr/occurrence.rb', line 11

def all(options={})
  get("/search_results", params.merge(options))
end

#all_paginated(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/seekr/occurrence.rb', line 15

def all_paginated(options={})
  options[:page] = 1
  response = get_search_results_json(options)
  iterate = !(response['search_results'].size < PER_PAGE)
  while iterate do
    options[:page] += 1
    next_page_response = get_search_results_json(options)['search_results']
    break if next_page_response.size.zero?
    response['search_results'].concat(next_page_response)
    iterate = !(next_page_response.empty? || next_page_response.size < PER_PAGE)
  end
  JSON.dump(response)
end