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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_zendesk/packages.rb +89 -0
  3. data/lib/support_ops_zendesk/zendesk/app_installations.rb +62 -0
  4. data/lib/support_ops_zendesk/zendesk/app_job_statuses.rb +157 -0
  5. data/lib/support_ops_zendesk/zendesk/apps.rb +476 -0
  6. data/lib/support_ops_zendesk/zendesk/articles.rb +362 -0
  7. data/lib/support_ops_zendesk/zendesk/audit_logs.rb +166 -0
  8. data/lib/support_ops_zendesk/zendesk/automations.rb +390 -0
  9. data/lib/support_ops_zendesk/zendesk/base.rb +472 -0
  10. data/lib/support_ops_zendesk/zendesk/brands.rb +172 -0
  11. data/lib/support_ops_zendesk/zendesk/client.rb +91 -0
  12. data/lib/support_ops_zendesk/zendesk/comments.rb +37 -0
  13. data/lib/support_ops_zendesk/zendesk/configuration.rb +138 -0
  14. data/lib/support_ops_zendesk/zendesk/custom_roles.rb +224 -0
  15. data/lib/support_ops_zendesk/zendesk/dynamic_content.rb +297 -0
  16. data/lib/support_ops_zendesk/zendesk/dynamic_content_variants.rb +309 -0
  17. data/lib/support_ops_zendesk/zendesk/group_memberships.rb +337 -0
  18. data/lib/support_ops_zendesk/zendesk/groups.rb +385 -0
  19. data/lib/support_ops_zendesk/zendesk/help_center_categories.rb +332 -0
  20. data/lib/support_ops_zendesk/zendesk/help_center_content_tags.rb +237 -0
  21. data/lib/support_ops_zendesk/zendesk/help_center_management_permission_groups.rb +271 -0
  22. data/lib/support_ops_zendesk/zendesk/help_center_sections.rb +378 -0
  23. data/lib/support_ops_zendesk/zendesk/help_center_topics.rb +274 -0
  24. data/lib/support_ops_zendesk/zendesk/help_center_user_segments.rb +279 -0
  25. data/lib/support_ops_zendesk/zendesk/job_statuses.rb +231 -0
  26. data/lib/support_ops_zendesk/zendesk/locales.rb +326 -0
  27. data/lib/support_ops_zendesk/zendesk/macros.rb +407 -0
  28. data/lib/support_ops_zendesk/zendesk/oauth_clients.rb +186 -0
  29. data/lib/support_ops_zendesk/zendesk/oauth_tokens.rb +114 -0
  30. data/lib/support_ops_zendesk/zendesk/organization_fields.rb +282 -0
  31. data/lib/support_ops_zendesk/zendesk/organization_memberships.rb +336 -0
  32. data/lib/support_ops_zendesk/zendesk/organizations.rb +568 -0
  33. data/lib/support_ops_zendesk/zendesk/requester_roles.rb +58 -0
  34. data/lib/support_ops_zendesk/zendesk/satisfaction_reasons.rb +161 -0
  35. data/lib/support_ops_zendesk/zendesk/schedule_holidays.rb +27 -0
  36. data/lib/support_ops_zendesk/zendesk/schedules.rb +192 -0
  37. data/lib/support_ops_zendesk/zendesk/search.rb +185 -0
  38. data/lib/support_ops_zendesk/zendesk/sla_policies.rb +302 -0
  39. data/lib/support_ops_zendesk/zendesk/targets.rb +96 -0
  40. data/lib/support_ops_zendesk/zendesk/theme_job_statuses.rb +154 -0
  41. data/lib/support_ops_zendesk/zendesk/themes.rb +328 -0
  42. data/lib/support_ops_zendesk/zendesk/ticket_field_options.rb +154 -0
  43. data/lib/support_ops_zendesk/zendesk/ticket_fields.rb +357 -0
  44. data/lib/support_ops_zendesk/zendesk/ticket_forms.rb +370 -0
  45. data/lib/support_ops_zendesk/zendesk/ticket_user_types.rb +67 -0
  46. data/lib/support_ops_zendesk/zendesk/tickets.rb +837 -0
  47. data/lib/support_ops_zendesk/zendesk/translations.rb +310 -0
  48. data/lib/support_ops_zendesk/zendesk/trigger_categories.rb +275 -0
  49. data/lib/support_ops_zendesk/zendesk/triggers.rb +427 -0
  50. data/lib/support_ops_zendesk/zendesk/user_field_options.rb +153 -0
  51. data/lib/support_ops_zendesk/zendesk/user_fields.rb +312 -0
  52. data/lib/support_ops_zendesk/zendesk/users.rb +889 -0
  53. data/lib/support_ops_zendesk/zendesk/via_types.rb +137 -0
  54. data/lib/support_ops_zendesk/zendesk/views.rb +636 -0
  55. data/lib/support_ops_zendesk/zendesk/webhooks.rb +206 -0
  56. data/lib/support_ops_zendesk/zendesk.rb +66 -0
  57. data/lib/support_ops_zendesk.rb +29 -0
  58. metadata +274 -0
@@ -0,0 +1,390 @@
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 Automations within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Array] actions An object describing what the automation will do
13
+ # @attr [Boolean] active Whether the automation is active
14
+ # @attr [Hash] conditions An object that describes the conditions under which the automation will execute
15
+ # @attr [String] created_at The time the automation was created
16
+ # @attr [Boolean] default If true, the automation is a default automation
17
+ # @attr [Integer] id Automatically assigned when created
18
+ # @attr [Integer] position The position of the automation which specifies the order it will be executed
19
+ # @attr [String] raw_title The raw title of the automation
20
+ # @attr [String] title The title of the automation
21
+ # @attr [String] updated_at The time of the last update of the automation
22
+ # @todo Search Automations => https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#search-automations
23
+ class Automations < SupportOps::Zendesk::Base
24
+ # @!parse
25
+ # # Creates/updates an automation
26
+ # #
27
+ # # @author Jason Colyer
28
+ # # @since 1.0.0
29
+ # # @return [Object] Instance of {SupportOps::Zendesk::Automations}
30
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
31
+ # # @see
32
+ # # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#create-automation
33
+ # # Zendesk API > automations > Create Automation
34
+ # # @see
35
+ # # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#update-automation
36
+ # # Zendesk API > Automations > Update Automation
37
+ # # @example
38
+ # # require 'support_ops_zendesk'
39
+ # #
40
+ # # SupportOps::Zendesk::Configuration.configure do |config|
41
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
42
+ # # config.username = 'jason@example.com'
43
+ # # config.token = 'abc123'
44
+ # # end
45
+ # #
46
+ # # new_automation = SupportOps::Zendesk::Automations.new
47
+ # # new_automation.title = 'Change priority to low for solved tickets'
48
+ # # new_automation.conditions = {
49
+ # # all: [
50
+ # # {
51
+ # # field: 'status',
52
+ # # operator: 'is',
53
+ # # value: 'solved'
54
+ # # },
55
+ # # {
56
+ # # field: 'priority',
57
+ # # operator: 'is_not',
58
+ # # value: 'low'
59
+ # # }
60
+ # # ],
61
+ # # any: []
62
+ # # }
63
+ # # new_automation.actions = [
64
+ # # {
65
+ # # field: 'priority',
66
+ # # value: 'low'
67
+ # # }
68
+ # # ]
69
+ # #
70
+ # # new_automation.save!
71
+ # #
72
+ # # pp new_automation.id
73
+ # # # => 23409462
74
+ # # @example
75
+ # # require 'support_ops_zendesk'
76
+ # #
77
+ # # SupportOps::Zendesk::Configuration.configure do |config|
78
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
79
+ # # config.username = 'jason@example.com'
80
+ # # config.token = 'abc123'
81
+ # # end
82
+ # #
83
+ # # existing_automation = SupportOps::Zendesk::Automations.get!(23409462)
84
+ # # existing_automation.title = 'Change ticket priority to low for solved tickets'
85
+ # #
86
+ # # existing_automation.save!
87
+ # #
88
+ # # pp existing_automation.title
89
+ # # # => "Change ticket priority to low for solved tickets"
90
+ # def save!; end
91
+ # @!parse
92
+ # # Deletes an automation
93
+ # #
94
+ # # @author Jason Colyer
95
+ # # @since 1.0.0
96
+ # # @return [Boolean]
97
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
98
+ # # @see
99
+ # # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#delete-automation
100
+ # # Zendesk API > Automations > Delete Automation
101
+ # # @example
102
+ # # require 'support_ops_zendesk'
103
+ # #
104
+ # # SupportOps::Zendesk::Configuration.configure do |config|
105
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
106
+ # # config.username = 'jason@example.com'
107
+ # # config.token = 'abc123'
108
+ # # end
109
+ # #
110
+ # # existing_automation = SupportOps::Zendesk::Automations.get!(23409462)
111
+ # # existing_automation.delete!
112
+ # def delete!; end
113
+ define_attributes :actions, :active, :conditions, :created_at, :default,
114
+ :id, :position, :raw_title, :title, :updated_at
115
+ readonly_attributes :created_at, :default, :id, :updated_at
116
+
117
+ ##
118
+ # Lists automations in the Zendesk system
119
+ #
120
+ # @author Jason Colyer
121
+ # @since 1.0.0
122
+ # @overload list(key: value)
123
+ # @param active [Boolean optional] Only active automations if true,
124
+ # inactive automations if false, or all if not provided
125
+ # @param sort [String optional] Possible values are "alphabetical",
126
+ # "created_at", "updated_at", "usage_1h", "usage_24h", or "usage_7d"
127
+ # (defaults to "position")
128
+ # @param sort_order [String optiona] "asc" for ascending, "desc" for
129
+ # descending
130
+ # @param limit [Integer optional] The limit to the number of automations
131
+ # returned. Default to 0 (i.e. no limit)
132
+ # @return [Array]
133
+ # @see
134
+ # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#list-automations
135
+ # Zendesk API > Automations > List Automations
136
+ # @see SupportOps::Zendesk::Configuration Setting up a client
137
+ # @example
138
+ # require 'support_ops_zendesk'
139
+ #
140
+ # SupportOps::Zendesk::Configuration.configure do |config|
141
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
142
+ # config.username = 'jason@example.com'
143
+ # config.token = 'abc123'
144
+ # end
145
+ #
146
+ # automations = SupportOps::Zendesk::Automations.list(limit: 10)
147
+ # pp automations.count
148
+ # # => 10
149
+ # pp automations.last.title
150
+ # # => "I'm the 10th automation"
151
+ def self.list(**args)
152
+ args[:limit] = 0 unless args[:limit]
153
+ sort_order = (args[:sort_order] == 'desc' ? '-' : '')
154
+ array = []
155
+ opts = 'page[size]=100'
156
+ opts += "&sort=#{sort_order}#{args[:sort]}" if args[:sort]
157
+ opts += "&active=#{args[:active]}" if args[:active]
158
+ loop do
159
+ response = client.connection.get("automations?#{opts}")
160
+ body = Oj.load(response.body)
161
+ array += body['automations'].map { |a| Automations.new(a) }
162
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
163
+ break unless body['meta']['has_more']
164
+
165
+ opts = body['links']['next'].split('?').last
166
+ end
167
+ return array if args[:limit].to_i.zero?
168
+
169
+ array.first(args[:limit].to_i)
170
+ end
171
+
172
+ ##
173
+ # Lists active automations in the Zendesk system
174
+ #
175
+ # @author Jason Colyer
176
+ # @since 1.0.0
177
+ # @overload list_active(key: value)
178
+ # @param sort [String optional] Possible values are "alphabetical",
179
+ # "created_at", "updated_at", "usage_1h", "usage_24h", or "usage_7d"
180
+ # (defaults to "position")
181
+ # @param sort_order [String optiona] "asc" for ascending, "desc" for
182
+ # descending
183
+ # @param limit [Integer optional] The limit to the number of automations
184
+ # returned. Default to 0 (i.e. no limit)
185
+ # @return [Array]
186
+ # @see
187
+ # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#list-automations
188
+ # Zendesk API > Automations > List Automations
189
+ # @see SupportOps::Zendesk::Configuration Setting up a client
190
+ # @example
191
+ # require 'support_ops_zendesk'
192
+ #
193
+ # SupportOps::Zendesk::Configuration.configure do |config|
194
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
195
+ # config.username = 'jason@example.com'
196
+ # config.token = 'abc123'
197
+ # end
198
+ #
199
+ # automations = SupportOps::Zendesk::Automations.list(limit: 10)
200
+ # pp automations.count
201
+ # # => 10
202
+ # pp automations.last.title
203
+ # # => "I'm the 10th automation"
204
+ def self.list_active(**args)
205
+ args[:limit] = 0 unless args[:limit]
206
+ sort_order = (args[:sort_order] == 'desc' ? '-' : '')
207
+ array = []
208
+ opts = 'page[size]=100'
209
+ opts += "&sort=#{sort_order}#{args[:sort]}" if args[:sort]
210
+ loop do
211
+ response = client.connection.get("automations/active?#{opts}")
212
+ body = Oj.load(response.body)
213
+ array += body['automations'].map { |a| Automations.new(a) }
214
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
215
+ break unless body['meta']['has_more']
216
+
217
+ opts = body['links']['next'].split('?').last
218
+ end
219
+ return array if args[:limit].to_i.zero?
220
+
221
+ array.first(args[:limit].to_i)
222
+ end
223
+
224
+ ##
225
+ # Locates a specific automation in the Zendesk system
226
+ #
227
+ # @author Jason Colyer
228
+ # @since 1.0.0
229
+ # @see
230
+ # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#show-automation
231
+ # Zendesk API > automations > Show Automation
232
+ # @see SupportOps::Zendesk::Configuration Setting up a client
233
+ # @example
234
+ # require 'support_ops_zendesk'
235
+ #
236
+ # SupportOps::Zendesk::Configuration.configure do |config|
237
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
238
+ # config.username = 'jason@example.com'
239
+ # config.token = 'abc123'
240
+ # end
241
+ #
242
+ # automation = SupportOps::Zendesk::Automations.get(25)
243
+ # pp automation.title
244
+ # # => "I'm the 25th automation"
245
+ def self.get(object)
246
+ if object.is_a? Automations
247
+ Automations.new(id: id).find
248
+ else
249
+ Automations.new(id: object).find
250
+ end
251
+ end
252
+
253
+ ##
254
+ # Locates a specific automation in the Zendesk system
255
+ #
256
+ # @author Jason Colyer
257
+ # @since 1.0.0
258
+ # @see
259
+ # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#show-automation
260
+ # Zendesk API > automations > Show Automation
261
+ # @see SupportOps::Zendesk::Configuration Setting up a client
262
+ # @example
263
+ # require 'support_ops_zendesk'
264
+ #
265
+ # SupportOps::Zendesk::Configuration.configure do |config|
266
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
267
+ # config.username = 'jason@example.com'
268
+ # config.token = 'abc123'
269
+ # end
270
+ #
271
+ # automation = SupportOps::Zendesk::Automations.get!(25)
272
+ # pp automation.title
273
+ # # => "I'm the 25th automation"
274
+ def self.get!(object)
275
+ if object.is_a? Automations
276
+ Automations.new(id: id).find!
277
+ else
278
+ Automations.new(id: object).find!
279
+ end
280
+ end
281
+
282
+ ##
283
+ # Updates multiple automations via a batch job
284
+ #
285
+ # @author Jason Colyer
286
+ # @since 1.0.0
287
+ # @param automations [Array] An array of {SupportOps::Zendesk::Automations} instances
288
+ # @return [object] A {SupportOps::Zendesk::JobStatuses} instance
289
+ # @see
290
+ # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#update-many-automations
291
+ # Zendesk API > Automations > Update Many Automations
292
+ # @example
293
+ # require 'support_ops_zendesk'
294
+ #
295
+ # SupportOps::Zendesk::Configuration.configure do |config|
296
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
297
+ # config.username = 'jason@example.com'
298
+ # config.token = 'abc123'
299
+ # end
300
+ #
301
+ # automation1 = SupportOps::Zendesk::Automations.get!(123)
302
+ # automation1.name = 'Set severity for low priority tickets non-solved tickets'
303
+ # automation2 = SupportOps::Zendesk::Automations.get!(456)
304
+ # automation2.name = 'Set severity for medium priority tickets non-solved tickets'
305
+ #
306
+ # updates = SupportOps::Zendesk::Automations.update_many!([automation1, automation2])
307
+ # pp updates.id
308
+ # # => "82de0b044094f0c67893ac9fe64f1a99"
309
+ def self.update_many!(automations)
310
+ raise 'The parameter must be an Array' unless automations.is_a? Array
311
+ raise 'You can only update a maximum of 100 automations at a time' if automations.count > 100
312
+ raise 'You can only use SupportOps::Zendesk::Automations instances in the Array' unless automations.reject { |o| o.is_a? SupportOps::Zendesk::Automations }.count.zero?
313
+
314
+ data = { automations: automations.map { |a| to_hash(a).compact } }.to_json
315
+ response = client.connection.put('automations/update_many', data)
316
+ raise "Failed to update automations => #{body['details']}" if response.status != 200
317
+ JobStatuses.new(Oj.load(response.body)['job_status'])
318
+ end
319
+
320
+ ##
321
+ # Deletes multiple automations via a batch job
322
+ #
323
+ # @author Jason Colyer
324
+ # @since 1.0.0
325
+ # @param automation_ids [Array] An array of automation IDs
326
+ # @return [object] A {SupportOps::Zendesk::JobStatuses} instance
327
+ # @see
328
+ # https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#bulk-delete-automations
329
+ # Zendesk API > Automations > Bulk Delete Automations
330
+ # @example
331
+ # require 'support_ops_zendesk'
332
+ #
333
+ # SupportOps::Zendesk::Configuration.configure do |config|
334
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
335
+ # config.username = 'jason@example.com'
336
+ # config.token = 'abc123'
337
+ # end
338
+ #
339
+ # delete = SupportOps::Zendesk::Automations.delete_many!([123, 456])
340
+ # pp delete.id
341
+ # # => "82de0b044094f0c67893ac9fe64f1a99"
342
+ def self.delete_many!(automation_ids)
343
+ raise 'The parameter must be an Array' unless automation_ids.is_a? Array
344
+ raise 'You can only delete a maximum of 100 automations at a time' if automation_ids.count > 100
345
+
346
+ response = client.connection.delete("automations/destroy_many?ids=#{automation_ids.join(',')}")
347
+ raise "Failed to delete automations => #{body['details']}" if response.status != 200
348
+ JobStatuses.new(Oj.load(response.body)['job_status'])
349
+ end
350
+
351
+ private
352
+
353
+ ##
354
+ # @private
355
+ def get_record
356
+ response = self.client.connection.get("automations/#{self.id}")
357
+ return nil if response.status != 200
358
+
359
+ Oj.load(response.body)['automation']
360
+ end
361
+
362
+ ##
363
+ # @private
364
+ def create_record
365
+ response = self.client.connection.post("automations", { automation: attributes_for_save }.to_json)
366
+ body = Oj.load(response.body)
367
+ raise "Failed to create automation => #{body['details']}" if response.status != 201
368
+ body['automation']
369
+ end
370
+
371
+ ##
372
+ # @private
373
+ def update_record
374
+ raise "Failed to update automation => You didn't change anything in the object" if attributes_for_save.keys == [:id]
375
+ response = self.client.connection.put("automations/#{self.id}", { automation: attributes_for_save }.to_json)
376
+ body = Oj.load(response.body)
377
+ raise "Failed to update automation #{self.id} => #{body['details']}" if response.status != 200
378
+ body['automation']
379
+ end
380
+
381
+ ##
382
+ # @private
383
+ def delete_record
384
+ response = self.client.connection.delete("automations/#{self.id}")
385
+ raise "Failed to delete automation => #{body['details']}" if response.status != 204
386
+ true
387
+ end
388
+ end
389
+ end
390
+ end