Class: KeytechKit::Search

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/keytechKit/search.rb

Overview

Can search the API by fulltext, fields, element types Can search by a predefined ‘stored’ query by its queryID Can sort the results Can group the results

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, username, password) ⇒ Search

Returns a new instance of Search.



16
17
18
19
# File 'lib/keytechKit/search.rb', line 16

def initialize(base_url, username, password)
  self.class.base_uri(base_url)
  @auth = { username: username, password: password }
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



14
15
16
# File 'lib/keytechKit/search.rb', line 14

def response
  @response
end

Instance Method Details

#query(options = {}) ⇒ Object

options = {}; :q = searchtext - optional parameter: makes a fulltext search, (unusable on very large data) :size :page :attributes = “ALL”,“None”,“Lister”, “Editor”, “GlobalLister”, “System”, “Secondary”, “Explorer” :reload = true :classes = “DEFAULT_DO”,“DEFAULT_FD”, “DEFAULT_MI”, “DEFAULT_MAIL”,“DEFAULT_TASK” :fields = [<attribute><operator><value>:] - as_do__created_by=jgrant:as_do_changed_by=pmiller - finds all elememnts cerated by jgrant and changed by pmiller Remember: dates must be send in epoch format! “/date(1464127200000)/”



30
31
32
33
34
35
36
37
38
39
# File 'lib/keytechKit/search.rb', line 30

def query(options = {})
  parameter = { query: options }
  parameter[:basic_auth] = @auth
  response = self.class.get('/search', parameter)
  if response.success?
    parse_response(response)
  else
    puts "Could not execute query: #{parse_response.headers['x-errordescription']}"
  end
end