Class: Readiness::Zendesk::OrganizationFields

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

Overview

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

Author:

  • Jason Colyer

Since:

  • 1.0.0

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

Examples:

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

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

#activeObject

Since:

  • 1.0.0



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

def active
  @active
end

#custom_field_optionsObject

Since:

  • 1.0.0



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

def custom_field_options
  @custom_field_options
end

#descriptionObject

Since:

  • 1.0.0



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

def description
  @description
end

#idObject

Since:

  • 1.0.0



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

def id
  @id
end

#keyObject

Since:

  • 1.0.0



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

def key
  @key
end

#positionObject

Since:

  • 1.0.0



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

def position
  @position
end

#regexp_for_validationObject

Since:

  • 1.0.0



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

def regexp_for_validation
  @regexp_for_validation
end

#titleObject

Since:

  • 1.0.0



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

def title
  @title
end

#typeObject

Since:

  • 1.0.0



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

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::OrganizationFields.new
field.type = 'text'
field.title = 'Support desc'
field.description = 'This field describes the support plan this organization has'
field.position = 0
field.active = true
field.key = 'support_description'
create = Readiness::Zendesk::OrganizationFields.create!(client, field)
pp create.id
# => 75

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

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

Parameters:

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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)

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::OrganizationFields.find(client, 8)
pp field.title
# => "Custom Field 1"

Parameters:

  • client (Object)

    An instance of Client

  • fid (Integer)

    The organization field ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

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::OrganizationFields.find!(client, 8)
pp field.title
# => "Custom Field 1"

Parameters:

  • client (Object)

    An instance of Client

  • fid (Integer)

    The organization field ID to find

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

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)
fields = Readiness::Zendesk::OrganizationFields.list(client)
pp fields.first.id
# => 7

Parameters:

  • client (Object)

    An instance of Client

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

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)
reorder = Readiness::Zendesk::OrganizationFields.reorder!(client, [4, 5, 2, 8])
pp reorder
# => true

Parameters:

  • client (Object)

    An instance of Client

  • fids (Array)

    An Array of field IDs (order is important)

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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

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::OrganizationFields.find!(client, 75)
field.title = 'Support description'
update = Readiness::Zendesk::OrganizationFields.update!(client, field)
pp update.title
# => "Support description"

Parameters:

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



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