Class: Readiness::Zendesk::TicketFieldOptions

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

Overview

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

Author:

  • Jason Colyer

Since:

  • 1.0.12

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 = {}) ⇒ TicketFieldOptions

Examples:

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

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.12



24
25
26
27
28
29
30
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 24

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

Instance Attribute Details

#idObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13

def id
  @id
end

#nameObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13

def name
  @name
end

#positionObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13

def position
  @position
end

#raw_nameObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13

def raw_name
  @raw_name
end

#valueObject

Since:

  • 1.0.12



13
14
15
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13

def value
  @value
end

Class Method Details

.create_or_update!(client, field, option) ⇒ Object

Creates or updates a ticket field option. This will exit on error.

Parameters:

Returns:

  • (Object)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



76
77
78
79
80
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 76

def self.create_or_update!(client, field, option)
  response = client.connection.post "ticket_fields/#{field.id}/options", to_clean_json_with_key(option, 'custom_field_option')
  handle_request_error(1, 'Zendesk', response.status, { action: 'Create/update ticket field option', message: Oj.load(response.body)}) unless [200, 201].include?(response.status)
  TicketFieldOptions.new(Oj.load(response.body)['custom_field_option'])
end

.delete!(client, field, option) ⇒ Boolean

Deletes a ticket field option. Will exit if unsuccessful

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)
field = Readiness::Zendesk::TicketFields.find!(client, 75)
option = field.custom_field_options.last
delete = Readiness::Zendesk::TicketFieldOptions.delete!(client, field, option)
pp delete
# => true

Parameters:

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



104
105
106
107
108
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 104

def self.delete!(client, field, option)
  response = client.connection.delete "ticket_fields/#{field.id}/options/#{option.id}"
  handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a ticket field option', id: "ticket_fields/#{field.id}/options/#{option.id}", message: Oj.load(response.body)}) unless response.status == 204
  true
end

.list(client, fid) ⇒ Array

Lists all ticket fields.

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)
options = Readiness::Zendesk::TicketFieldOptions.list(client, 123)
pp fields.count
# => 5

Parameters:

  • client (Object)

    An instance of Client

  • fid (Integer)

    The field ID to get the field options for

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.12



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

def self.list(client, fid)
  array = []
  page = 1
  loop do
    response = client.connection.get("ticket_fields/#{fid}/options?page=#{page}")
    handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body['custom_field_options'].map { |f| TicketFieldOptions.new(f) }
    break unless body['custom_field_options'].count == 100

    page += 1
  end
  array
end