Class: Readiness::Zendesk::Search

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/zendesk/search.rb

Overview

Defines the class Search within the module Readiness::Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Class Method Summary collapse

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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
search = Readiness::Zendesk::Search.organzations(client, 'Support')
pp search.first.name
# => "Support AMER"

Parameters:

  • client (Object)

    An instance of Client

  • query (String)

    The query String to use

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Parameters:

  • type (String)

    The type of search to perform

  • result (Hash)

    The search result item

Returns:

  • (Object)

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
search = Readiness::Zendesk::Search.organizations(client, 'salesforce_id:ABCDEFGH0123456*')
pp search.first.notes
# => "This org is escalated. Please talk to support managers."

Parameters:

  • client (Object)

    An instance of Client

  • query (String)

    The query String to use

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
search = Readiness::Zendesk::Search.search(client, 'organization', 'salesforce_id:ABCDEFGH0123456*')
pp search.first.notes
# => "This org is escalated. Please talk to support managers."

Parameters:

  • client (Object)

    An instance of Client

  • type (String)

    The type of search to perform

  • query (String)

    The query String to use

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
search = Readiness::Zendesk::Search.tickets(client, 'custom_field_360018253094:americas__usa tags:ultimate satisfaction:badwithcomment')
pp search.first.id
# => 125834

Parameters:

  • client (Object)

    An instance of Client

  • query (String)

    The query String to use

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

Examples:

require 'support_readiness'
config = Readiness::Zendesk::Configuration.new
config.username = 'alice@example.com'
config.token = 'test123abc'
config.url = 'https://example.zendesk.com/api/v2'
client = Readiness::Zendesk::Client.new(config)
search = Readiness::Zendesk::Search.users(client, 'email:alice@example.com')
pp search.first.name
# => "Alice Example"

Parameters:

  • client (Object)

    An instance of Client

  • query (String)

    The query String to use

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



55
56
57
# File 'lib/support_readiness/zendesk/search.rb', line 55

def self.users(client, query)
  search(client, 'user', query)
end