Module: Zendesk2::Searchable

Overview

Defines #search on relevant collections

Defined Under Namespace

Modules: Attributes

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
8
9
# File 'lib/zendesk2/searchable.rb', line 4

def self.included(klass)
  klass.send(:extend, Zendesk2::Searchable::Attributes)
  # @note signal to underlying collection that a search request
  #       must be use when requesting associated pages
  klass.send(:attribute, :filtered, type: :boolean)
end

Instance Method Details

#search(terms, params = {}) ⇒ Object

Search for resources of a certain type.

If you need more control over your search (see Zendesk2::Real#search)

Examples:

search with a simple hash

client.users.search("email" => "[email protected]")

search with fully qualified query

client.tickets.search("created>2012-06-17+type:ticket+organization:'Mondocam Photo'")

Parameters:

  • seach (String, Hash)

    terms. This will be converted to a qualified Zendesk search String

See Also:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zendesk2/searchable.rb', line 22

def search(terms, params = {})
  query = (terms.is_a?(Hash) ? search_by_hash(terms) : search_by_string(terms))
  body = cistern.send(self.class.search_request, query, params).body
  data = body.delete('results')

  return nil unless data

  load(data)

  merge_attributes(Cistern::Hash.slice(body, 'count', 'next_page', 'previous_page').merge('filtered' => true))
  self
end