Class: Readiness::Zendesk::Search
- Defined in:
- lib/support_readiness/zendesk/search.rb
Overview
Defines the class Search within the module Readiness::Zendesk.
Class Method Summary collapse
-
.group(client, query) ⇒ Array
A wrapper for #search that specifies to use type:group.
-
.object_from_type(type, result) ⇒ Object
Returns the type of Object to use depending on the type of query.
-
.organizations(client, query) ⇒ Array
A wrapper for #search that specifies to use type:organization.
-
.search(client, type, query) ⇒ Array
Perform a search and list the first 1000 results.
-
.tickets(client, query) ⇒ Array
A wrapper for #search that specifies to use type:ticket.
-
.users(client, query) ⇒ Array
A wrapper for #search that specifies to use type:user.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.group(client, query) ⇒ Array
A wrapper for #search that specifies to use type:group
102 103 104 |
# File 'lib/support_readiness/zendesk/search.rb', line 102 def self.group(client, query) search(client, 'group', query) end |
.object_from_type(type, result) ⇒ Object
Returns the type of Object to use depending on the type of query
149 150 151 152 153 154 155 156 |
# File 'lib/support_readiness/zendesk/search.rb', line 149 def self.object_from_type(type, result) return Tickets.new(result) if type == 'ticket' return Users.new(result) if type == 'user' return Organizations.new(result) if type == 'organization' return Groups.new(result) if type == 'group' nil end |
.organizations(client, query) ⇒ Array
A wrapper for #search that specifies to use type:organization
78 79 80 |
# File 'lib/support_readiness/zendesk/search.rb', line 78 def self.organizations(client, query) search(client, 'organization', query) end |
.search(client, type, query) ⇒ Array
Perform a search and list the first 1000 results
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/support_readiness/zendesk/search.rb', line 126 def self.search(client, type, query) array = [] page = 1 loop do response = client.connection.get "search?page=#{page}&query=type:#{type} #{ERB::Util.url_encode(query)}" handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['results'].map { |r| object_from_type(type, r) } break if array.count >= 1000 break if body['next_page'].nil? page += 1 end array end |
.tickets(client, query) ⇒ Array
A wrapper for #search that specifies to use type:ticket
32 33 34 |
# File 'lib/support_readiness/zendesk/search.rb', line 32 def self.tickets(client, query) search(client, 'ticket', query) end |
.users(client, query) ⇒ Array
A wrapper for #search that specifies to use type:user
55 56 57 |
# File 'lib/support_readiness/zendesk/search.rb', line 55 def self.users(client, query) search(client, 'user', query) end |