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,312 @@
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 UserFields within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Boolean] active If true, this field is available for use
13
+ # @attr [String] created_at The time of the last update of the ticket field
14
+ # @attr [Array] custom_field_options Required and presented for a custom field of type "dropdown"; each option is represented by an object with a name and value property
15
+ # @attr [String] description User-defined description of this field's purpose
16
+ # @attr [Integer] id Automatically assigned upon creation
17
+ # @attr [String] key A unique key that identifies this custom field; this is used for updating the field and referencing in placeholders; the key must consist of only letters, numbers, and underscores; it can't be only numbers
18
+ # @attr [Integer] position Ordering of the field relative to other fields
19
+ # @attr [String] raw_description The dynamic content placeholder, if present, or the description value, if not
20
+ # @attr [String] raw_title The dynamic content placeholder, if present, or the title value, if not
21
+ # @attr [String] regexp_for_validation Regular expression field only; the validation pattern for a field value to be deemed valid
22
+ # @attr [Hash] relationship_filter A filter definition that allows your autocomplete to filter down results
23
+ # @attr [String] relationship_target_type A representation of what type of object the field references; options are "zen:user", "zen:organization", "zen:ticket", and "zen:custom_object:{key}" where key is a custom object key
24
+ # @attr [Boolean] system If true, only active and position values of this field can be changed
25
+ # @attr [String] tag Optional for custom field of type "checkbox"; not presented otherwise
26
+ # @attr [String] title The title of the custom field
27
+ # @attr [String] type he custom field type: "checkbox", "date", "decimal", "dropdown", "integer", "lookup", "multiselect", "regexp", "text", or "textarea"
28
+ # @attr [String] update_at The time of the last update of the ticket field
29
+ class UserFields < SupportOps::Zendesk::Base
30
+ # @!parse
31
+ # # Creates/updates a user field
32
+ # #
33
+ # # @author Jason Colyer
34
+ # # @since 1.0.0
35
+ # # @return [Object] Instance of {SupportOps::Zendesk::UserFields}
36
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
37
+ # # @see
38
+ # # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#create-user-field
39
+ # # Zendesk API > User Fields > Create User Field
40
+ # # @see
41
+ # # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#update-user-field
42
+ # # Zendesk API > User Fields > Update User Field
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_field = SupportOps::Zendesk::UserFields.new
53
+ # # new_field.title = 'Support description'
54
+ # # new_field.type = 'text'
55
+ # # new_field.description = 'This field describes the support plan this organization has'
56
+ # # new_field.key = 'support_description'
57
+ # #
58
+ # # new_field.save!
59
+ # #
60
+ # # pp new_field.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
+ # # existing_field = SupportOps::Zendesk::UserFields.get!(23409462)
72
+ # # existing_field.title = 'Support description (text)'
73
+ # #
74
+ # # existing_field.save!
75
+ # #
76
+ # # pp existing_field.title
77
+ # # # => "Support description (text)"
78
+ # def save!; end
79
+ # @!parse
80
+ # # Deletes a user field
81
+ # #
82
+ # # @author Jason Colyer
83
+ # # @since 1.0.0
84
+ # # @return [Boolean]
85
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
86
+ # # @see
87
+ # # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#delete-user-field
88
+ # # Zendesk API > User Fields > Delete User Field
89
+ # # @example
90
+ # # require 'support_ops_zendesk'
91
+ # #
92
+ # # SupportOps::Zendesk::Configuration.configure do |config|
93
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
94
+ # # config.username = 'jason@example.com'
95
+ # # config.token = 'abc123'
96
+ # # end
97
+ # #
98
+ # # existing_field = SupportOps::Zendesk::UserFields.get!(23409462)
99
+ # # existing_field.delete!
100
+ # def delete!; end
101
+ # @!parse
102
+ # # Lists field options for a user field
103
+ # #
104
+ # # @author Jason Colyer
105
+ # # @since 1.0.0
106
+ # # @return [Boolean]
107
+ # # @note This is inherited from {SupportOps::Zendesk::Base#field_options}
108
+ # # @see
109
+ # # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#list-user-field-options
110
+ # # Zendesk API > User Fields > List User Field Options
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
+ # # existing_field = SupportOps::Zendesk::UserFields.get!(23409462)
121
+ # # options = existing_field.field_options
122
+ # # pp options.count
123
+ # # # => 5
124
+ # def field_options; end
125
+ define_attributes :active, :created_at, :custom_field_options,
126
+ :description, :id, :key, :position, :raw_description,
127
+ :raw_title, :regexp_for_validation,
128
+ :relationship_filter, :relationship_target_type,
129
+ :system, :tag, :title, :type, :updated_at
130
+ readonly_attributes :created_at, :id, :system, :updated_at
131
+
132
+ ##
133
+ # Lists user fields in the Zendesk system
134
+ #
135
+ # @author Jason Colyer
136
+ # @since 1.0.0
137
+ # @overload list(key: value)
138
+ # @param limit [Integer optional] The limit to the number of user fields
139
+ # returned. Default to 0 (i.e. no limit)
140
+ # @return [Array]
141
+ # @see
142
+ # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#list-user-fields
143
+ # Zendesk API > User Fields > List User Fields
144
+ # @see SupportOps::Zendesk::Configuration Setting up a client
145
+ # @example
146
+ # require 'support_ops_zendesk'
147
+ #
148
+ # SupportOps::Zendesk::Configuration.configure do |config|
149
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
150
+ # config.username = 'jason@example.com'
151
+ # config.token = 'abc123'
152
+ # end
153
+ #
154
+ # fields = SupportOps::Zendesk::UserFields.list(limit: 10)
155
+ # pp fields.count
156
+ # # => 10
157
+ # pp fields.last.title
158
+ # # => "I'm the 10th user field"
159
+ def self.list(**args)
160
+ args[:limit] = 0 unless args[:limit]
161
+ array = []
162
+ opts = 'page[size]=100'
163
+ loop do
164
+ response = client.connection.get("user_fields?#{opts}")
165
+ body = Oj.load(response.body)
166
+ array += body['user_fields'].map { |u| UserFields.new(u) }
167
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
168
+ break unless body['meta']['has_more']
169
+
170
+ opts = body['links']['next'].split('?').last
171
+ end
172
+ return array if args[:limit].to_i.zero?
173
+
174
+ array.first(args[:limit].to_i)
175
+ end
176
+
177
+ ##
178
+ # Locates a specific user field in the Zendesk system
179
+ #
180
+ # @author Jason Colyer
181
+ # @since 1.0.0
182
+ # @see
183
+ # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#show-user-field
184
+ # Zendesk API > User Fields > Show User Field
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
+ # field = SupportOps::Zendesk::UserFields.get(25)
196
+ # pp field.title
197
+ # # => "I'm the 25th user field"
198
+ def self.get(object)
199
+ if object.is_a? UserFields
200
+ UserFields.new(id: id).find
201
+ else
202
+ UserFields.new(id: object).find
203
+ end
204
+ end
205
+
206
+ ##
207
+ # Locates a specific user field in the Zendesk system
208
+ #
209
+ # @author Jason Colyer
210
+ # @since 1.0.0
211
+ # @see
212
+ # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#show-user-field
213
+ # Zendesk API > User Fields > Show User Field
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
+ # field = SupportOps::Zendesk::UserFields.get!(25)
225
+ # pp field.title
226
+ # # => "I'm the 25th user field"
227
+ def self.get!(object)
228
+ if object.is_a? UserFields
229
+ UserFields.new(id: id).find!
230
+ else
231
+ UserFields.new(id: object).find!
232
+ end
233
+ end
234
+
235
+ ##
236
+ # Reorders the user field positions in Zendesk. Must include all of them.
237
+ #
238
+ # @author Jason Colyer
239
+ # @since 1.0.0
240
+ # @param field_ids [Array] The IDs of user fields in the new order
241
+ # @see
242
+ # https://developer.zendesk.com/api-reference/ticketing/users/user_fields/#reorder-user-field
243
+ # Zendesk API > User Fields > Reorder User Field
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
+ # pp SupportOps::Zendesk::UserFields.reorder!([25, 38, 24, 37])
255
+ # # => true
256
+ def self.reorder!(field_ids)
257
+ current_order = list.sort_by { |l| l.position }.map { |l| l.id }
258
+ raise 'You must include all user field IDs here' unless field_ids.count == current_order.count
259
+ raise 'You did not make any changes' if current_order == field_ids
260
+ data = { organization_field_ids: field_ids }.to_json
261
+ response = client.connection.put('user_fields/reorder', data)
262
+ body = Oj.load(response.body)
263
+ raise "Unable to reorder user fields => #{body}" if response.status != 200
264
+ true
265
+ end
266
+
267
+ private
268
+
269
+ ##
270
+ # @private
271
+ def get_record
272
+ response = self.client.connection.get("user_fields/#{self.id}")
273
+ return nil if response.status != 200
274
+
275
+ Oj.load(response.body)['user_field']
276
+ end
277
+
278
+ ##
279
+ # @private
280
+ def create_record
281
+ response = self.client.connection.post("user_fields", { user_field: attributes_for_save }.to_json)
282
+ body = Oj.load(response.body)
283
+ raise "Failed to create user field => #{body['details']}" if response.status != 201
284
+ body['user_field']
285
+ end
286
+
287
+ ##
288
+ # @private
289
+ def update_record
290
+ raise "Failed to update user field => You didn't change anything in the object" if attributes_for_save.keys == [:id]
291
+ response = self.client.connection.put("user_fields/#{self.id}", { user_field: attributes_for_save }.to_json)
292
+ body = Oj.load(response.body)
293
+ raise "Failed to update user field #{self.id} => #{body['details']}" if response.status != 200
294
+ body['user_field']
295
+ end
296
+
297
+ ##
298
+ # @private
299
+ def delete_record
300
+ response = self.client.connection.delete("user_fields/#{self.id}")
301
+ raise "Failed to delete user field => #{body['details']}" if response.status != 204
302
+ true
303
+ end
304
+
305
+ ##
306
+ # @private
307
+ def field_options_record
308
+ UserFieldOptions.list(user_field_id: self.id)
309
+ end
310
+ end
311
+ end
312
+ end