Class: Readiness::Zendesk::UserFieldOptions
- Defined in:
- lib/support_readiness/zendesk/user_field_options.rb
Overview
Defines the class UserFieldOptions within the module Readiness::Zendesk.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.create_or_update!(client, field, option) ⇒ Object
Creates or updates an user field option.
-
.delete!(client, field, option) ⇒ Boolean
Deletes aan user field option.
-
.list(client, fid) ⇒ Array
Lists all user fields options for a specific user field.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ UserFieldOptions
constructor
Creates a new UserFieldOptions 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 = {}) ⇒ UserFieldOptions
Creates a new Readiness::Zendesk::UserFieldOptions instance
24 25 26 27 28 29 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 24 def initialize(object = {}) @id = object['id'] @name = object['name'] @position = object['position'] @value = object['value'] end |
Instance Attribute Details
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 13 def id @id end |
#name ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 13 def name @name end |
#position ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 13 def position @position end |
#value ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 13 def value @value end |
Class Method Details
.create_or_update!(client, field, option) ⇒ Object
Creates or updates an user field option. This will exit on error.
75 76 77 78 79 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 75 def self.create_or_update!(client, field, option) response = client.connection.post "user_fields/#{field.id}/options", to_clean_json_with_key(option, 'custom_field_option') handle_request_error(1, 'Zendesk', response.status, { action: 'Create/update user field option', message: Oj.load(response.body)}) unless [200, 201].include?(response.status) UserFieldOptions.new(Oj.load(response.body)['custom_field_option']) end |
.delete!(client, field, option) ⇒ Boolean
Deletes aan user field option. Will exit if unsuccessful
103 104 105 106 107 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 103 def self.delete!(client, field, option) response = client.connection.delete "user_fields/#{field.id}/options/#{option.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a user field option', id: "user_fields/#{field.id}/options/#{option.id}", message: Oj.load(response.body)}) unless response.status == 204 true end |
.list(client, fid) ⇒ Array
Lists all user fields options for a specific user field.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/support_readiness/zendesk/user_field_options.rb', line 50 def self.list(client, fid) array = [] page = 1 loop do response = client.connection.get("user_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| UserFieldOptions.new(f) } break unless body['custom_field_options'].count == 100 page += 1 end array end |