Class: Readiness::Zendesk::TicketFieldOptions
- Defined in:
- lib/support_readiness/zendesk/ticket_field_options.rb
Overview
Defines the class TicketFieldOptions within the module Readiness::Zendesk.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.create_or_update!(client, field, option) ⇒ Object
Creates or updates a ticket field option.
-
.delete!(client, field, option) ⇒ Boolean
Deletes a ticket field option.
-
.list(client, fid) ⇒ Array
Lists all ticket fields.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ TicketFieldOptions
constructor
Creates a new TicketFieldOptions instance.
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
Creates a new Readiness::Zendesk::TicketFieldOptions instance
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
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13 def id @id end |
#name ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13 def name @name end |
#position ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13 def position @position end |
#raw_name ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/ticket_field_options.rb', line 13 def raw_name @raw_name end |
#value ⇒ Object
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.
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
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.
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 |