Class: Sumo::Search
- Inherits:
-
Object
- Object
- Sumo::Search
- Defined in:
- lib/sumo/search.rb
Overview
This class represents a search job.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.create(params = {}, client = Sumo.client) ⇒ Object
Create a new search job with the given query.
Instance Method Summary collapse
-
#delete! ⇒ Object
Cancel the search job.
-
#get_messages(query) ⇒ Object
Get the messages from the given offset and limit.
-
#get_records(query) ⇒ Object
Get the records from the given offset and limit.
-
#initialize(id, client) ⇒ Search
constructor
Initialize a new ‘Sumo::Search` with the given `id` and `client`.
-
#messages ⇒ Object
Return an ‘Enumerator` containing each message found by the search.
-
#records ⇒ Object
Return an ‘Enumerator` containing each record found by the search.
-
#status ⇒ Object
Get the status of the search job.
Constructor Details
#initialize(id, client) ⇒ Search
Initialize a new ‘Sumo::Search` with the given `id` and `client`.
13 14 15 16 |
# File 'lib/sumo/search.rb', line 13 def initialize(id, client) @id = id @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/sumo/search.rb', line 3 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/sumo/search.rb', line 3 def id @id end |
Class Method Details
.create(params = {}, client = Sumo.client) ⇒ Object
Create a new search job with the given query.
6 7 8 9 10 |
# 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 |
Instance Method Details
#delete! ⇒ Object
Cancel the search job.
25 26 27 28 |
# File 'lib/sumo/search.rb', line 25 def delete! client.delete(:path => base_path) nil end |
#get_messages(query) ⇒ Object
Get the messages from the given offset and limit.
49 50 51 52 |
# File 'lib/sumo/search.rb', line 49 def (query) resp = client.get(:path => "#{base_path}/messages", :query => query) extract_response('messages', resp) end |
#get_records(query) ⇒ Object
Get the records from the given offset and limit.
55 56 57 58 |
# 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 ⇒ Object
Return an ‘Enumerator` containing each message found by the search.
31 32 33 34 35 36 37 |
# File 'lib/sumo/search.rb', line 31 def @messages ||= Sumo::Collection.new( :get_values => proc { |hash| self.(hash) }, :get_status => proc { self.status }, :count_key => 'messageCount' ).each end |
#records ⇒ Object
Return an ‘Enumerator` containing each record found by the search.
40 41 42 43 44 45 46 |
# 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 ⇒ Object
Get the status of the search job.
20 21 22 |
# File 'lib/sumo/search.rb', line 20 def status JSON.parse(client.get(:path => base_path)) end |