Class: Readiness::Zendesk::TriggerCategories

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

Overview

TODO:

Find methods

TODO:

Create method

TODO:

Update method

TODO:

Delete method

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

Author:

  • Jason Colyer

Since:

  • 1.0.92

Instance Attribute Summary collapse

Class Method Summary collapse

Instance 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

Constructor Details

#initialize(object = {}) ⇒ TriggerCategories

Creates a new Readiness::Zendesk::TriggerCategories instance

Examples:

require 'support_readiness'
Readiness::Zendesk::TriggerCategories.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.92



28
29
30
31
32
# File 'lib/support_readiness/zendesk/trigger_categories.rb', line 28

def initialize(object = {})
  @id = object['id']
  @name = object['name']
  @position = object['position']
end

Instance Attribute Details

#idObject

Since:

  • 1.0.92



17
18
19
# File 'lib/support_readiness/zendesk/trigger_categories.rb', line 17

def id
  @id
end

#nameObject

Since:

  • 1.0.92



17
18
19
# File 'lib/support_readiness/zendesk/trigger_categories.rb', line 17

def name
  @name
end

#positionObject

Since:

  • 1.0.92



17
18
19
# File 'lib/support_readiness/zendesk/trigger_categories.rb', line 17

def position
  @position
end

Class Method Details

.find_by_name(client, name, cache = nil) ⇒ Object

Locates a trigger category within Zendesk by name. Can utilize a cacheh for quicker 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)
category = Readiness::Zendesk::TriggerCategories.find_by_name!(client, 'Notification App')
pp category.id
# => 10092446182300
list = Readiness::Zendesk::TriggerCategories.list(client)
category = Readiness::Zendesk::TriggerCategories.find_by_name!(client, 'Notification App', list)
pp category.id
# => 10092446182300

Parameters:

  • client (Object)

    An instance of Client

  • name (String)

    The trigger category name to look for

  • cache (Array) (defaults to: nil)

    The results of #list

Returns:

Author:

  • Jason Colyer

Since:

  • 1.0.92



90
91
92
93
94
95
96
97
# File 'lib/support_readiness/zendesk/trigger_categories.rb', line 90

def self.find_by_name(client, name, cache = nil)
  categories = if cache.nil?
                 TriggerCategories.list(client)
               else
                 cache
               end
  categories.detect { |c| c.name == name }
end

.list(client) ⇒ Array

Lists trigger categories

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)
categories = Readiness::Zendesk::TriggerCategories.list(client)
pp categories.first.id
# => 10001

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.92



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/support_readiness/zendesk/trigger_categories.rb', line 52

def self.list(client)
  array = []
  opts = "page[size]=100"
  loop do
    response = client.connection.get("trigger_categories?#{opts}")
    handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body['trigger_categories'].map { |t| TriggerCategories.new(t) }
    break unless body['meta']['has_more']

    opts = body['links']['next'].split('?').last
  end
  array
end