gitlab-customer-support-operations_zendesk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/support_ops_zendesk/packages.rb +89 -0
- data/lib/support_ops_zendesk/zendesk/app_installations.rb +62 -0
- data/lib/support_ops_zendesk/zendesk/app_job_statuses.rb +157 -0
- data/lib/support_ops_zendesk/zendesk/apps.rb +476 -0
- data/lib/support_ops_zendesk/zendesk/articles.rb +362 -0
- data/lib/support_ops_zendesk/zendesk/audit_logs.rb +166 -0
- data/lib/support_ops_zendesk/zendesk/automations.rb +390 -0
- data/lib/support_ops_zendesk/zendesk/base.rb +472 -0
- data/lib/support_ops_zendesk/zendesk/brands.rb +172 -0
- data/lib/support_ops_zendesk/zendesk/client.rb +91 -0
- data/lib/support_ops_zendesk/zendesk/comments.rb +37 -0
- data/lib/support_ops_zendesk/zendesk/configuration.rb +138 -0
- data/lib/support_ops_zendesk/zendesk/custom_roles.rb +224 -0
- data/lib/support_ops_zendesk/zendesk/dynamic_content.rb +297 -0
- data/lib/support_ops_zendesk/zendesk/dynamic_content_variants.rb +309 -0
- data/lib/support_ops_zendesk/zendesk/group_memberships.rb +337 -0
- data/lib/support_ops_zendesk/zendesk/groups.rb +385 -0
- data/lib/support_ops_zendesk/zendesk/help_center_categories.rb +332 -0
- data/lib/support_ops_zendesk/zendesk/help_center_content_tags.rb +237 -0
- data/lib/support_ops_zendesk/zendesk/help_center_management_permission_groups.rb +271 -0
- data/lib/support_ops_zendesk/zendesk/help_center_sections.rb +378 -0
- data/lib/support_ops_zendesk/zendesk/help_center_topics.rb +274 -0
- data/lib/support_ops_zendesk/zendesk/help_center_user_segments.rb +279 -0
- data/lib/support_ops_zendesk/zendesk/job_statuses.rb +231 -0
- data/lib/support_ops_zendesk/zendesk/locales.rb +326 -0
- data/lib/support_ops_zendesk/zendesk/macros.rb +407 -0
- data/lib/support_ops_zendesk/zendesk/oauth_clients.rb +186 -0
- data/lib/support_ops_zendesk/zendesk/oauth_tokens.rb +114 -0
- data/lib/support_ops_zendesk/zendesk/organization_fields.rb +282 -0
- data/lib/support_ops_zendesk/zendesk/organization_memberships.rb +336 -0
- data/lib/support_ops_zendesk/zendesk/organizations.rb +568 -0
- data/lib/support_ops_zendesk/zendesk/requester_roles.rb +58 -0
- data/lib/support_ops_zendesk/zendesk/satisfaction_reasons.rb +161 -0
- data/lib/support_ops_zendesk/zendesk/schedule_holidays.rb +27 -0
- data/lib/support_ops_zendesk/zendesk/schedules.rb +192 -0
- data/lib/support_ops_zendesk/zendesk/search.rb +185 -0
- data/lib/support_ops_zendesk/zendesk/sla_policies.rb +302 -0
- data/lib/support_ops_zendesk/zendesk/targets.rb +96 -0
- data/lib/support_ops_zendesk/zendesk/theme_job_statuses.rb +154 -0
- data/lib/support_ops_zendesk/zendesk/themes.rb +328 -0
- data/lib/support_ops_zendesk/zendesk/ticket_field_options.rb +154 -0
- data/lib/support_ops_zendesk/zendesk/ticket_fields.rb +357 -0
- data/lib/support_ops_zendesk/zendesk/ticket_forms.rb +370 -0
- data/lib/support_ops_zendesk/zendesk/ticket_user_types.rb +67 -0
- data/lib/support_ops_zendesk/zendesk/tickets.rb +837 -0
- data/lib/support_ops_zendesk/zendesk/translations.rb +310 -0
- data/lib/support_ops_zendesk/zendesk/trigger_categories.rb +275 -0
- data/lib/support_ops_zendesk/zendesk/triggers.rb +427 -0
- data/lib/support_ops_zendesk/zendesk/user_field_options.rb +153 -0
- data/lib/support_ops_zendesk/zendesk/user_fields.rb +312 -0
- data/lib/support_ops_zendesk/zendesk/users.rb +889 -0
- data/lib/support_ops_zendesk/zendesk/via_types.rb +137 -0
- data/lib/support_ops_zendesk/zendesk/views.rb +636 -0
- data/lib/support_ops_zendesk/zendesk/webhooks.rb +206 -0
- data/lib/support_ops_zendesk/zendesk.rb +66 -0
- data/lib/support_ops_zendesk.rb +29 -0
- metadata +274 -0
@@ -0,0 +1,328 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module SupportOps.
|
4
|
+
module SupportOps
|
5
|
+
# Defines the module Zendesk
|
6
|
+
module Zendesk
|
7
|
+
##
|
8
|
+
# Defines the class Themes within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] author The author of the theme. Specified in the theme manifest
|
13
|
+
# @attr [Integer] brand_id The brand id of the theme
|
14
|
+
# @attr [String] created_at The time at which the theme was created
|
15
|
+
# @attr [String] id Automatically assigned when the theme is created
|
16
|
+
# @attr [Boolean] live Whether or not the theme is currently published in Help Center
|
17
|
+
# @attr [String] name The name of the theme
|
18
|
+
# @attr [String] updated_at The time at which the theme was last updated
|
19
|
+
# @attr [String] version The version number of the theme. Specified in the theme manifest
|
20
|
+
# @attr [String] zipfile The zipfile to use for creates and updates
|
21
|
+
# @todo Publish Theme > https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#publish-theme
|
22
|
+
class Themes < SupportOps::Zendesk::Base
|
23
|
+
# @!parse
|
24
|
+
# # Creates/updates a theme
|
25
|
+
# #
|
26
|
+
# # @author Jason Colyer
|
27
|
+
# # @since 1.0.0
|
28
|
+
# # @see SupportOps::Zendesk::Configuration Setting up a client
|
29
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::Themes}
|
30
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#save!}
|
31
|
+
# # @example
|
32
|
+
# # require 'support_ops_zendesk'
|
33
|
+
# #
|
34
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
35
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
36
|
+
# # config.username = 'jason@example.com'
|
37
|
+
# # config.token = 'abc123'
|
38
|
+
# # config.connection_type = 'upload'
|
39
|
+
# # end
|
40
|
+
# #
|
41
|
+
# # new_theme = SupportOps::Zendesk::Themes.new
|
42
|
+
# # new_theme.brand_id = 123
|
43
|
+
# # new_theme.name = 'New theme'
|
44
|
+
# # new_theme.zipfile = SupportOps::Zendesk::Themes.package!('data/new_theme')
|
45
|
+
# #
|
46
|
+
# # new_theme.save!
|
47
|
+
# #
|
48
|
+
# # pp new_theme.id
|
49
|
+
# # # => "28a0b408-626a-4bea-88ab-2d48a8078870"
|
50
|
+
# # @example
|
51
|
+
# # require 'support_ops_zendesk'
|
52
|
+
# #
|
53
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
54
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
55
|
+
# # config.username = 'jason@example.com'
|
56
|
+
# # config.token = 'abc123'
|
57
|
+
# # config.connection_type = 'upload'
|
58
|
+
# # end
|
59
|
+
# #
|
60
|
+
# # existing_theme = SupportOps::Zendesk::Themes.get!('28a0b408-626a-4bea-88ab-2d48a8078870')
|
61
|
+
# # existing_theme.zipfile = SupportOps::Zendesk::Themes.package!('data/modified_theme')
|
62
|
+
# #
|
63
|
+
# # new_theme.save!
|
64
|
+
# #
|
65
|
+
# # pp new_theme.id
|
66
|
+
# # # => "28a0b408-626a-4bea-88ab-2d48a8078870"
|
67
|
+
# def save!; end
|
68
|
+
# @!parse
|
69
|
+
# # Deletes a theme
|
70
|
+
# #
|
71
|
+
# # @author Jason Colyer
|
72
|
+
# # @since 1.0.0
|
73
|
+
# # @return [Boolean]
|
74
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
75
|
+
# # @see
|
76
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#delete-theme
|
77
|
+
# # Zendesk API > Themes > Delete Theme
|
78
|
+
# # @example
|
79
|
+
# # require 'support_ops_zendesk'
|
80
|
+
# #
|
81
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
82
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
83
|
+
# # config.username = 'jason@example.com'
|
84
|
+
# # config.token = 'abc123'
|
85
|
+
# # end
|
86
|
+
# #
|
87
|
+
# # existing_theme = SupportOps::Zendesk::Themes.get!('9f3c1c11-32bf-480b-9358-13bbc55d1bfe')
|
88
|
+
# # existing_theme.delete!
|
89
|
+
# def delete!; end
|
90
|
+
define_attributes :author, :brand_id, :created_at, :id, :live, :name,
|
91
|
+
:updated_at, :version, :zipfile
|
92
|
+
readonly_attributes :author, :brand_id, :created_at, :id, :live, :name,
|
93
|
+
:updated_at, :version, :zipfile
|
94
|
+
|
95
|
+
##
|
96
|
+
# Lists themes in the Zendesk system
|
97
|
+
#
|
98
|
+
# @author Jason Colyer
|
99
|
+
# @since 1.0.0
|
100
|
+
# @return [Array]
|
101
|
+
# @see
|
102
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#list-themes
|
103
|
+
# Zendesk API > Themes > List Themes
|
104
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
105
|
+
# @example
|
106
|
+
# require 'support_ops_zendesk'
|
107
|
+
#
|
108
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
109
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
110
|
+
# config.username = 'jason@example.com'
|
111
|
+
# config.token = 'abc123'
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# targets = SupportOps::Zendesk::Targets.list
|
115
|
+
# pp targets.count
|
116
|
+
# # => 3
|
117
|
+
def self.list
|
118
|
+
response = client.connection.get('guide/theming/themes')
|
119
|
+
body = Oj.load(response.body)
|
120
|
+
body['themes'].map { |t| Themes.new(t) }
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Locates a theme within Zendesk by name. Can utilize a cache for quicker results
|
125
|
+
#
|
126
|
+
# @author Jason Colyer
|
127
|
+
# @since 1.0.0
|
128
|
+
# @overload find_by_name(key: value)
|
129
|
+
# @param name [String required] The name to search for
|
130
|
+
# @param cache [Array] An Array of SupportOps::Zendesk::Themes to use as a cache
|
131
|
+
# @return [Object] An instance of {SupportOps::Zendesk::Themes}
|
132
|
+
# @example
|
133
|
+
# require 'support_ops_zendesk'
|
134
|
+
#
|
135
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
136
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
137
|
+
# config.username = 'jason@example.com'
|
138
|
+
# config.token = 'abc123'
|
139
|
+
# end
|
140
|
+
#
|
141
|
+
# themes = SupportOps::Zendesk::Themes.list
|
142
|
+
# theme = SupportOps::Zendesk::Themes.find_by_name(name: 'Backup', cache: themes)
|
143
|
+
# pp theme.name
|
144
|
+
# # => "Backup"
|
145
|
+
# pp theme.id
|
146
|
+
# # => "9f3c1c11-32bf-480b-9358-13bbc55d1bfe"
|
147
|
+
def self.find_by_name(**args)
|
148
|
+
raise 'You have to provide a name' unless args[:name]
|
149
|
+
if args[:cache]
|
150
|
+
raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
|
151
|
+
themes = args[:cache]
|
152
|
+
else
|
153
|
+
themes = list
|
154
|
+
end
|
155
|
+
themes.detect { |c| c.name.downcase == args[:name].to_s.downcase }
|
156
|
+
end
|
157
|
+
|
158
|
+
##
|
159
|
+
# Locates the live theme within Zendesk
|
160
|
+
#
|
161
|
+
# @author Jason Colyer
|
162
|
+
# @since 1.0.0
|
163
|
+
# @return [Object] An instance of {SupportOps::Zendesk::Themes}
|
164
|
+
# @example
|
165
|
+
# require 'support_ops_zendesk'
|
166
|
+
#
|
167
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
168
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
169
|
+
# config.username = 'jason@example.com'
|
170
|
+
# config.token = 'abc123'
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
# themes = SupportOps::Zendesk::Themes.list
|
174
|
+
# theme = SupportOps::Zendesk::Themes.find_by_name(name: 'Backup', cache: themes)
|
175
|
+
# pp theme.name
|
176
|
+
# # => "Backup"
|
177
|
+
# pp theme.id
|
178
|
+
# # => "9f3c1c11-32bf-480b-9358-13bbc55d1bfe"
|
179
|
+
def self.live
|
180
|
+
themes = list
|
181
|
+
themes.detect { |t| t.live }
|
182
|
+
end
|
183
|
+
|
184
|
+
##
|
185
|
+
# Locates a specific theme in the Zendesk system
|
186
|
+
#
|
187
|
+
# @author Jason Colyer
|
188
|
+
# @since 1.0.0
|
189
|
+
# @see
|
190
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#show-theme
|
191
|
+
# Zendesk API > Themes > Show Theme
|
192
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
193
|
+
# @example
|
194
|
+
# require 'support_ops_zendesk'
|
195
|
+
#
|
196
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
197
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
198
|
+
# config.username = 'jason@example.com'
|
199
|
+
# config.token = 'abc123'
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# theme = SupportOps::Zendesk::Themes.get('9f3c1c11-32bf-480b-9358-13bbc55d1bfe')
|
203
|
+
# pp theme.live
|
204
|
+
# # => false
|
205
|
+
def self.get(object)
|
206
|
+
if object.is_a? Themes
|
207
|
+
Themes.new(id: id).find
|
208
|
+
else
|
209
|
+
Themes.new(id: object).find
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# Locates a specific theme in the Zendesk system
|
215
|
+
#
|
216
|
+
# @author Jason Colyer
|
217
|
+
# @since 1.0.0
|
218
|
+
# @see
|
219
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#show-theme
|
220
|
+
# Zendesk API > Themes > Show Theme
|
221
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
222
|
+
# @example
|
223
|
+
# require 'support_ops_zendesk'
|
224
|
+
#
|
225
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
226
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
227
|
+
# config.username = 'jason@example.com'
|
228
|
+
# config.token = 'abc123'
|
229
|
+
# end
|
230
|
+
#
|
231
|
+
# theme = SupportOps::Zendesk::Themes.get!('9f3c1c11-32bf-480b-9358-13bbc55d1bfe')
|
232
|
+
# pp theme.live
|
233
|
+
# # => false
|
234
|
+
def self.get!(object)
|
235
|
+
if object.is_a? Themes
|
236
|
+
Themes.new(id: id).find!
|
237
|
+
else
|
238
|
+
Themes.new(id: object).find!
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
##
|
243
|
+
# Creates a zipfile for the theme
|
244
|
+
#
|
245
|
+
# @author Jason Colyer
|
246
|
+
# @since 1.0.0
|
247
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
248
|
+
# @param base_folder [String optional] The path to the folder the theme
|
249
|
+
# files are located in; defaults to './'
|
250
|
+
# @example
|
251
|
+
# require 'support_ops_zendesk'
|
252
|
+
#
|
253
|
+
# file = SupportOps::Zendesk::Themes.package!('data/new_app')
|
254
|
+
# pp file
|
255
|
+
# # => "data/20250409124436282.zip"
|
256
|
+
def self.package!(base_folder = '')
|
257
|
+
list = %w[ assets manifest.json script.js settings style.css templates thumbnail.png translations ]
|
258
|
+
SupportOps::Packages.create_zipfile!(item_list: list, input_dir: base_folder)
|
259
|
+
end
|
260
|
+
|
261
|
+
private
|
262
|
+
|
263
|
+
##
|
264
|
+
# @private
|
265
|
+
def get_record
|
266
|
+
response = self.client.connection.get("guide/theming/themes/#{self.id}")
|
267
|
+
return nil if response.status != 200
|
268
|
+
|
269
|
+
Oj.load(response.body)['theme']
|
270
|
+
end
|
271
|
+
|
272
|
+
##
|
273
|
+
# @private
|
274
|
+
def create_record
|
275
|
+
data = {
|
276
|
+
'attributes' => {
|
277
|
+
'brand_id' => self.brand_id,
|
278
|
+
'format' => 'zip'
|
279
|
+
}
|
280
|
+
}
|
281
|
+
response = self.client.connection.post('guide/theming/jobs/themes/imports', { 'job' => data }.to_json)
|
282
|
+
raise "Failed to create theme (generate job) => #{body}" if response.status != 202
|
283
|
+
job = ThemeJobStatuses.new(body['job'])
|
284
|
+
upload_url = job.data['upload']['url']
|
285
|
+
upload_params = job.data['upload']['parameters']
|
286
|
+
data = upload_params.merge(file: ::Faraday::UploadIO.new(file, 'application/zip'))
|
287
|
+
response = self.client.connection.post(url, data)
|
288
|
+
job.wait_for_completetion
|
289
|
+
response = client.connection.get('guide/theming/themes')
|
290
|
+
body = Oj.load(response.body)
|
291
|
+
body['themes'].detect { |t| t.name == self.name }
|
292
|
+
end
|
293
|
+
|
294
|
+
##
|
295
|
+
# @private
|
296
|
+
def update_record
|
297
|
+
data = {
|
298
|
+
'attributes' => {
|
299
|
+
'theme_id' => self.id,
|
300
|
+
'replace_settings' => true,
|
301
|
+
'format' => 'zip'
|
302
|
+
}
|
303
|
+
}
|
304
|
+
response = self.client.connection.post('guide/theming/jobs/themes/updates', { 'job' => data }.to_json)
|
305
|
+
body = Oj.load(response.body)
|
306
|
+
raise "Failed to update theme (generate job) => #{body}" if response.status != 202
|
307
|
+
job = ThemeJobStatuses.new(body['job'])
|
308
|
+
upload_url = job.data['upload']['url']
|
309
|
+
upload_params = job.data['upload']['parameters']
|
310
|
+
data = upload_params.merge(file: ::Faraday::UploadIO.new(file, 'application/zip'))
|
311
|
+
response = self.client.connection.post(url, data)
|
312
|
+
job.wait_for_completetion
|
313
|
+
response = client.connection.get('guide/theming/themes')
|
314
|
+
body = Oj.load(response.body)
|
315
|
+
response = self.client.connection.get("guide/theming/themes/#{self.id}")
|
316
|
+
Oj.load(response.body)['theme']
|
317
|
+
end
|
318
|
+
|
319
|
+
##
|
320
|
+
# @private
|
321
|
+
def delete_record
|
322
|
+
response = self.client.connection.delete("guide/theming/themes/#{self.id}")
|
323
|
+
raise "Failed to delete theme => #{body}" if response.status != 204
|
324
|
+
true
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module SupportOps.
|
4
|
+
module SupportOps
|
5
|
+
# Defines the module Zendesk
|
6
|
+
module Zendesk
|
7
|
+
##
|
8
|
+
# Defines the class TicketFieldOptions within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [Integer] id Automatically assigned upon creation
|
13
|
+
# @attr [String] name The name of the custom field option
|
14
|
+
# @attr [Integer] position Ordering of the field relative to other field options
|
15
|
+
# @attr [String] raw_name The dynamic content placeholder, if present, or the name value, if not
|
16
|
+
# @attr [String] value The corresponding tag and backend value for the field option
|
17
|
+
# @todo Show a Ticket Field Option => https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/#show-ticket-field-option
|
18
|
+
class TicketFieldOptions < SupportOps::Zendesk::Base
|
19
|
+
# @!parse
|
20
|
+
# # Creates or updates a ticket field option
|
21
|
+
# #
|
22
|
+
# # @author Jason Colyer
|
23
|
+
# # @since 1.0.0
|
24
|
+
# # @return [Object]
|
25
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#create_or_update!}
|
26
|
+
# # @see
|
27
|
+
# # https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/#create-or-update-ticket-field-option
|
28
|
+
# # Zendesk API > Ticket Fields > Create Or Update Ticket Field Option
|
29
|
+
# # @example
|
30
|
+
# # require 'support_ops_zendesk'
|
31
|
+
# #
|
32
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
33
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
34
|
+
# # config.username = 'jason@example.com'
|
35
|
+
# # config.token = 'abc123'
|
36
|
+
# # end
|
37
|
+
# #
|
38
|
+
# # new_option = SupportOps::Zendesk::TicketFieldOptions.new
|
39
|
+
# # new_option.name = 'Linux'
|
40
|
+
# # new_option.value = 'system_linux'
|
41
|
+
# # new_option.ticket_field_id = 123456
|
42
|
+
# #
|
43
|
+
# # new_option.create_or_update!
|
44
|
+
# #
|
45
|
+
# # pp new_option.name
|
46
|
+
# # # => "Linux"
|
47
|
+
# def create_or_update!; end
|
48
|
+
# @!parse
|
49
|
+
# # Deletes a ticket field option
|
50
|
+
# #
|
51
|
+
# # @author Jason Colyer
|
52
|
+
# # @since 1.0.0
|
53
|
+
# # @return [Boolean]
|
54
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
55
|
+
# # @see
|
56
|
+
# # https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/#delete-ticket-field-option
|
57
|
+
# # Zendesk API > Ticket Fields > Delete Ticket Field Option
|
58
|
+
# # @example
|
59
|
+
# # require 'support_ops_zendesk'
|
60
|
+
# #
|
61
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
62
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
63
|
+
# # config.username = 'jason@example.com'
|
64
|
+
# # config.token = 'abc123'
|
65
|
+
# # end
|
66
|
+
# #
|
67
|
+
# # existing_field = SupportOps::Zendesk::TicketFieldOptions.get!(23409462)
|
68
|
+
# # existing_option = existing_field.field_options.last
|
69
|
+
# # existing_option.delete!
|
70
|
+
# def delete!; end
|
71
|
+
define_attributes :id, :name, :position, :raw_name, :value,
|
72
|
+
:ticket_field_id
|
73
|
+
readonly_attributes :id, :ticket_field_id
|
74
|
+
|
75
|
+
##
|
76
|
+
# Lists ticket field options in the Zendesk system
|
77
|
+
#
|
78
|
+
# @author Jason Colyer
|
79
|
+
# @since 1.0.0
|
80
|
+
# @overload list(key: value)
|
81
|
+
# @param ticket_field_id [Integer required] The ticket field to find the options for
|
82
|
+
# @param limit [Integer optional] The limit to the number of ticket
|
83
|
+
# field options returned. Default to 0 (i.e. no limit)
|
84
|
+
# @return [Array]
|
85
|
+
# @see
|
86
|
+
# https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_fields/#list-ticket-field-options
|
87
|
+
# Zendesk API > Ticket Fields > List Ticket Field Options
|
88
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
89
|
+
# @example
|
90
|
+
# require 'support_ops_zendesk'
|
91
|
+
#
|
92
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
93
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
94
|
+
# config.username = 'jason@example.com'
|
95
|
+
# config.token = 'abc123'
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# field = SupportOps::Zendesk::TicketFields.get!(50)
|
99
|
+
# options = SupportOps::Zendesk::TicketFields.list(ticket_field_id: field.id)
|
100
|
+
# pp options.count
|
101
|
+
# # => 5
|
102
|
+
# pp options.last.value
|
103
|
+
# # => "other_or_misc"
|
104
|
+
def self.list(**args)
|
105
|
+
raise 'You must provide a ticket value' unless args[:ticket_field_id]
|
106
|
+
args[:limit] = 0 unless args[:limit]
|
107
|
+
array = []
|
108
|
+
opts = 'page[size]=100'
|
109
|
+
loop do
|
110
|
+
response = client.connection.get("ticket_fields/#{args[:ticket_field_id]}/options?#{opts}")
|
111
|
+
body = Oj.load(response.body)
|
112
|
+
body['custom_field_options'].each do |c|
|
113
|
+
c['ticket_field_id'] = args[:ticket_field_id]
|
114
|
+
end
|
115
|
+
array += body['custom_field_options'].map { |c| TicketFieldOptions.new(c) }
|
116
|
+
break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
|
117
|
+
break unless body['meta']['has_more']
|
118
|
+
|
119
|
+
opts = body['links']['next'].split('?').last
|
120
|
+
end
|
121
|
+
return array if args[:limit].to_i.zero?
|
122
|
+
|
123
|
+
array.first(args[:limit].to_i)
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
##
|
129
|
+
# @private
|
130
|
+
def create_or_update_record
|
131
|
+
data = {
|
132
|
+
'id' => self.id,
|
133
|
+
'name' => self.name,
|
134
|
+
'value' => self.value,
|
135
|
+
'position' => self.position,
|
136
|
+
'raw_name' => self.raw_name
|
137
|
+
}.compact
|
138
|
+
response = self.client.connection.post("ticket_fields/#{self.ticket_field_id}/options", { custom_field_option: data }.to_json)
|
139
|
+
body = Oj.load(response.body)
|
140
|
+
raise "Failed to create or update ticket field option => #{body}" unless [200, 201].include?(response.status)
|
141
|
+
body['custom_field_option']['ticket_field_id'] = self.ticket_field_id
|
142
|
+
body['custom_field_option']
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# @private
|
147
|
+
def delete_record
|
148
|
+
response = client.connection.delete("ticket_fields/#{self.ticket_field_id}/options/#{self.id}")
|
149
|
+
raise "Failed to delete ticket field option #{self.id} => #{body}" if response.status != 204
|
150
|
+
true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|