Class: Readiness::Zendesk::UserFields
- Defined in:
- lib/support_readiness/zendesk/user_fields.rb
Overview
Defines the class UserFields within the module Readiness::Zendesk.
Instance Attribute Summary collapse
- #active ⇒ Object
- #custom_field_options ⇒ Object
- #description ⇒ Object
- #id ⇒ Object
- #key ⇒ Object
- #position ⇒ Object
- #regexp_for_validation ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
Class Method Summary collapse
-
.create!(client, field) ⇒ Object
Creates an user field.
-
.delete!(client, field) ⇒ Boolean
Deletes an user field.
-
.find(client, fid) ⇒ Object
Locates an user field within Zendesk.
-
.find!(client, fid) ⇒ Object
Locates an user field within Zendesk.
-
.list(client) ⇒ Array
Lists user fields.
-
.reorder!(client, fids) ⇒ Boolean
Reorders user fields.
-
.update!(client, field) ⇒ Object
Updates an user field.
Instance Method Summary collapse
-
#initialize(client, object = {}) ⇒ UserFields
constructor
Creates a new UserFields instance.
-
#user_field_options(client, object) ⇒ Array
Gets the user field options for a user field.
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(client, object = {}) ⇒ UserFields
Creates a new Readiness::Zendesk::UserFields instance
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 30 def initialize(client, object = {}) @active = object['active'] @custom_field_options = (client, object) @id = object['id'] @description = object['description'] @key = object['key'] @position = object['position'] @regexp_for_validation = object['regexp_for_validation'] @title = object['title'] @type = object['type'] end |
Instance Attribute Details
#active ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def active @active end |
#custom_field_options ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def @custom_field_options end |
#description ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def description @description end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def id @id end |
#key ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def key @key end |
#position ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def position @position end |
#regexp_for_validation ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def regexp_for_validation @regexp_for_validation end |
#title ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def title @title end |
#type ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 13 def type @type end |
Class Method Details
.create!(client, field) ⇒ Object
Creates an user field. Will exit if unsuccessful
172 173 174 175 176 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 172 def self.create!(client, field) response = client.connection.post 'user_fields', to_clean_json_with_key(field, 'user_field') handle_request_error(1, 'Zendesk', response.status, { action: 'Create user field', message: Oj.load(response.body)}) unless response.status == 201 UserFields.new(client, Oj.load(response.body)['user_field']) end |
.delete!(client, field) ⇒ Boolean
Deletes an user field. Will exit if unsuccessful
225 226 227 228 229 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 225 def self.delete!(client, field) response = client.connection.delete "user_fields/#{field.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete user field', id: field.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.find(client, fid) ⇒ Object
Locates an user field within Zendesk. This will not exit on error (except Authentication errors)
113 114 115 116 117 118 119 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 113 def self.find(client, fid) response = client.connection.get "user_fields/#{fid}" handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: fid }) unless response.status == 200 return UserFields.new(client, Oj.load(response.body)['user_field']) if response.status == 200 Oj.load(response.body) end |
.find!(client, fid) ⇒ Object
Locates an user field within Zendesk. This will exit on error
140 141 142 143 144 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 140 def self.find!(client, fid) response = client.connection.get "user_fields/#{fid}" handle_request_error(1, 'Zendesk', response.status, { action: 'Find user field', id: fid }) unless response.status == 200 UserFields.new(client, Oj.load(response.body)['user_field']) end |
.list(client) ⇒ Array
Lists user fields
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 78 def self.list(client) array = [] opts = "page[size]=100" loop do response = client.connection.get("user_fields?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['user_fields'].map { |t| UserFields.new(client, t) } break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.reorder!(client, fids) ⇒ Boolean
Reorders user fields. Will exit if unsuccessful
250 251 252 253 254 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 250 def self.reorder!(client, fids) response = client.connection.put 'user_fields/reorder', { user_field_ids: fids }.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Reorder user fields', id: fids, message: Oj.load(response.body)}) unless response.status == 200 true end |
.update!(client, field) ⇒ Object
Updates an user field. Will exit if unsuccessful
199 200 201 202 203 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 199 def self.update!(client, field) response = client.connection.put "user_fields/#{field.id}", to_clean_json_with_key(field, 'user_field') handle_request_error(1, 'Zendesk', response.status, { action: 'Update user field', message: Oj.load(response.body)}) unless response.status == 200 UserFields.new(client, Oj.load(response.body)['user_field']) end |
Instance Method Details
#user_field_options(client, object) ⇒ Array
Gets the user field options for a user field
50 51 52 53 54 55 56 57 58 |
# File 'lib/support_readiness/zendesk/user_fields.rb', line 50 def (client, object) return nil unless %w[dropdown].include? object['type'] # Handles when the position value is nil object['custom_field_options'].each do |c| c['position'] = object['custom_field_options'].index(c) end object['custom_field_options'].map { |c| UserFieldOptions.new(c) } end |