Class: Readiness::Zendesk::TicketFields
- Inherits:
-
Client
- Object
- Client
- Readiness::Zendesk::TicketFields
show all
- Defined in:
- lib/support_readiness/zendesk/ticket_fields.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.create!(client, field) ⇒ Object
-
.delete!(client, field) ⇒ Boolean
-
.find(client, fid) ⇒ Hash
Locates a ticket field within Zendesk.
-
.find!(client, fid) ⇒ Hash
Locates a ticket field within Zendesk.
-
.find_by_name(client, name, cache = nil) ⇒ Object
Locates a ticket field within Zendesk by name.
-
.find_by_name!(client, name) ⇒ Object
Locates a ticket field within Zendesk by name.
-
.list(client, limit = 0, sort = 'id') ⇒ Array
-
.update!(client, field) ⇒ Object
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(client, object = {}) ⇒ TicketFields
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 30
def initialize(client, object = {})
@active = object['active']
@agent_description = object['agent_description']
@collapsed_for_agents = object['collapsed_for_agents']
@custom_field_options = ticket_field_options(client, object)
@description = object['description']
@editable_in_portal = object['editable_in_portal']
@id = object['id']
@key = object['key']
@position = object['position']
@raw_title_in_portal = object['raw_title_in_portal']
@regexp_for_validation = object['regexp_for_validation']
@removable = object['removable']
@required = object['required']
@system_field_options = object['system_field_options']
@tag = object['tag']
@title = object['title']
@title_in_portal = object['title_in_portal']
@type = object['type']
@visible_in_portal = object['visible_in_portal']
end
|
Instance Attribute Details
#active ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def active
@active
end
|
#agent_description ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def agent_description
@agent_description
end
|
#collapsed_for_agents ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def collapsed_for_agents
@collapsed_for_agents
end
|
#custom_field_options ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def custom_field_options
@custom_field_options
end
|
#description ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def description
@description
end
|
#editable_in_portal ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def editable_in_portal
@editable_in_portal
end
|
#id ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def id
@id
end
|
#key ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def key
@key
end
|
#position ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def position
@position
end
|
#raw_title_in_portal ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def raw_title_in_portal
@raw_title_in_portal
end
|
#regexp_for_validation ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def regexp_for_validation
@regexp_for_validation
end
|
#removable ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def removable
@removable
end
|
#required ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def required
@required
end
|
#system_field_options ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def system_field_options
@system_field_options
end
|
#tag ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def tag
@tag
end
|
#title ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def title
@title
end
|
#title_in_portal ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def title_in_portal
@title_in_portal
end
|
#type ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def type
@type
end
|
#visible_in_portal ⇒ Object
13
14
15
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 13
def visible_in_portal
@visible_in_portal
end
|
Class Method Details
.create!(client, field) ⇒ Object
231
232
233
234
235
236
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 231
def self.create!(client, field)
field.custom_field_options = nil
response = client.connection.post 'ticket_fields', to_clean_json_with_key(field, 'ticket_field')
handle_request_error(1, 'Zendesk', response.status, { action: 'Create ticket field', message: Oj.load(response.body)}) unless response.status == 201
TicketFields.new(client, Oj.load(response.body)['ticket_field'])
end
|
.delete!(client, field) ⇒ Boolean
Deletes a ticket field. Will exit if unsuccessful
290
291
292
293
294
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 290
def self.delete!(client, field)
response = client.connection.delete "ticket_fields/#{field.id}"
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a ticket field', id: field.id, message: Oj.load(response.body)}) unless response.status == 204
true
end
|
.find(client, fid) ⇒ Hash
Locates a ticket field within Zendesk. This will not exit on error (except Authentication errors)
123
124
125
126
127
128
129
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 123
def self.find(client, fid)
response = client.connection.get("ticket_fields/#{fid}")
handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: fid }) unless response.status == 200
return TicketFields.new(client, Oj.load(response.body)['ticket_field']) if response.status == 200
Oj.load(response.body)
end
|
.find!(client, fid) ⇒ Hash
Locates a ticket field within Zendesk. This will exit on error
150
151
152
153
154
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 150
def self.find!(client, fid)
response = client.connection.get("ticket_fields/#{fid}")
handle_request_error(1, 'Zendesk', response.status, { action: 'Find ticket field', id: fid }) unless response.status == 200
TicketFields.new(client, Oj.load(response.body)['ticket_field'])
end
|
.find_by_name(client, name, cache = nil) ⇒ Object
Locates a ticket field within Zendesk by name. Can utilize a cacheh for quicker results
175
176
177
178
179
180
181
182
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 175
def self.find_by_name(client, name, cache = nil)
fields = if cache.nil?
TicketFields.list(client)
else
cache
end
fields.detect { |f| f.title == name }
end
|
.find_by_name!(client, name) ⇒ Object
Locates a ticket field within Zendesk by name. This will exit on error
202
203
204
205
206
207
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 202
def self.find_by_name!(client, name)
fields = TicketFields.list(client)
field = fields.detect { |f| f.title == name }
handle_request_error(1, 'Zendesk', 404, { action: 'Find ticket field', id: name }) if field.nil?
field
end
|
.list(client, limit = 0, sort = 'id') ⇒ Array
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 88
def self.list(client, limit = 0, sort = 'id')
array = []
opts = "page[size]=100"
loop do
response = client.connection.get("ticket_fields?#{opts}")
handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body['ticket_fields'].map { |f| TicketFields.new(client, f) }
break if limit != 0 && array.count >= (limit * 100)
break unless body['meta']['has_more']
opts = body['links'] ['next'].split('?').last
end
array
end
|
.update!(client, field) ⇒ Object
263
264
265
266
267
268
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 263
def self.update!(client, field)
field.custom_field_options = nil
response = client.connection.put "ticket_fields/#{field.id}", to_clean_json_with_key(field, 'ticket_field')
handle_request_error(1, 'Zendesk', response.status, { action: 'Update ticket field', message: Oj.load(response.body)}) unless response.status == 200
TicketFields.new(client, Oj.load(response.body)['ticket_field'])
end
|
Instance Method Details
#ticket_field_options(client, object) ⇒ Array
Gets the ticket field options for a ticket field
60
61
62
63
64
65
66
67
68
|
# File 'lib/support_readiness/zendesk/ticket_fields.rb', line 60
def ticket_field_options(client, object)
return nil unless %w[tagger multiselect].include? object['type']
object['custom_field_options'].each do |c|
c['position'] = object['custom_field_options'].index(c)
end
object['custom_field_options'].map { |c| TicketFieldOptions.new(c) }
end
|