class Seekr::Occurrence

Constants

PER_PAGE

Attributes

monitor_id[R]

Public Class Methods

new(monitor_id) click to toggle source
# File lib/seekr/occurrence.rb, line 7
def initialize(monitor_id)
  @monitor_id = monitor_id
end

Public Instance Methods

all(options={}) click to toggle source
# File lib/seekr/occurrence.rb, line 11
def all(options={})
  get("/search_results", params.merge(options))
end
all_paginated(options={}) click to toggle source
# 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

Private Instance Methods

get_search_results_json(options={}) click to toggle source
# File lib/seekr/occurrence.rb, line 39
def get_search_results_json(options={})
  JSON.parse(get("/search_results", params.merge(options)))
end
params() click to toggle source
# File lib/seekr/occurrence.rb, line 32
def params
  {
    search_id: monitor_id,
    per_page: PER_PAGE
  }
end