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,310 @@
|
|
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 Translations within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] body HTML body of the translation. Empty by default
|
13
|
+
# @attr [String] created_at The time at which the translation was created
|
14
|
+
# @attr [Integer] created_by_id The id of the user who created the translation
|
15
|
+
# @attr [Boolean] draft True if the translation is a draft; false otherwise; false by default
|
16
|
+
# @attr [String] html_url The url of the translation in Help Center
|
17
|
+
# @attr [Integer] id Automatically assigned when a translation is created
|
18
|
+
# @attr [String] locale The locale of the translation
|
19
|
+
# @attr [Boolean] outdated True if the translation is outdated; false otherwise; false by default
|
20
|
+
# @attr [Integer] source_id The id of the item that has this translation
|
21
|
+
# @attr [String] source_type The type of the item that has this translation; can be "article", "section", or "category".
|
22
|
+
# @attr [String] title The title of the translation
|
23
|
+
# @attr [String] updated_at The time at which the translation was last updated
|
24
|
+
# @attr [Integer] updated_by_id The id of the user who last updated the translation
|
25
|
+
class Translations < SupportOps::Zendesk::Base
|
26
|
+
# @!parse
|
27
|
+
# # Creates/updates a translation
|
28
|
+
# #
|
29
|
+
# # @author Jason Colyer
|
30
|
+
# # @since 1.0.0
|
31
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::Articles},
|
32
|
+
# # {SupportOps::Zendesk::HelpCenterCategories}, or
|
33
|
+
# # {SupportOps::Zendesk::HelpCenterSections}
|
34
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#save!}
|
35
|
+
# # @see
|
36
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#create-translation
|
37
|
+
# # Zendesk API > Translations > Create Translation
|
38
|
+
# # @see
|
39
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#update-translation
|
40
|
+
# # Zendesk API > Translations > Update Translation
|
41
|
+
# # @example
|
42
|
+
# # require 'support_ops_zendesk'
|
43
|
+
# #
|
44
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
45
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
46
|
+
# # config.username = 'jason@example.com'
|
47
|
+
# # config.token = 'abc123'
|
48
|
+
# # end
|
49
|
+
# #
|
50
|
+
# # object = SupportOps::Zendesk::Articles.list.last
|
51
|
+
# # new_translation = SupportOps::Zendesk::Translations.new
|
52
|
+
# # new_translation.locale = 'en-us'
|
53
|
+
# # new_translation.title = 'Super Hero Tricks'
|
54
|
+
# # new_translation.body = 'This article contains a collection of Super Hero tricks'
|
55
|
+
# # new_translation.source_id = object.id
|
56
|
+
# # new_translation.source_type = 'article'
|
57
|
+
# #
|
58
|
+
# # new_translation.save!
|
59
|
+
# #
|
60
|
+
# # pp new_translation.id
|
61
|
+
# # # => 23409462
|
62
|
+
# # @example
|
63
|
+
# # require 'support_ops_zendesk'
|
64
|
+
# #
|
65
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
66
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
67
|
+
# # config.username = 'jason@example.com'
|
68
|
+
# # config.token = 'abc123'
|
69
|
+
# # end
|
70
|
+
# #
|
71
|
+
# # object = SupportOps::Zendesk::Articles.list.last
|
72
|
+
# # existing_translation = SupportOps::Zendesk::Translations.get!(object, 'en-us')
|
73
|
+
# # existing_translation.title = 'Super Hero Tricks (be like All Might)'
|
74
|
+
# #
|
75
|
+
# # existing_translation.save!
|
76
|
+
# #
|
77
|
+
# # pp existing_trigger.title
|
78
|
+
# # # => "Super Hero Tricks (be like All Might)"
|
79
|
+
# def save!; end
|
80
|
+
# @!parse
|
81
|
+
# # Deletes a translation
|
82
|
+
# #
|
83
|
+
# # @author Jason Colyer
|
84
|
+
# # @since 1.0.0
|
85
|
+
# # @return [Boolean]
|
86
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
87
|
+
# # @see
|
88
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#delete-translation
|
89
|
+
# # Zendesk API > Translations > Delete Translation
|
90
|
+
# # @example
|
91
|
+
# # require 'support_ops_zendesk'
|
92
|
+
# #
|
93
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
94
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
95
|
+
# # config.username = 'jason@example.com'
|
96
|
+
# # config.token = 'abc123'
|
97
|
+
# # end
|
98
|
+
# #
|
99
|
+
# # object = SupportOps::Zendesk::Articles.list.last
|
100
|
+
# # existing_translation = SupportOps::Zendesk::Translations.get!(object, 'en-us')
|
101
|
+
# # existing_translation.delete!
|
102
|
+
# def delete!; end
|
103
|
+
define_attributes :body, :created_at, :created_by_id, :draft, :html_url,
|
104
|
+
:id, :locale, :outdated, :source_id, :source_type,
|
105
|
+
:title, :updated_at, :updated_by_id
|
106
|
+
readonly_attributes :created_at, :created_by_id, :html_url, :id,
|
107
|
+
:source_id, :source_type, :updated_at, :updated_by_id
|
108
|
+
|
109
|
+
##
|
110
|
+
# Lists translations in the Zendesk system
|
111
|
+
#
|
112
|
+
# @author Jason Colyer
|
113
|
+
# @since 1.0.0
|
114
|
+
# @param object [Object] An existing {SupportOps::Zendesk::Articles},
|
115
|
+
# {SupportOps::Zendesk::HelpCenterCategories}, or
|
116
|
+
# {SupportOps::Zendesk::HelpCenterSections}
|
117
|
+
# @return [Array]
|
118
|
+
# @see
|
119
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#list-translations
|
120
|
+
# Zendesk API > Translations > List Translations
|
121
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
122
|
+
# @example
|
123
|
+
# require 'support_ops_zendesk'
|
124
|
+
#
|
125
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
126
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
127
|
+
# config.username = 'jason@example.com'
|
128
|
+
# config.token = 'abc123'
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# object = SupportOps::Zendesk::HelpCenterSections.list.first
|
132
|
+
# translations = SupportOps::Zendesk::Translations.list(object)
|
133
|
+
# pp translations.count
|
134
|
+
# # => 2
|
135
|
+
def self.list(object)
|
136
|
+
if object.is_a? HelpCenterCategories
|
137
|
+
response = client.connection.get("help_center/categories/#{object.id}/translations")
|
138
|
+
elsif object.is_a? HelpCenterSections
|
139
|
+
response = client.connection.get("help_center/sections/#{object.id}/translations")
|
140
|
+
elsif object.is_a? Articles
|
141
|
+
response = client.connection.get("help_center/articles/#{object.id}/translations")
|
142
|
+
else
|
143
|
+
raise "Unknown object for a translation: #{object.class}"
|
144
|
+
end
|
145
|
+
body = Oj.load(response.body)
|
146
|
+
body['translations'].map { |t| Translations.new(t) }
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Lists missing translation locales in the Zendesk system
|
151
|
+
#
|
152
|
+
# @author Jason Colyer
|
153
|
+
# @since 1.0.0
|
154
|
+
# @param object [Object] An existing {SupportOps::Zendesk::Articles},
|
155
|
+
# {SupportOps::Zendesk::HelpCenterCategories}, or
|
156
|
+
# {SupportOps::Zendesk::HelpCenterSections}
|
157
|
+
# @return [Array]
|
158
|
+
# @see
|
159
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#list-missing-translations
|
160
|
+
# Zendesk API > Translations > List Missing Translations
|
161
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
162
|
+
# @example
|
163
|
+
# require 'support_ops_zendesk'
|
164
|
+
#
|
165
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
166
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
167
|
+
# config.username = 'jason@example.com'
|
168
|
+
# config.token = 'abc123'
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# object = SupportOps::Zendesk::Articles.list.last
|
172
|
+
# locales = SupportOps::Zendesk::Translations.list_missing(object)
|
173
|
+
# pp locales
|
174
|
+
# # => ["da-dk"]
|
175
|
+
def self.list_missing(object)
|
176
|
+
if object.is_a? HelpCenterCategories
|
177
|
+
response = client.connection.get("help_center/categories/#{object.id}/translations/missing")
|
178
|
+
elsif object.is_a? HelpCenterSections
|
179
|
+
response = client.connection.get("help_center/sections/#{object.id}/translations/missing")
|
180
|
+
elsif object.is_a? Articles
|
181
|
+
response = client.connection.get("help_center/articles/#{object.id}/translations/missing")
|
182
|
+
else
|
183
|
+
raise "Unknown object for a translation: #{object.class}"
|
184
|
+
end
|
185
|
+
body = Oj.load(response.body)
|
186
|
+
body['locales']
|
187
|
+
end
|
188
|
+
|
189
|
+
##
|
190
|
+
# Locates a specific translation in the Zendesk system
|
191
|
+
#
|
192
|
+
# @author Jason Colyer
|
193
|
+
# @since 1.0.0
|
194
|
+
# @see
|
195
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#show-translation
|
196
|
+
# Zendesk API > Translations > Show Translation
|
197
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
198
|
+
# @param object [Object] An existing {SupportOps::Zendesk::Articles},
|
199
|
+
# {SupportOps::Zendesk::HelpCenterCategories}, or
|
200
|
+
# {SupportOps::Zendesk::HelpCenterSections}
|
201
|
+
# @param locale [String] The locale to fetch the translation for
|
202
|
+
# @example
|
203
|
+
# require 'support_ops_zendesk'
|
204
|
+
#
|
205
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
206
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
207
|
+
# config.username = 'jason@example.com'
|
208
|
+
# config.token = 'abc123'
|
209
|
+
# end
|
210
|
+
#
|
211
|
+
# object = SupportOps::Zendesk::Articles.list.last
|
212
|
+
# translation = SupportOps::Zendesk::Translations.get(object, 'en-us')
|
213
|
+
# pp translation.title
|
214
|
+
# # => "Support Pages"
|
215
|
+
def self.get(object, locale)
|
216
|
+
type = if object.is_a? HelpCenterCategories
|
217
|
+
'category'
|
218
|
+
elsif object.is_a? HelpCenterSections
|
219
|
+
'section'
|
220
|
+
elsif object.is_a? Articles
|
221
|
+
'article'
|
222
|
+
end
|
223
|
+
Translations.new(
|
224
|
+
locale: locale,
|
225
|
+
source_type: type,
|
226
|
+
source_id: object.id
|
227
|
+
).find
|
228
|
+
end
|
229
|
+
|
230
|
+
##
|
231
|
+
# Locates a specific translation in the Zendesk system
|
232
|
+
#
|
233
|
+
# @author Jason Colyer
|
234
|
+
# @since 1.0.0
|
235
|
+
# @see
|
236
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#show-translation
|
237
|
+
# Zendesk API > Translations > Show Translation
|
238
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
239
|
+
# @param object [Object] An existing {SupportOps::Zendesk::Articles},
|
240
|
+
# {SupportOps::Zendesk::HelpCenterCategories}, or
|
241
|
+
# {SupportOps::Zendesk::HelpCenterSections}
|
242
|
+
# @param locale [String] The locale to fetch the translation for
|
243
|
+
# @example
|
244
|
+
# require 'support_ops_zendesk'
|
245
|
+
#
|
246
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
247
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
248
|
+
# config.username = 'jason@example.com'
|
249
|
+
# config.token = 'abc123'
|
250
|
+
# end
|
251
|
+
#
|
252
|
+
# object = SupportOps::Zendesk::Articles.list.last
|
253
|
+
# translation = SupportOps::Zendesk::Translations.get!(object, 'en-us')
|
254
|
+
# pp translation.title
|
255
|
+
# # => "Support Pages"
|
256
|
+
def self.get!(object, locale)
|
257
|
+
type = if object.is_a? HelpCenterCategories
|
258
|
+
'category'
|
259
|
+
elsif object.is_a? HelpCenterSections
|
260
|
+
'section'
|
261
|
+
elsif object.is_a? Articles
|
262
|
+
'article'
|
263
|
+
end
|
264
|
+
Translations.new(
|
265
|
+
locale: locale,
|
266
|
+
source_type: type,
|
267
|
+
source_id: object.id
|
268
|
+
).find!
|
269
|
+
end
|
270
|
+
|
271
|
+
private
|
272
|
+
|
273
|
+
##
|
274
|
+
# @private
|
275
|
+
def get_record
|
276
|
+
response = self.client.connection.get("help_center/#{self.source_type.pluralize}/#{self.source_id}/translations/#{self.locale}")
|
277
|
+
return nil if response.status != 200
|
278
|
+
|
279
|
+
Oj.load(response.body)['translation']
|
280
|
+
end
|
281
|
+
|
282
|
+
##
|
283
|
+
# @private
|
284
|
+
def create_record
|
285
|
+
response = self.client.connection.post("help_center/#{self.source_type.pluralize.downcase}/#{self.source_id}/translations", { translation: attributes_for_save }.to_json)
|
286
|
+
body = Oj.load(response.body)
|
287
|
+
raise "Failed to create translation => #{body}" if response.status != 201
|
288
|
+
body['translation']
|
289
|
+
end
|
290
|
+
|
291
|
+
##
|
292
|
+
# @private
|
293
|
+
def update_record
|
294
|
+
raise "Failed to update trigger => You didn't change anything in the object" if attributes_for_save.keys == [:id]
|
295
|
+
response = self.client.connection.put("help_center/#{self.source_type.pluralize.downcase}/#{self.source_id}/translations/#{self.locale}", { translation: attributes_for_save }.to_json)
|
296
|
+
body = Oj.load(response.body)
|
297
|
+
raise "Failed to update translation #{self.source_type.pluralize}/#{self.source_id} #{self.id} => #{body}" if response.status != 200
|
298
|
+
body['translation']
|
299
|
+
end
|
300
|
+
|
301
|
+
##
|
302
|
+
# @private
|
303
|
+
def delete_record
|
304
|
+
response = self.client.connection.delete("help_center/translations/#{self.id}")
|
305
|
+
raise "Failed to delete translation => #{body}" if response.status != 204
|
306
|
+
true
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
@@ -0,0 +1,275 @@
|
|
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 TriggerCategories within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] created_at When this record was created
|
13
|
+
# @attr [Integer] id Automatically assigned when the trigger category is created
|
14
|
+
# @attr [String] name Trigger cagegory name
|
15
|
+
# @attr [Integer] position The position of the trigger category
|
16
|
+
# @attr [String] updated_at When this record was updated
|
17
|
+
# @todo Create Batch Job for Ticket Trigger Categories => https://developer.zendesk.com/api-reference/ticketing/business-rules/trigger_categories/#create-batch-job-for-ticket-trigger-categories
|
18
|
+
class TriggerCategories < SupportOps::Zendesk::Base
|
19
|
+
# @!parse
|
20
|
+
# # Creates/updates a trigger category
|
21
|
+
# #
|
22
|
+
# # @author Jason Colyer
|
23
|
+
# # @since 1.0.0
|
24
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::Users}
|
25
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#save!}
|
26
|
+
# # @see
|
27
|
+
# # https://developer.zendesk.com/api-reference/ticketing/business-rules/trigger_categories/#create-ticket-trigger-category
|
28
|
+
# # Zendesk API > Ticket Trigger Categories > Create Ticket Trigger Category
|
29
|
+
# # @see
|
30
|
+
# # https://developer.zendesk.com/api-reference/ticketing/business-rules/trigger_categories/#update-ticket-trigger-category
|
31
|
+
# # Zendesk API > Ticket Trigger Categories > Update Ticket Trigger Category
|
32
|
+
# # @example
|
33
|
+
# # require 'support_ops_zendesk'
|
34
|
+
# #
|
35
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
36
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
37
|
+
# # config.username = 'jason@example.com'
|
38
|
+
# # config.token = 'abc123'
|
39
|
+
# # end
|
40
|
+
# #
|
41
|
+
# # new_category = SupportOps::Zendesk::TriggerCategories.new
|
42
|
+
# # new_category.name = 'Misc'
|
43
|
+
# # new_category.position = 19
|
44
|
+
# #
|
45
|
+
# # new_category.save!
|
46
|
+
# #
|
47
|
+
# # pp new_category.id
|
48
|
+
# # # => 10001
|
49
|
+
# # @example
|
50
|
+
# # require 'support_ops_zendesk'
|
51
|
+
# #
|
52
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
53
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
54
|
+
# # config.username = 'jason@example.com'
|
55
|
+
# # config.token = 'abc123'
|
56
|
+
# # end
|
57
|
+
# #
|
58
|
+
# # existing_category = SupportOps::Zendesk::TriggerCategories.get!(10001)
|
59
|
+
# # existing_category.name = 'Misc/Etc.'
|
60
|
+
# #
|
61
|
+
# # existing_category.save!
|
62
|
+
# #
|
63
|
+
# # pp existing_category.name
|
64
|
+
# # # => "Misc/Etc."
|
65
|
+
# def save!; end
|
66
|
+
# @!parse
|
67
|
+
# # Deletes a trigger category
|
68
|
+
# #
|
69
|
+
# # @author Jason Colyer
|
70
|
+
# # @since 1.0.0
|
71
|
+
# # @return [Boolean]
|
72
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
73
|
+
# # @see
|
74
|
+
# # https://developer.zendesk.com/api-reference/ticketing/business-rules/trigger_categories/#delete-ticket-trigger-category
|
75
|
+
# # Zendesk API > Ticket Trigger Categories > Delete Ticket Trigger Category
|
76
|
+
# # @example
|
77
|
+
# # require 'support_ops_zendesk'
|
78
|
+
# #
|
79
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
80
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
81
|
+
# # config.username = 'jason@example.com'
|
82
|
+
# # config.token = 'abc123'
|
83
|
+
# # end
|
84
|
+
# #
|
85
|
+
# # existing_category = SupportOps::Zendesk::TriggerCategories.get!(10001)
|
86
|
+
# # existing_category.delete!
|
87
|
+
# def delete!; end
|
88
|
+
define_attributes :created_at, :id, :name, :position, :updated_at
|
89
|
+
readonly_attributes :created_at, :id, :updated_at
|
90
|
+
|
91
|
+
##
|
92
|
+
# Lists trigger categories in the Zendesk system
|
93
|
+
#
|
94
|
+
# @author Jason Colyer
|
95
|
+
# @since 1.0.0
|
96
|
+
# @overload list(key: value)
|
97
|
+
# @param sort [String optional] Sort parameters. Allowed values are
|
98
|
+
# "position", "-position", "name", "-name", "created_at",
|
99
|
+
# "-created_at", "updated_at", or "-updated_at".
|
100
|
+
# @param limit [Integer optional] The limit to the number of trigger
|
101
|
+
# categories returned. Default to 0 (i.e. no limit)
|
102
|
+
# @return [Array]
|
103
|
+
# @see
|
104
|
+
# https://developer.zendesk.com/api-reference/ticketing/business-rules/trigger_categories/#list-ticket-trigger-categories
|
105
|
+
# Zendesk API > Ticket Trigger Categories > List Ticket Trigger Categories
|
106
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
107
|
+
# @example
|
108
|
+
# require 'support_ops_zendesk'
|
109
|
+
#
|
110
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
111
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
112
|
+
# config.username = 'jason@example.com'
|
113
|
+
# config.token = 'abc123'
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# categories = SupportOps::Zendesk::TriggerCategories.list(limit: 25)
|
117
|
+
# pp categories.count
|
118
|
+
# # => 18
|
119
|
+
# pp categories.last.name
|
120
|
+
# # => "2FA"
|
121
|
+
def self.list(**args)
|
122
|
+
args[:sort] = nil unless args[:sort]
|
123
|
+
args[:limit] = 0 unless args[:limit]
|
124
|
+
params = ''
|
125
|
+
params += "sort=#{args[:sort]}&" unless args[:sort].nil?
|
126
|
+
categories = []
|
127
|
+
opts = "#{params}page[size]=100"
|
128
|
+
loop do
|
129
|
+
response = client.connection.get("trigger_categories?#{opts}")
|
130
|
+
body = Oj.load(response.body)
|
131
|
+
categories += body['trigger_categories'].map { |t| TriggerCategories.new(t) }
|
132
|
+
break if args[:limit].to_i.positive? && categories.count >= args[:limit].to_i
|
133
|
+
break unless body['meta']['has_more']
|
134
|
+
|
135
|
+
opts = body['links']['next'].split('?').last
|
136
|
+
end
|
137
|
+
return categories if args[:limit].to_i.zero?
|
138
|
+
|
139
|
+
categories.first(args[:limit].to_i)
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Locates a trigger categories within Zendesk by name. Can utilize a cache for quicker results
|
144
|
+
#
|
145
|
+
# @author Jason Colyer
|
146
|
+
# @since 1.0.0
|
147
|
+
# @overload find_by_name(key: value)
|
148
|
+
# @param name [String required] The name to search for
|
149
|
+
# @param cache [Array] An Array of SupportOps::Zendesk::TriggerCategories to use as a cache
|
150
|
+
# @return [Object] An instance of {SupportOps::Zendesk::TriggerCategories}
|
151
|
+
# @example
|
152
|
+
# require 'support_ops_zendesk'
|
153
|
+
#
|
154
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
155
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
156
|
+
# config.username = 'jason@example.com'
|
157
|
+
# config.token = 'abc123'
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# categories = SupportOps::Zendesk::TriggerCategories.list
|
161
|
+
# category = SupportOps::Zendesk::TriggerCategories.find_by_name(name: '2FA', cache: categories)
|
162
|
+
# pp category.name
|
163
|
+
# # => "2FA"
|
164
|
+
# pp category.id
|
165
|
+
# # => 18451777063964
|
166
|
+
def self.find_by_name(**args)
|
167
|
+
raise 'You have to provide a name' unless args[:name]
|
168
|
+
if args[:cache]
|
169
|
+
raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
|
170
|
+
categories = args[:cache]
|
171
|
+
else
|
172
|
+
categories = list
|
173
|
+
end
|
174
|
+
categories.detect { |c| c.name.downcase == args[:name].to_s.downcase }
|
175
|
+
end
|
176
|
+
|
177
|
+
##
|
178
|
+
# Locates a specific trigger category in the Zendesk system
|
179
|
+
#
|
180
|
+
# @author Jason Colyer
|
181
|
+
# @since 1.0.0
|
182
|
+
# @see
|
183
|
+
# https://developer.zendesk.com/api-reference/ticketing/business-rules/trigger_categories/#show-ticket-trigger-category
|
184
|
+
# Zendesk API > Ticket Trigger Categories > Show Ticket Trigger Category
|
185
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
186
|
+
# @example
|
187
|
+
# require 'support_ops_zendesk'
|
188
|
+
#
|
189
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
190
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
191
|
+
# config.username = 'jason@example.com'
|
192
|
+
# config.token = 'abc123'
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# category = SupportOps::Zendesk::TriggerCategories.get(18451777063964)
|
196
|
+
# pp category.name
|
197
|
+
# # => "2FA"
|
198
|
+
def self.get(object)
|
199
|
+
if object.is_a? TriggerCategories
|
200
|
+
TriggerCategories.new(id: id).find
|
201
|
+
else
|
202
|
+
TriggerCategories.new(id: object).find
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
##
|
207
|
+
# Locates a specific trigger category in the Zendesk system
|
208
|
+
#
|
209
|
+
# @author Jason Colyer
|
210
|
+
# @since 1.0.0
|
211
|
+
# @see
|
212
|
+
# https://developer.zendesk.com/api-reference/ticketing/business-rules/trigger_categories/#show-ticket-trigger-category
|
213
|
+
# Zendesk API > Ticket Trigger Categories > Show Ticket Trigger Category
|
214
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
215
|
+
# @example
|
216
|
+
# require 'support_ops_zendesk'
|
217
|
+
#
|
218
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
219
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
220
|
+
# config.username = 'jason@example.com'
|
221
|
+
# config.token = 'abc123'
|
222
|
+
# end
|
223
|
+
#
|
224
|
+
# category = SupportOps::Zendesk::TriggerCategories.get!(18451777063964)
|
225
|
+
# pp category.name
|
226
|
+
# # => "2FA"
|
227
|
+
def self.get!(object)
|
228
|
+
if object.is_a? TriggerCategories
|
229
|
+
TriggerCategories.new(id: id).find!
|
230
|
+
else
|
231
|
+
TriggerCategories.new(id: object).find!
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
private
|
236
|
+
|
237
|
+
##
|
238
|
+
# @private
|
239
|
+
def get_record
|
240
|
+
response = self.client.connection.get("trigger_categories/#{self.id}")
|
241
|
+
return nil if response.status != 200
|
242
|
+
|
243
|
+
Oj.load(response.body)['trigger_category']
|
244
|
+
end
|
245
|
+
|
246
|
+
##
|
247
|
+
# @private
|
248
|
+
def create_record
|
249
|
+
response = self.client.connection.post("trigger_categories", { trigger_category: attributes_for_save }.to_json)
|
250
|
+
body = Oj.load(response.body)
|
251
|
+
raise "Failed to create trigger category => #{body['errors']}" if response.status != 201
|
252
|
+
body['trigger_category']
|
253
|
+
end
|
254
|
+
|
255
|
+
##
|
256
|
+
# @private
|
257
|
+
def update_record
|
258
|
+
raise "Failed to update user => You didn't change anything in the object" if attributes_for_save.keys == [:id]
|
259
|
+
response = self.client.connection.put("trigger_categories/#{self.id}", { trigger_category: attributes_for_save }.to_json)
|
260
|
+
body = Oj.load(response.body)
|
261
|
+
raise "Failed to update trigger category #{self.id} => #{body['errors']}" if response.status != 200
|
262
|
+
body['trigger_category']
|
263
|
+
end
|
264
|
+
|
265
|
+
##
|
266
|
+
# @private
|
267
|
+
def delete_record
|
268
|
+
response = self.client.connection.delete("trigger_categories/#{self.id}")
|
269
|
+
body = Oj.load(response.body)
|
270
|
+
raise "Failed to delete trigger category => #{body['errors']}" if response.status != 204
|
271
|
+
true
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|