Class: Readiness::Zendesk::OrganizationFields
- Defined in:
- lib/support_readiness/zendesk/organization_fields.rb
Overview
Defines the class OrganizationFields 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 organization field.
-
.delete!(client, field) ⇒ Boolean
Deletes an organization field.
-
.find(client, fid) ⇒ Hash
Locates an organization field within Zendesk.
-
.find!(client, fid) ⇒ Object
Locates an organization field within Zendesk.
-
.list(client, limit = 0, sort = 'id') ⇒ Array
Lists all organization fields.
-
.reorder!(client, fids) ⇒ Boolean
Reorders organization fields.
-
.update!(client, field) ⇒ Object
Updates an organization field.
Instance Method Summary collapse
-
#initialize(object = {}) ⇒ OrganizationFields
constructor
Creates a new OrganizationFields 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 = {}) ⇒ OrganizationFields
Creates a new Readiness::Zendesk::OrganizationFields instance
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 24 def initialize(object = {}) @active = object['active'] @custom_field_options = object['custom_field_options'] @description = object['description'] @id = object['id'] @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/organization_fields.rb', line 13 def active @active end |
#custom_field_options ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def @custom_field_options end |
#description ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def description @description end |
#id ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def id @id end |
#key ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def key @key end |
#position ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def position @position end |
#regexp_for_validation ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def regexp_for_validation @regexp_for_validation end |
#title ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def title @title end |
#type ⇒ Object
13 14 15 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 13 def type @type end |
Class Method Details
.create!(client, field) ⇒ Object
Creates an organization field. Will exit if unsuccessful
148 149 150 151 152 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 148 def self.create!(client, field) response = client.connection.post 'organization_fields', to_clean_json_with_key(field, 'organization_field') handle_request_error(1, 'Zendesk', response.status, { action: 'Create organization field', message: Oj.load(response.body)}) unless response.status == 201 OrganizationFields.new(Oj.load(response.body)['organization_field']) end |
.delete!(client, field) ⇒ Boolean
Deletes an organization field. Will exit if unsuccessful
201 202 203 204 205 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 201 def self.delete!(client, field) response = client.connection.delete "organization_fields/#{field.id}" handle_request_error(1, 'Zendesk', response.status, { action: 'Delete an organization field', id: field.id, message: Oj.load(response.body)}) unless response.status == 204 true end |
.find(client, fid) ⇒ Hash
Locates an organization field within Zendesk. This will not exit on error (except Authentication errors)
89 90 91 92 93 94 95 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 89 def self.find(client, fid) response = client.connection.get("organization_fields/#{fid}") handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: fid }) unless response.status == 200 return OrganizationFields.new(Oj.load(response.body)['organization_field']) if response.status == 200 Oj.load(response.body) end |
.find!(client, fid) ⇒ Object
Locates an organization field within Zendesk. This will exit on error
116 117 118 119 120 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 116 def self.find!(client, fid) response = client.connection.get("organization_fields/#{fid}") handle_request_error(1, 'Zendesk', response.status, { action: 'Find organization field', id: fid }) unless response.status == 200 OrganizationFields.new(Oj.load(response.body)['organization_field']) end |
.list(client, limit = 0, sort = 'id') ⇒ Array
Lists all organization fields
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 54 def self.list(client, limit = 0, sort = 'id') array = [] opts = "page[size]=100" loop do response = client.connection.get("organization_fields?#{opts}") handle_request_error(0, 'Zendesk', response.status) unless response.status == 200 body = Oj.load(response.body) array += body['organization_fields'].map { |f| OrganizationFields.new(f) } break if limit != 0 && array.count >= (limit * 100) break unless body['meta']['has_more'] opts = body['links'] ['next'].split('?').last end array end |
.reorder!(client, fids) ⇒ Boolean
Reorders organization fields. Will exit if unsuccessful
226 227 228 229 230 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 226 def self.reorder!(client, fids) response = client.connection.put 'organization_fields/reorder', { organization_field_ids: fids }.to_json handle_request_error(1, 'Zendesk', response.status, { action: 'Reorder organization fields', id: fids, message: Oj.load(response.body)}) unless response.status == 200 true end |
.update!(client, field) ⇒ Object
Updates an organization field. Will exit if unsuccessful
175 176 177 178 179 |
# File 'lib/support_readiness/zendesk/organization_fields.rb', line 175 def self.update!(client, field) response = client.connection.put "organization_fields/#{field.id}", to_clean_json_with_key(field, 'organization_field') handle_request_error(1, 'Zendesk', response.status, { action: 'Update organization field', message: Oj.load(response.body)}) unless response.status == 200 OrganizationFields.new(Oj.load(response.body)['organization_field']) end |