class Sumo::Search

This class represents a search job.

Attributes

client[R]
id[R]

Public Class Methods

create(params = {}, client = Sumo.client) click to toggle source

Create a new search job with the given query.

# File lib/sumo/search.rb, line 6
def self.create(params = {}, client = Sumo.client)
  params[:timeZone] ||= params.delete(:time_zone) || params.delete(:tz)
  result = client.post(:path => '/search/jobs', :body => params.to_json)
  new(JSON.parse(result)['id'], client)
end

Private Class Methods

new(id, client) click to toggle source

Initialize a new `Sumo::Search` with the given `id` and `client`.

# File lib/sumo/search.rb, line 13
def initialize(id, client)
  @id = id
  @client = client
end

Public Instance Methods

delete!() click to toggle source

Cancel the search job.

# File lib/sumo/search.rb, line 25
def delete!
  client.delete(:path => base_path)
  nil
end
get_messages(query) click to toggle source

Get the messages from the given offset and limit.

# File lib/sumo/search.rb, line 49
def get_messages(query)
  resp = client.get(:path => "#{base_path}/messages", :query => query)
  extract_response('messages', resp)
end
get_records(query) click to toggle source

Get the records from the given offset and limit.

# File lib/sumo/search.rb, line 55
def get_records(query)
  resp = client.get(:path => "#{base_path}/records", :query => query)
  extract_response('records', resp)
end
messages() click to toggle source

Return an `Enumerator` containing each message found by the search.

# File lib/sumo/search.rb, line 31
def messages
  @messages ||= Sumo::Collection.new(
    :get_values => proc { |hash| self.get_messages(hash) },
    :get_status => proc { self.status },
    :count_key => 'messageCount'
  ).each
end
records() click to toggle source

Return an `Enumerator` containing each record found by the search.

# File lib/sumo/search.rb, line 40
def records
  @records ||= Sumo::Collection.new(
    :get_values => proc { |hash| self.get_records(hash) },
    :get_status => proc { self.status },
    :count_key => 'recordCount'
  ).each
end
status() click to toggle source

Get the status of the search job.

# File lib/sumo/search.rb, line 20
def status
  JSON.parse(client.get(:path => base_path))
end

Private Instance Methods

base_path() click to toggle source
# File lib/sumo/search.rb, line 65
def base_path
  @base_path ||= "/search/jobs/#{id}"
end
extract_response(key, resp) click to toggle source
# File lib/sumo/search.rb, line 60
def extract_response(key, resp)
  JSON.parse(resp)[key].map { |hash| hash['map'] }
end