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,472 @@
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 Base within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Base
13
+ class << self
14
+ def client
15
+ Configuration.config.client
16
+ end
17
+
18
+ def configure
19
+ yield Configuration.config
20
+ end
21
+
22
+ def define_attributes(*attrs)
23
+ @attributes = attrs
24
+ attrs.each do |attr|
25
+ attr_accessor attr
26
+ end
27
+ end
28
+
29
+ def attributes
30
+ @attributes || []
31
+ end
32
+
33
+ def readonly_attributes(*attrs)
34
+ return @readonly_attributes || [] if attrs.empty?
35
+
36
+ @readonly_attributes = attrs
37
+ end
38
+ end
39
+
40
+ def initialize(attributes = {}, client = nil)
41
+ @client = client
42
+ @original_attributes = {}
43
+ set_attributes(attributes)
44
+ store_original_attributes
45
+ end
46
+
47
+ def store_original_attributes
48
+ @original_attributes = {}
49
+ self.class.attributes.each do |attr|
50
+ @original_attributes[attr] = instance_variable_get("@#{attr}")
51
+ end
52
+ end
53
+
54
+ ##
55
+ # Converts an Object to a Hash
56
+ #
57
+ # @author Jason Colyer
58
+ # @since 1.0.0
59
+ # @param object [Object]
60
+ # @return [Hash]
61
+ def self.to_hash(object)
62
+ Hash[object.instance_variables.map { |name| [name.to_s[1..-1], object.instance_variable_get(name)] }]
63
+ end
64
+
65
+ def find
66
+ ensure_client_present!
67
+ set_attributes(get_record)
68
+ store_original_attributes
69
+ self
70
+ end
71
+
72
+ def find!
73
+ ensure_client_present!
74
+ attrs = get_record
75
+ if attrs == nil
76
+ if self.is_a? SupportOps::Zendesk::Translations
77
+ raise "Unable to locate #{self.class.name.demodulize.singularize.downcase} '#{self.source_id} (locale: #{self.locale})'"
78
+ else
79
+ raise "Unable to locate #{self.class.name.demodulize.singularize.downcase} '#{self.id}'"
80
+ end
81
+ end
82
+ set_attributes(attrs)
83
+ store_original_attributes
84
+ self
85
+ end
86
+
87
+ def collaborators
88
+ ensure_client_present!
89
+ collaborators_record
90
+ end
91
+
92
+ def followers
93
+ ensure_client_present!
94
+ followers_record
95
+ end
96
+
97
+ def ccs
98
+ ensure_client_present!
99
+ ccs_record
100
+ end
101
+
102
+ def comments
103
+ ensure_client_present!
104
+ comments_record
105
+ end
106
+
107
+ def mark_as_spam!
108
+ ensure_client_present!
109
+ mark_as_spam_record
110
+ end
111
+
112
+ def incidents
113
+ ensure_client_present!
114
+ incidents_record
115
+ end
116
+
117
+ def redact_attachments!
118
+ ensure_client_present!
119
+ redact_attachments_record
120
+ end
121
+
122
+ def save!
123
+ ensure_client_present!
124
+ new_data = if id.nil?
125
+ create_record
126
+ else
127
+ update_record
128
+ end
129
+ if self.is_a? SupportOps::Zendesk::Themes
130
+ new_data
131
+ else
132
+ new_data.each do |key, value|
133
+ self.instance_variable_set("@#{key}", value) if self.respond_to?("#{key}=")
134
+ end
135
+ store_original_attributes
136
+ self
137
+ end
138
+ end
139
+
140
+ def delete!
141
+ ensure_client_present!
142
+ delete_record
143
+ end
144
+
145
+ def create_or_update!
146
+ ensure_client_present!
147
+ new_data = create_or_update_record
148
+ store_original_attributes
149
+ new_data.each do |key, value|
150
+ self.instance_variable_set("@#{key}", value) if self.respond_to?("#{key}=")
151
+ end
152
+ self
153
+ end
154
+
155
+ def tickets
156
+ ensure_client_present!
157
+ tickets_record
158
+ end
159
+
160
+ def ccd_tickets
161
+ ensure_client_present!
162
+ ccd_ticket_record
163
+ end
164
+
165
+ def assigned_tickets
166
+ ensure_client_present!
167
+ assigned_ticket_record
168
+ end
169
+
170
+ def organization
171
+ ensure_client_present!
172
+ organization_record
173
+ end
174
+
175
+ def organizations
176
+ ensure_client_present!
177
+ organizations_record
178
+ end
179
+
180
+ def memberships
181
+ ensure_client_present!
182
+ memberships_record
183
+ end
184
+
185
+ def organization_memberships
186
+ ensure_client_present!
187
+ organization_memberships_record
188
+ end
189
+
190
+ def group_memberships
191
+ ensure_client_present!
192
+ group_memberships_record
193
+ end
194
+
195
+ def groups
196
+ ensure_client_present!
197
+ groups_record
198
+ end
199
+
200
+ def set_password!
201
+ ensure_client_present!
202
+ set_password_record
203
+ end
204
+
205
+ def users
206
+ ensure_client_present!
207
+ users_record
208
+ end
209
+
210
+ def make_default!
211
+ ensure_client_present!
212
+ make_default_record
213
+ end
214
+
215
+ def create_satisfaction_score!(**args)
216
+ ensure_client_present!
217
+ create_satisfaction_score_record(**args)
218
+ end
219
+
220
+ def wait_for_completetion(**args)
221
+ ensure_client_present!
222
+ new_data = wait_for_completetion_record(**args)
223
+ store_original_attributes
224
+ new_data.each do |key, value|
225
+ self.instance_variable_set("@#{key}", value) if self.respond_to?("#{key}=")
226
+ end
227
+ self
228
+ end
229
+
230
+ def preview!
231
+ ensure_client_present!
232
+ preview_record
233
+ end
234
+
235
+ def holidays
236
+ ensure_client_present!
237
+ holidays_record
238
+ end
239
+
240
+ def category
241
+ ensure_client_present!
242
+ category_record
243
+ end
244
+
245
+ def clone!
246
+ ensure_client_present!
247
+ clone_record
248
+ end
249
+
250
+ def field_options
251
+ ensure_client_present!
252
+ field_options_record
253
+ end
254
+
255
+ def item_variants
256
+ ensure_client_present!
257
+ item_variants_record
258
+ end
259
+
260
+ def parent
261
+ ensure_client_present!
262
+ parent_record
263
+ end
264
+
265
+ def translations
266
+ ensure_client_present!
267
+ translations_record
268
+ end
269
+
270
+ def public_key
271
+ ensure_client_present!
272
+ public_key_record
273
+ end
274
+
275
+ def web_url
276
+ web_url_record
277
+ end
278
+
279
+ def client=(new_client)
280
+ @client = new_client
281
+ end
282
+
283
+ protected
284
+
285
+ attr_reader :attributes, :original_attributes
286
+
287
+ def set_attributes(attributes)
288
+ return unless attributes
289
+
290
+ attrs = attributes.transform_keys(&:to_sym)
291
+
292
+ self.class.attributes.each do |attr|
293
+ instance_variable_set("@#{attr}", attrs[attr])
294
+ end
295
+ end
296
+
297
+ def attributes_for_save
298
+ if send(:id) == nil
299
+ self.class.attributes
300
+ .reject { |attr| self.class.readonly_attributes.include?(attr) }
301
+ .each_with_object({}) do |attr, hash|
302
+ hash[attr] = send(attr)
303
+ end
304
+ else
305
+ self.class.attributes
306
+ .reject { |attr| self.class.readonly_attributes.include?(attr) }
307
+ .each_with_object({}) do |attr, hash|
308
+ current_value = send(attr)
309
+ original_value = @original_attributes[attr]
310
+
311
+ hash[attr] = current_value if attr == :id
312
+ if original_value != current_value
313
+ hash[attr] = current_value
314
+ end
315
+ end
316
+ end
317
+ end
318
+
319
+ def client
320
+ @client ||= self.class.client
321
+ end
322
+
323
+ def ensure_client_present!
324
+ raise 'No client configured. Use SupportOps::Zendesk.configure to set up the client.' unless client
325
+ end
326
+
327
+ def get_record(**args)
328
+ raise NotImplementedError
329
+ end
330
+
331
+ def create_record
332
+ raise NotImplementedError
333
+ end
334
+
335
+ def update_record
336
+ raise NotImplementedError
337
+ end
338
+
339
+ def delete_record
340
+ raise NotImplementedError
341
+ end
342
+
343
+ def collaborators_record
344
+ raise NotImplementedError
345
+ end
346
+
347
+ def followers_record
348
+ raise NotImplementedError
349
+ end
350
+
351
+ def ccs_record
352
+ raise NotImplementedError
353
+ end
354
+
355
+ def comments_record
356
+ raise NotImplementedError
357
+ end
358
+
359
+ def mark_as_spam_record
360
+ raise NotImplementedError
361
+ end
362
+
363
+ def incidents_record
364
+ raise NotImplementedError
365
+ end
366
+
367
+ def redact_attachments_record
368
+ raise NotImplementedError
369
+ end
370
+
371
+ def create_or_update_record
372
+ raise NotImplementedError
373
+ end
374
+
375
+ def tickets_record
376
+ raise NotImplementedError
377
+ end
378
+
379
+ def ccd_ticket_record
380
+ raise NotImplementedError
381
+ end
382
+
383
+ def assigned_ticket_record
384
+ raise NotImplementedError
385
+ end
386
+
387
+ def organization_record
388
+ raise NotImplementedError
389
+ end
390
+
391
+ def memberships_record
392
+ raise NotImplementedError
393
+ end
394
+
395
+ def organization_memberships_record
396
+ raise NotImplementedError
397
+ end
398
+
399
+ def group_memberships_record
400
+ raise NotImplementedError
401
+ end
402
+
403
+ def set_password_record
404
+ raise NotImplementedError
405
+ end
406
+
407
+ def organizations_record
408
+ raise NotImplementedError
409
+ end
410
+
411
+ def groups_record
412
+ raise NotImplementedError
413
+ end
414
+
415
+ def users_record
416
+ raise NotImplementedError
417
+ end
418
+
419
+ def make_default_record
420
+ raise NotImplementedError
421
+ end
422
+
423
+ def wait_for_completetion_record(**args)
424
+ raise NotImplementedError
425
+ end
426
+
427
+ def create_satisfaction_score_record(**args)
428
+ raise NotImplementedError
429
+ end
430
+
431
+ def preview_record
432
+ raise NotImplementedError
433
+ end
434
+
435
+ def holidays_record
436
+ raise NotImplementedError
437
+ end
438
+
439
+ def category_record
440
+ raise NotImplementedError
441
+ end
442
+
443
+ def clone_record
444
+ raise NotImplementedError
445
+ end
446
+
447
+ def field_options_record
448
+ raise NotImplementedError
449
+ end
450
+
451
+ def item_variants_record
452
+ raise NotImplementedError
453
+ end
454
+
455
+ def parent_record
456
+ raise NotImplementedError
457
+ end
458
+
459
+ def translations_record
460
+ raise NotImplementedError
461
+ end
462
+
463
+ def public_key_record
464
+ raise NotImplementedError
465
+ end
466
+
467
+ def web_url_record
468
+ raise NotImplementedError
469
+ end
470
+ end
471
+ end
472
+ end
@@ -0,0 +1,172 @@
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 Brands within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Boolean] active If the brand is set as active
13
+ # @attr [String] brand_url The url of the brand
14
+ # @attr [String] created_at The time the brand was created
15
+ # @attr [Boolean] default Is the brand the default brand for this account
16
+ # @attr [Boolean] has_help_center If the brand has a Help Center
17
+ # @attr [String] help_center_state The state of the Help Center. Allowed values are "enabled", "disabled", or "restricted".
18
+ # @attr [String] host_mapping The hostmapping to this brand, if any. Only admins view this property.
19
+ # @attr [Integer] id The ID automatically assigned when the brand is created
20
+ # @attr [Boolean] is_deleted If the brand object is deleted or not
21
+ # @attr [Hash] logo A file represented as an Attachment object
22
+ # @attr [String] name The name of the brand
23
+ # @attr [String] signature_template The signature template for a brand
24
+ # @attr [String] subdomain The subdomain of the brand
25
+ # @attr [Array] ticket_form_ids The ids of ticket forms that are available for use by a brand
26
+ # @attr [String] updated_at The time of the last update of the brand
27
+ # @todo Create brand => https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#create-brand
28
+ # @todo Update a Brand => https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#update-a-brand
29
+ # @todo Delete a Brand => https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#delete-a-brand
30
+ # @todo Check Host Mapping Validity => https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#check-host-mapping-validity
31
+ # @todo Check Host Mapping Validity for an Existing Brand => https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#check-host-mapping-validity-for-an-existing-brand
32
+ class Brands < SupportOps::Zendesk::Base
33
+ define_attributes :active, :brand_url, :created_at, :default,
34
+ :has_help_center, :help_center_state, :host_mapping,
35
+ :id, :is_deleted, :logo, :name, :signature_template,
36
+ :subdomain, :ticket_form_ids, :updated_at
37
+ readonly_attributes :created_at, :help_center_state, :id,
38
+ :ticket_form_ids, :updated_at
39
+
40
+ ##
41
+ # Lists all brands in the Zendesk system
42
+ #
43
+ # @author Jason Colyer
44
+ # @since 1.0.0
45
+ # @return [Array]
46
+ # @see
47
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#list-brands
48
+ # Zendesk API > Brands > List Brands
49
+ # @see SupportOps::Zendesk::Configuration Setting up a client
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
+ # end
58
+ #
59
+ # brands = SupportOps::Zendesk::Brands.list
60
+ # pp brands.last.name
61
+ # # => "Billing"
62
+ def self.list
63
+ response = client.connection.get('brands?page[size]=100')
64
+ Oj.load(response.body)['brands'].map { |b| Brands.new(b) }
65
+ end
66
+
67
+ ##
68
+ # Locates a brand within Zendesk by name. Can utilize a cache for quicker results
69
+ #
70
+ # @author Jason Colyer
71
+ # @since 1.0.0
72
+ # @overload find_by_name(key: value)
73
+ # @param name [String required] The name to search for
74
+ # @param cache [Array] An Array of SupportOps::Zendesk::Brands to use as a cache
75
+ # @return [Object] An instance of {SupportOps::Zendesk::Brands}
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
+ # brands = SupportOps::Zendesk::Brands.list
86
+ # brand = SupportOps::Zendesk::Brands.find_by_name(name: 'Billing', cache: brands)
87
+ # pp brand.name
88
+ # # => "Billing"
89
+ # pp brand.id
90
+ # # => 123456
91
+ def self.find_by_name(**args)
92
+ raise 'You have to provide a name' unless args[:name]
93
+ if args[:cache]
94
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
95
+ brands = args[:cache]
96
+ else
97
+ brands = list
98
+ end
99
+ brands.detect { |c| c.name.downcase == args[:name].to_s.downcase }
100
+ end
101
+
102
+ ##
103
+ # Locates a specific group in the Zendesk system
104
+ #
105
+ # @author Jason Colyer
106
+ # @since 1.0.0
107
+ # @see
108
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#show-a-brand
109
+ # Zendesk API > Brands > Show a Brand
110
+ # @see SupportOps::Zendesk::Configuration Setting up a client
111
+ # @example
112
+ # require 'support_ops_zendesk'
113
+ #
114
+ # SupportOps::Zendesk::Configuration.configure do |config|
115
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
116
+ # config.username = 'jason@example.com'
117
+ # config.token = 'abc123'
118
+ # end
119
+ #
120
+ # brand = SupportOps::Zendesk::Brands.get(123456)
121
+ # pp brand.name
122
+ # # => "Billing"
123
+ def self.get(object)
124
+ if object.is_a? Brands
125
+ Brands.new(id: id).find
126
+ else
127
+ Brands.new(id: object).find
128
+ end
129
+ end
130
+
131
+ ##
132
+ # Locates a specific group in the Zendesk system
133
+ #
134
+ # @author Jason Colyer
135
+ # @since 1.0.0
136
+ # @see
137
+ # https://developer.zendesk.com/api-reference/ticketing/account-configuration/brands/#show-a-brand
138
+ # Zendesk API > Brands > Show a Brand
139
+ # @see SupportOps::Zendesk::Configuration Setting up a client
140
+ # @example
141
+ # require 'support_ops_zendesk'
142
+ #
143
+ # SupportOps::Zendesk::Configuration.configure do |config|
144
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
145
+ # config.username = 'jason@example.com'
146
+ # config.token = 'abc123'
147
+ # end
148
+ #
149
+ # brand = SupportOps::Zendesk::Brands.get!(123456)
150
+ # pp brand.name
151
+ # # => "Billing"
152
+ def self.get!(object)
153
+ if object.is_a? Brands
154
+ Brands.new(id: id).find!
155
+ else
156
+ Brands.new(id: object).find!
157
+ end
158
+ end
159
+
160
+ private
161
+
162
+ ##
163
+ # @private
164
+ def get_record
165
+ response = self.client.connection.get("brands/#{self.id}")
166
+ return nil if response.status != 200
167
+
168
+ Oj.load(response.body)['brand']
169
+ end
170
+ end
171
+ end
172
+ end