Class: ZendeskSupportAPI::Search
- Inherits:
-
Object
- Object
- ZendeskSupportAPI::Search
- Defined in:
- lib/zendesk_support_api/search.rb
Overview
Search class - developer.zendesk.com/rest_api/docs/support/search
Class Method Summary collapse
-
.bad_search(string) ⇒ String
Prints out an error message.
-
.list(client, query, sort = '', order = 'desc') ⇒ Array
Perform a search and list results (first 100).
-
.order_valid?(order) ⇒ Boolean
Determines if a given order string is valid.
-
.sort_order_string(sort, order) ⇒ String
Determines the sort and order to use in the query.
-
.sort_valid?(sort) ⇒ Boolean
Determines if a given sort string is valid.
Class Method Details
.bad_search(string) ⇒ String
Prints out an error message
91 92 93 |
# File 'lib/zendesk_support_api/search.rb', line 91 def self.bad_search(string) "Search cannot be completed: #{string}" end |
.list(client, query, sort = '', order = 'desc') ⇒ Array
Perform a search and list results (first 100)
36 37 38 39 40 41 42 |
# File 'lib/zendesk_support_api/search.rb', line 36 def self.list(client, query, sort = '', order = 'desc') return bad_search("invalid sort - #{sort}") unless sort_valid?(sort) return bad_search("invalid order - #{order}") unless order_valid?(order) sort_order = sort_order_string(sort, order) client.request(:get, "search.json?query=#{query}#{sort_order}")['results'] end |
.order_valid?(order) ⇒ Boolean
Determines if a given order string is valid
77 78 79 80 |
# File 'lib/zendesk_support_api/search.rb', line 77 def self.order_valid?(order) valid = %w[asc desc] valid.include? order end |
.sort_order_string(sort, order) ⇒ String
Determines the sort and order to use in the query
109 110 111 112 113 |
# File 'lib/zendesk_support_api/search.rb', line 109 def self.sort_order_string(sort, order) sort = (sort.empty? ? '' : "&sort_by=#{sort}") order = (order == 'desc' ? '' : '&order_by=asc') "#{sort}#{order}" end |
.sort_valid?(sort) ⇒ Boolean
Determines if a given sort string is valid
57 58 59 60 61 62 |
# File 'lib/zendesk_support_api/search.rb', line 57 def self.sort_valid?(sort) return true if sort.empty? valid = %w[updated_at created_at priority status ticket_type] valid.include? sort end |