class Readiness::Zendesk::OrganizationFields

@since 1.0.0
@author Jason Colyer
Defines the class OrganizationFields within the module {Readiness::Zendesk}.
#

def self.create!(client, field)

Other tags:
    See: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#create-organization-field - Zendesk API > Organization Fields > Create Organization Field

Returns:
  • (Object) - An instance of {Readiness::Zendesk::OrganizationFields}

Parameters:
  • field (Object) -- An instance of {Readiness::Zendesk::OrganizationFields}
  • client (Object) -- An instance of {Readiness::Zendesk::Client}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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

def self.delete!(client, field)

Other tags:
    See: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#delete-organization-field - Zendesk API > Organization Fields > Delete Organization Field

Returns:
  • (Boolean) -

Parameters:
  • field (Object) -- An instance of {Readiness::Zendesk::OrganizationFields}
  • client (Object) -- An instance of {Readiness::Zendesk::Client}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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

def self.find(client, fid)

Other tags:
    See: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#show-organization-field - > Organization Fields > Show Organization Field

Returns:
  • (Hash) -

Parameters:
  • fid (Integer) -- The organization field ID to find
  • client (Object) -- An instance of {Readiness::Zendesk::Client}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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

def self.find!(client, fid)

Other tags:
    See: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#show-organization-field - > Organization Fields > Show Organization Field

Returns:
  • (Object) - An instance of {Readiness::Zendesk::OrganizationFields}

Parameters:
  • fid (Integer) -- The organization field ID to find
  • client (Object) -- An instance of {Readiness::Zendesk::Client}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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

def self.list(client, limit = 0, sort = 'id')

Other tags:
    See: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#list-organization-fields - Zendesk API > Organization Fields > List Organization Fields

Returns:
  • (Array) -

Parameters:
  • client (Object) -- An instance of {Readiness::Zendesk::Client}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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

def self.reorder!(client, fids)

Other tags:
    See: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#reorder-organization-field - Zendesk API > Organization Fields > Reorder Organization Field

Returns:
  • (Boolean) -

Parameters:
  • fids (Array) -- An Array of field IDs (order is important)
  • client (Object) -- An instance of {Readiness::Zendesk::Client}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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

def self.update!(client, field)

Other tags:
    See: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#update-organization-field - Zendesk API > Organization Fields > Update Organization Field

Returns:
  • (Object) - An instance of {Readiness::Zendesk::OrganizationFields}

Parameters:
  • field (Object) -- An instance of {Readiness::Zendesk::OrganizationFields}
  • client (Object) -- An instance of {Readiness::Zendesk::Client}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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

def initialize(object = {})

Parameters:
  • object (Object) -- An instance of {Readiness::Zendesk::OrganizationFields}

Other tags:
    Since: - 1.0.0

Other tags:
    Author: - Jason Colyer
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