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,568 @@
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 Organizations within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at The time the organization was created
13
+ # @attr [String] details Any details obout the organization, such as the address
14
+ # @attr [Array] domain_names An array of domain names associated with this organization
15
+ # @attr [String] external_id A unique external id to associate organizations to an external record
16
+ # @attr [Integer] group_id New tickets from users in this organization are automatically put in this group
17
+ # @attr [Integer] id Automatically assigned when the organization is created
18
+ # @attr [String] name A unique name for the organization
19
+ # @attr [String] notes Any notes you have about the organization
20
+ # @attr [Array] organization_fields Custom fields for this organization
21
+ # @attr [Boolean] shared_comments End users in this organization are able to comment on each other's tickets
22
+ # @attr [Boolean] shared_tickets End users in this organization are able to see each other's tickets
23
+ # @attr [Array] tags The tags of the organization
24
+ # @attr [String] updated_at The time of the last update of the organization
25
+ # @todo Show Organization's Related Information => https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information
26
+ # @todo Merge Organization With Another Organization => https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#merge-organization-with-another-organization
27
+ # @todo Show Organization Merge => https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization-merge
28
+ # @todo List Organization Merges => https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organization-merges
29
+ class Organizations < SupportOps::Zendesk::Base
30
+ # @!parse
31
+ # # Creates/updates an organization
32
+ # #
33
+ # # @author Jason Colyer
34
+ # # @since 1.0.0
35
+ # # @return [Object] Instance of {SupportOps::Zendesk::Organizations}
36
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
37
+ # # @see
38
+ # # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization
39
+ # # Zendesk API > Organizations > Create Organization
40
+ # # @see
41
+ # # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization
42
+ # # Zendesk API > Organizations > Update Organization
43
+ # # @example
44
+ # # require 'support_ops_zendesk'
45
+ # #
46
+ # # SupportOps::Zendesk::Configuration.configure do |config|
47
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
48
+ # # config.username = 'jason@example.com'
49
+ # # config.token = 'abc123'
50
+ # # end
51
+ # #
52
+ # # new_org = SupportOps::Zendesk::Organizations.new
53
+ # # new_org.name = 'My Organization'
54
+ # #
55
+ # # new_org.save!
56
+ # #
57
+ # # pp new_org.id
58
+ # # # => 23409462
59
+ # # @example
60
+ # # require 'support_ops_zendesk'
61
+ # #
62
+ # # SupportOps::Zendesk::Configuration.configure do |config|
63
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
64
+ # # config.username = 'jason@example.com'
65
+ # # config.token = 'abc123'
66
+ # # end
67
+ # #
68
+ # # existing_org = SupportOps::Zendesk::Organizations.get!(23409462)
69
+ # # existing_org.notes = 'Something interesting'
70
+ # #
71
+ # # existing_org.save!
72
+ # #
73
+ # # pp existing_org.name
74
+ # # # => "My Organization"
75
+ # def save!; end
76
+ # @!parse
77
+ # # Deletes an organization
78
+ # #
79
+ # # @author Jason Colyer
80
+ # # @since 1.0.0
81
+ # # @return [Boolean]
82
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
83
+ # # @see
84
+ # # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#delete-organization
85
+ # # Zendesk API > Organizations > Delete Organization
86
+ # # @example
87
+ # # require 'support_ops_zendesk'
88
+ # #
89
+ # # SupportOps::Zendesk::Configuration.configure do |config|
90
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
91
+ # # config.username = 'jason@example.com'
92
+ # # config.token = 'abc123'
93
+ # # end
94
+ # #
95
+ # # existing_org = SupportOps::Zendesk::Organizations.get!(23409462)
96
+ # # existing_org.delete!
97
+ # def delete!; end
98
+ # @!parse
99
+ # # Creates or updates an organization
100
+ # #
101
+ # # @author Jason Colyer
102
+ # # @since 1.0.0
103
+ # # @return [Object]
104
+ # # @note This is inherited from {SupportOps::Zendesk::Base#create_or_update!}
105
+ # # @see
106
+ # # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization
107
+ # # Zendesk API > Organizations > Create Or Update Organization
108
+ # # @example
109
+ # # require 'support_ops_zendesk'
110
+ # #
111
+ # # SupportOps::Zendesk::Configuration.configure do |config|
112
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
113
+ # # config.username = 'jason@example.com'
114
+ # # config.token = 'abc123'
115
+ # # end
116
+ # #
117
+ # # existing_org = SupportOps::Zendesk::Organizations.get!(123)
118
+ # # existing_org.name = 'My Organization'
119
+ # #
120
+ # # existing_org.create_or_update!
121
+ # #
122
+ # # pp existing_org.name
123
+ # # # => "My Organization"
124
+ # def create_or_update!; end
125
+ # @!parse
126
+ # # Lists organization memberships
127
+ # #
128
+ # # @author Jason Colyer
129
+ # # @since 1.0.0
130
+ # # @return [Object]
131
+ # # @note This is inherited from {SupportOps::Zendesk::Base#memberships}
132
+ # # @see
133
+ # # https://developer.zendesk.com/api-reference/ticketing/organizations/organization_memberships/#list-memberships
134
+ # # Zendesk API > Organization Memberships > List Memberships
135
+ # # @example
136
+ # # require 'support_ops_zendesk'
137
+ # #
138
+ # # SupportOps::Zendesk::Configuration.configure do |config|
139
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
140
+ # # config.username = 'jason@example.com'
141
+ # # config.token = 'abc123'
142
+ # # end
143
+ # #
144
+ # # existing_org = SupportOps::Zendesk::Organizations.get!(123)
145
+ # # memberships = existing_org.memberships
146
+ # #
147
+ # # pp memberships.first.user_id
148
+ # # # => 29
149
+ # def memberships; end
150
+ # @!parse
151
+ # # Lists organization tickets
152
+ # #
153
+ # # @author Jason Colyer
154
+ # # @since 1.0.0
155
+ # # @return [Object]
156
+ # # @note This is inherited from {SupportOps::Zendesk::Base#tickets}
157
+ # # @see
158
+ # # https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#list-tickets
159
+ # # Zendesk API > Tickets > List Tickets
160
+ # # @example
161
+ # # require 'support_ops_zendesk'
162
+ # #
163
+ # # SupportOps::Zendesk::Configuration.configure do |config|
164
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
165
+ # # config.username = 'jason@example.com'
166
+ # # config.token = 'abc123'
167
+ # # end
168
+ # #
169
+ # # existing_org = SupportOps::Zendesk::Organizations.get!(16)
170
+ # # tickets = existing_org.tickets
171
+ # #
172
+ # # pp tickets.first.status
173
+ # # # => "pending"
174
+ # def tickets; end
175
+ # @!parse
176
+ # # Lists organization users
177
+ # #
178
+ # # @author Jason Colyer
179
+ # # @since 1.0.0
180
+ # # @return [Object]
181
+ # # @note This is inherited from {SupportOps::Zendesk::Base#users}
182
+ # # @see
183
+ # # https://developer.zendesk.com/api-reference/ticketing/users/users/#list-users
184
+ # # Zendesk API > USers > List Users
185
+ # # @example
186
+ # # require 'support_ops_zendesk'
187
+ # #
188
+ # # SupportOps::Zendesk::Configuration.configure do |config|
189
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
190
+ # # config.username = 'jason@example.com'
191
+ # # config.token = 'abc123'
192
+ # # end
193
+ # #
194
+ # # existing_org = SupportOps::Zendesk::Organizations.get!(16)
195
+ # # users = existing_org.users
196
+ # #
197
+ # # pp users.count
198
+ # # # => 28
199
+ # def users; end
200
+ define_attributes :created_at, :details, :domain_names, :external_id,
201
+ :group_id, :id, :name, :notes, :organization_fields,
202
+ :shared_comments, :shared_tickets, :tags, :updated_at
203
+ readonly_attributes :created_at, :id, :updated_at
204
+
205
+ ##
206
+ # Returns an approximate count of organizations in the account. If the count exceeds 100,000, it is updated every 24 hours.
207
+ #
208
+ # @author Jason Colyer
209
+ # @since 1.0.0
210
+ # @return [Hash]
211
+ # @see
212
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#count-organizations
213
+ # Zendesk API > Organizations > Count Organizations
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
+ # orgs = SupportOps::Zendesk::Organizations.count
225
+ # pp orgs['value']
226
+ # # => 102
227
+ def self.count
228
+ response = client.connection.get('organizations/count')
229
+ Oj.load(response.body)['count']
230
+ end
231
+
232
+ ##
233
+ # Lists organizations in the Zendesk system
234
+ #
235
+ # @author Jason Colyer
236
+ # @since 1.0.0
237
+ # @overload list(key: value)
238
+ # @param limit [Integer optional] The limit to the number of
239
+ # organizations returned. Default to 0 (i.e. no limit)
240
+ # @return [Array]
241
+ # @see
242
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations
243
+ # Zendesk API > Organizations > List Organizations
244
+ # @see SupportOps::Zendesk::Configuration Setting up a client
245
+ # @example
246
+ # require 'support_ops_zendesk'
247
+ #
248
+ # SupportOps::Zendesk::Configuration.configure do |config|
249
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
250
+ # config.username = 'jason@example.com'
251
+ # config.token = 'abc123'
252
+ # end
253
+ #
254
+ # orgs = SupportOps::Zendesk::Organizations.list(limit: 250)
255
+ # pp orgs.count
256
+ # # => 250
257
+ # pp orgs.last.name
258
+ # # => "I'm the 250th organization"
259
+ def self.list(**args)
260
+ args[:limit] = 0 unless args[:limit]
261
+ orgs = []
262
+ opts = 'page[size]=100'
263
+ loop do
264
+ response = client.connection.get("organizations?#{opts}")
265
+ body = Oj.load(response.body)
266
+ orgs += body['organizations'].map { |o| Organizations.new(o) }
267
+ break if args[:limit].to_i.positive? && orgs.count >= args[:limit].to_i
268
+ break unless body['meta']['has_more']
269
+
270
+ opts = body['links']['next'].split('?').last
271
+ end
272
+ return orgs if args[:limit].to_i.zero?
273
+
274
+ orgs.first(args[:limit].to_i)
275
+ end
276
+
277
+ ##
278
+ # Locates a specific organization in the Zendesk system
279
+ #
280
+ # @author Jason Colyer
281
+ # @since 1.0.0
282
+ # @see
283
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization
284
+ # Zendesk API > Organizations > Show Organization
285
+ # @see SupportOps::Zendesk::Configuration Setting up a client
286
+ # @example
287
+ # require 'support_ops_zendesk'
288
+ #
289
+ # SupportOps::Zendesk::Configuration.configure do |config|
290
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
291
+ # config.username = 'jason@example.com'
292
+ # config.token = 'abc123'
293
+ # end
294
+ #
295
+ # org = SupportOps::Zendesk::Organizations.get(250)
296
+ # pp org.name
297
+ # # => "I'm the 250th organization"
298
+ def self.get(object)
299
+ if object.is_a? Organizations
300
+ Organizations.new(id: id).find
301
+ else
302
+ Organizations.new(id: object).find
303
+ end
304
+ end
305
+
306
+ ##
307
+ # Locates a specific organization in the Zendesk system
308
+ #
309
+ # @author Jason Colyer
310
+ # @since 1.0.0
311
+ # @see
312
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization
313
+ # Zendesk API > Organizations > Show Organization
314
+ # @see SupportOps::Zendesk::Configuration Setting up a client
315
+ # @example
316
+ # require 'support_ops_zendesk'
317
+ #
318
+ # SupportOps::Zendesk::Configuration.configure do |config|
319
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
320
+ # config.username = 'jason@example.com'
321
+ # config.token = 'abc123'
322
+ # end
323
+ #
324
+ # org = SupportOps::Zendesk::Organizations.get!(250)
325
+ # pp org.name
326
+ # # => "I'm the 250th organization"
327
+ def self.get!(object)
328
+ if object.is_a? Organizations
329
+ Organizations.new(id: id).find!
330
+ else
331
+ Organizations.new(id: object).find!
332
+ end
333
+ end
334
+
335
+ ##
336
+ # Locates up to 100 organizations within Zendesk.
337
+ #
338
+ # @author Jason Colyer
339
+ # @since 1.0.0
340
+ # @param organization_ids [Array] The organization IDs to find
341
+ # @return [Array]
342
+ # @see
343
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations
344
+ # Zendesk API > Organizations > Show Many Organizations
345
+ # @example
346
+ # require 'support_ops_zendesk'
347
+ #
348
+ # SupportOps::Zendesk::Configuration.configure do |config|
349
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
350
+ # config.username = 'jason@example.com'
351
+ # config.token = 'abc123'
352
+ # end
353
+ #
354
+ # orgs = SupportOps::Zendesk::Organizations.get_many([255, 256])
355
+ # pp orgs.map { |t| t.name }
356
+ # # => ["Org 255", "256th Org"]
357
+ def self.get_many(organization_ids)
358
+ raise 'The parameter must be an Array' unless organization_ids.is_a? Array
359
+ raise 'You can only get a maximum of 100 organizations at a time' if organization_ids.count > 100
360
+
361
+ response = client.connection.get("organizations/show_many?ids=#{organization_ids.join(',')}")
362
+ Oj.load(response.body)['organizations'].map { |o| Organizations.new(o) }
363
+ end
364
+
365
+ ##
366
+ # Deletes multiple organizations via a batch job
367
+ #
368
+ # @author Jason Colyer
369
+ # @since 1.0.0
370
+ # @param organization_ids [Array] An array of organization IDs
371
+ # @return [object] A {SupportOps::Zendesk::JobStatuses} instance
372
+ # @see
373
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#bulk-delete-organizations
374
+ # Zendesk API > Organizations > Bulk Delete Organizations
375
+ # @example
376
+ # require 'support_ops_zendesk'
377
+ #
378
+ # SupportOps::Zendesk::Configuration.configure do |config|
379
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
380
+ # config.username = 'jason@example.com'
381
+ # config.token = 'abc123'
382
+ # end
383
+ #
384
+ # delete = SupportOps::Zendesk::Organizations.delete_many!([123, 456])
385
+ # pp delete.id
386
+ # # => "82de0b044094f0c67893ac9fe64f1a99"
387
+ def self.delete_many!(organization_ids)
388
+ raise 'The parameter must be an Array' unless organization_ids.is_a? Array
389
+ raise 'You can only delete a maximum of 100 organizations at a time' if organization_ids.count > 100
390
+
391
+ response = client.connection.delete("organizations/destroy_many?ids=#{organization_ids.join(',')}")
392
+ raise "Failed to delete organizations => #{body['details']}" if response.status != 200
393
+ JobStatuses.new(Oj.load(response.body)['job_status'])
394
+ end
395
+
396
+ ##
397
+ # Creates multiple organizations via a batch job
398
+ #
399
+ # @author Jason Colyer
400
+ # @since 1.0.0
401
+ # @param organizations [Array] An array of {SupportOps::Zendesk::Organizations} instances
402
+ # @return [object] A {SupportOps::Zendesk::JobStatuses} instance
403
+ # @see
404
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-many-organizations
405
+ # Zendesk API > Organizations > Create Many Organizations
406
+ # @example
407
+ # require 'support_ops_zendesk'
408
+ #
409
+ # SupportOps::Zendesk::Configuration.configure do |config|
410
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
411
+ # config.username = 'jason@example.com'
412
+ # config.token = 'abc123'
413
+ # end
414
+ #
415
+ # org1 = SupportOps::Zendesk::Organizations.new
416
+ # org1.name = 'Org for Alice'
417
+ # org2 = SupportOps::Zendesk::Organizations.new
418
+ # org2.name = 'Org for Bob'
419
+ #
420
+ # creates = SupportOps::Zendesk::Organizations.create_many!([org1, org2])
421
+ # pp creates.id
422
+ # # => "82de0b044094f0c67893ac9fe64f1a99"
423
+ def self.create_many!(organizations)
424
+ raise 'The parameter must be an Array' unless organizations.is_a? Array
425
+ raise 'You can only create a maximum of 100 organizations at a time' if organizations.count > 100
426
+ raise 'You can only use SupportOps::Zendesk::Organizations instances in the Array' unless organizations.reject { |o| o.is_a? SupportOps::Zendesk::Organizations }.count.zero?
427
+
428
+ data = { organizations: organizations.map { |o| to_hash(o).compact } }.to_json
429
+ response = client.connection.post('organizations/create_many', data)
430
+ raise "Failed to create organizations => #{body['details']}" if response.status != 200
431
+ JobStatuses.new(Oj.load(response.body)['job_status'])
432
+ end
433
+
434
+ ##
435
+ # Updates multiple organizations via a batch job
436
+ #
437
+ # @author Jason Colyer
438
+ # @since 1.0.0
439
+ # @param organizations [Array] An array of {SupportOps::Zendesk::Organizations} instances
440
+ # @return [object] A {SupportOps::Zendesk::JobStatuses} instance
441
+ # @see
442
+ # https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-many-organizations
443
+ # Zendesk API > Organizations > Update Many Organizations
444
+ # @example
445
+ # require 'support_ops_zendesk'
446
+ #
447
+ # SupportOps::Zendesk::Configuration.configure do |config|
448
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
449
+ # config.username = 'jason@example.com'
450
+ # config.token = 'abc123'
451
+ # end
452
+ #
453
+ # org1 = SupportOps::Zendesk::Organizations.get!(123)
454
+ # org1.name = 'Org for Alice Company'
455
+ # org2 = SupportOps::Zendesk::Organizations.get!(456)
456
+ # org2.name = 'Org for Bob Company'
457
+ #
458
+ # updates = SupportOps::Zendesk::Organizations.update_many!([org1, org2])
459
+ # pp updates.id
460
+ # # => "82de0b044094f0c67893ac9fe64f1a99"
461
+ def self.update_many!(organizations)
462
+ raise 'The parameter must be an Array' unless organizations.is_a? Array
463
+ raise 'You can only update a maximum of 100 organizations at a time' if organizations.count > 100
464
+ raise 'You can only use SupportOps::Zendesk::Organizations instances in the Array' unless organizations.reject { |o| o.is_a? SupportOps::Zendesk::Organizations }.count.zero?
465
+
466
+ data = { organizations: organizations.map { |o| to_hash(o).compact } }.to_json
467
+ response = client.connection.put('organizations/update_many', data)
468
+ raise "Failed to update organizations => #{body['details']}" if response.status != 200
469
+ JobStatuses.new(Oj.load(response.body)['job_status'])
470
+ end
471
+
472
+ private
473
+
474
+ ##
475
+ # @private
476
+ def get_record
477
+ response = self.client.connection.get("organizations/#{self.id}")
478
+ return nil if response.status != 200
479
+
480
+ Oj.load(response.body)['organization']
481
+ end
482
+
483
+ ##
484
+ # @private
485
+ def create_record
486
+ response = self.client.connection.post("organizations", { organization: attributes_for_save }.to_json)
487
+ body = Oj.load(response.body)
488
+ raise "Failed to create organization => #{body['details']}" if response.status != 201
489
+ body['organization']
490
+ end
491
+
492
+ ##
493
+ # @private
494
+ def update_record
495
+ raise "Failed to update organization => You didn't change anything in the object" if attributes_for_save.keys == [:id]
496
+ response = self.client.connection.put("organizations/#{self.id}", { organization: attributes_for_save }.to_json)
497
+ body = Oj.load(response.body)
498
+ raise "Failed to update organization #{self.id} => #{body['details']}" if response.status != 200
499
+ body['organization']
500
+ end
501
+
502
+ ##
503
+ # @private
504
+ def delete_record
505
+ response = self.client.connection.delete("organizations/#{self.id}")
506
+ raise "Failed to delete organization => #{body['details']}" if response.status != 204
507
+ true
508
+ end
509
+
510
+ ##
511
+ # @private
512
+ def create_or_update_record
513
+ response = self.client.connection.post('organizations/create_or_update', { organization: attributes_for_save }.to_json)
514
+ body = Oj.load(response.body)
515
+ raise "Failed to create or update organization => #{body['details']}" unless [200, 201].include?(response.status)
516
+ body['organization']
517
+ end
518
+
519
+ ##
520
+ # @private
521
+ def memberships_record
522
+ memberships_list = []
523
+ opts = 'page[size]=100'
524
+ loop do
525
+ response = client.connection.get("organizations/#{self.id}/organization_memberships?#{opts}")
526
+ body = Oj.load(response.body)
527
+ memberships_list += body['organization_memberships'].map { |o| OrganizationMemberships.new(o) }
528
+ break unless body['meta']['has_more']
529
+
530
+ opts = body['links']['next'].split('?').last
531
+ end
532
+ memberships_list
533
+ end
534
+
535
+ ##
536
+ # @private
537
+ def tickets_record
538
+ tickets_list = []
539
+ opts = 'page[size]=100'
540
+ loop do
541
+ response = self.client.connection.get("organizations/#{self.id}/tickets?#{opts}")
542
+ body = Oj.load(response.body)
543
+ tickets_list += body['tickets'].map { |t| Tickets.new(t) }
544
+ break unless body['meta']['has_more']
545
+
546
+ opts = body['links']['next'].split('?').last
547
+ end
548
+ tickets_list
549
+ end
550
+
551
+ ##
552
+ # @private
553
+ def users_record
554
+ user_list = []
555
+ opts = 'page[size]=100'
556
+ loop do
557
+ response = self.client.connection.get("organizations/#{self.id}/users?#{opts}")
558
+ body = Oj.load(response.body)
559
+ user_list += body['users'].map { |u| Users.new(u) }
560
+ break unless body['meta']['has_more']
561
+
562
+ opts = body['links']['next'].split('?').last
563
+ end
564
+ user_list
565
+ end
566
+ end
567
+ end
568
+ end
@@ -0,0 +1,58 @@
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 RequesterRoles within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Various] id The identifer of the object
13
+ # @attr [String] name The name of the requester role
14
+ class RequesterRoles < SupportOps::Zendesk::Base
15
+ define_attributes :id, :name
16
+ readonly_attributes :id, :name
17
+
18
+ ##
19
+ # Lists requester roles
20
+ #
21
+ # @author Jason Colyer
22
+ # @since 1.0.0
23
+ # @param client [Object] An instance of {SupportOps::Zendesk::Client}
24
+ # @return [Array]
25
+ # @example
26
+ # require 'support_ops_zendesk'
27
+ # requester_roles = SupportOps::Zendesk::RequesterRoles.list
28
+ # pp requester_roles.first.name
29
+ # # => "Agent"
30
+ def self.list
31
+ [
32
+ { 'id' => 4, 'name' => 'Agent' },
33
+ { 'id' => 'LIGHT_AGENT', 'name' => 'Light Agent' },
34
+ { 'id' => 0, 'name' => 'End User' },
35
+ { 'id' => 2, 'name' => 'Admin' }
36
+ ].map { |r| RequesterRoles.new(r) }
37
+ end
38
+
39
+ ##
40
+ # Locates a requester roles within Zendesk by name
41
+ #
42
+ # @author Jason Colyer
43
+ # @since 1.0.0
44
+ # @overload find_by_name(key: value)
45
+ # @param name [String required] The name to search for
46
+ # @return [Object] An instance of {SupportOps::Zendesk::ViaTypes}
47
+ # @example
48
+ # require 'support_ops_zendesk'
49
+ # requester_role = SupportOps::Zendesk::RequesterRoles.find_by_name('Light Agent')
50
+ # pp requester_role.id
51
+ # # => "LIGHT_AGENT"
52
+ def self.find_by_name(**args)
53
+ raise 'You have to provide a name' unless args[:name]
54
+ list.detect { |r| r.name.downcase == name.downcase }
55
+ end
56
+ end
57
+ end
58
+ end