lib/zendesk2/searchable.rb in zendesk2-1.4.1 vs lib/zendesk2/searchable.rb in zendesk2-1.4.2

- old
+ new

@@ -1,8 +1,11 @@ module Zendesk2::Searchable 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 # Search for resources of a certain type. # # If you need more control over your search (see Zendesk2::Client::Real#search) @@ -12,11 +15,11 @@ # @example search with fully qualified query # client.tickets.search("created>2012-06-17+type:ticket+organization:'Mondocam Photo'") # # @param [String, Hash] seach terms. This will be converted to a qualified Zendesk search String # @see http://developer.zendesk.com/documentation/rest_api/search.html - def search(terms) + def search(terms, params={}) query = if terms.is_a?(Hash) terms.merge!("type" => self.class.search_type) if self.class.search_type terms.merge(self.class.scopes.inject({}){|r,k| r.merge(k.to_s => public_send(k))}). map { |k,v| "#{k}:#{v}" }.join(" ") else @@ -31,15 +34,15 @@ qualified_search end end end - body = connection.send(self.class.search_request, query).body + body = connection.send(self.class.search_request, query, params).body if data = body.delete("results") - collection = self.clone.load(data) - collection.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page")) - collection + self.load(data) + self.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page").merge("filtered" => true)) + self end end module Attributes attr_accessor :search_type