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,362 @@
|
|
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 Articles within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [Integer] author_id The id of the user who wrote the article (set to the user who made the request on create by default)
|
13
|
+
# @attr [String] body HTML body of the article. Unsafe tags and attributes may be removed before display
|
14
|
+
# @attr [Boolean] comments_disabled True if comments are disabled; false otherwise
|
15
|
+
# @attr [Array] content_tag_ids The list of content tags attached to the article
|
16
|
+
# @attr [String] created_at The time the article was created
|
17
|
+
# @attr [Boolean] draft True if the translation for the current locale is a draft; false otherwise; false by default
|
18
|
+
# @attr [String] edited_at The time the article was last edited in its displayed locale
|
19
|
+
# @attr [String] html_url The url of the article in Help Center
|
20
|
+
# @attr [Integer] id Automatically assigned when the article is created
|
21
|
+
# @attr [Array] label_names An array of label names associated with this article; by default no label names are used
|
22
|
+
# @attr [String] locale The locale that the article is being displayed in
|
23
|
+
# @attr [Array] outdated_locales Locales in which the article was marked as outdated
|
24
|
+
# @attr [Integer] permission_group_id The id of the permission group which defines who can edit and publish this article
|
25
|
+
# @attr [Integer] position The position of this article in the article list
|
26
|
+
# @attr [Boolean] promoted True if this article is promoted; false otherwise; false by default
|
27
|
+
# @attr [Integer] section_id The id of the section to which this article belongs
|
28
|
+
# @attr [String] source_locale The source (default) locale of the article
|
29
|
+
# @attr [String] title The title of the article
|
30
|
+
# @attr [String] updated_at The time the article was last updated
|
31
|
+
# @attr [Integer] user_segment_id The id of the user segment which defines who can see this article; set to null to make it accessible to everyone; either user_segment_id or user_segment_ids must be specified
|
32
|
+
# @attr [Array] user_segment_ids List of user segment ids which define who can view this article; set to an empty list to make it accessible to everyone
|
33
|
+
# @attr [Integer] vote_count The total number of upvotes and downvotes
|
34
|
+
# @attr [Integer] vote_sum The sum of upvotes (+1) and downvotes (-1), which may be positive or negative
|
35
|
+
# @todo Update Article Source Locale > https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#update-article-source-locale
|
36
|
+
# @todo Associate Attachments in Bulk to Article > https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#associate-attachments-in-bulk-to-article
|
37
|
+
class Articles < SupportOps::Zendesk::Base
|
38
|
+
# @!parse
|
39
|
+
# # Creates/updates an article
|
40
|
+
# #
|
41
|
+
# # @author Jason Colyer
|
42
|
+
# # @since 1.0.0
|
43
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::HelpCenterSections}
|
44
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#save!}
|
45
|
+
# # @see
|
46
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#create-article
|
47
|
+
# # Zendesk API > Articles > Create Article
|
48
|
+
# # @see
|
49
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#update-article
|
50
|
+
# # Zendesk API > Articles > Update Article
|
51
|
+
# # @example
|
52
|
+
# # require 'support_ops_zendesk'
|
53
|
+
# #
|
54
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
55
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
56
|
+
# # config.username = 'jason@example.com'
|
57
|
+
# # config.token = 'abc123'
|
58
|
+
# # end
|
59
|
+
# #
|
60
|
+
# # new_article = SupportOps::Zendesk::Articles.new
|
61
|
+
# # new_article.body = 'Use a tripod'
|
62
|
+
# # new_article.locale = 'en-us'
|
63
|
+
# # new_article.permission_group_id = 56
|
64
|
+
# # new_article.title = 'Taking photos in low light'
|
65
|
+
# # new_article.user_segment_id = 123
|
66
|
+
# # new_article.section_id = 123456
|
67
|
+
# #
|
68
|
+
# # new_article.save!
|
69
|
+
# #
|
70
|
+
# # pp new_article.id
|
71
|
+
# # # => 122
|
72
|
+
# # @example
|
73
|
+
# # require 'support_ops_zendesk'
|
74
|
+
# #
|
75
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
76
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
77
|
+
# # config.username = 'jason@example.com'
|
78
|
+
# # config.token = 'abc123'
|
79
|
+
# # end
|
80
|
+
# #
|
81
|
+
# # existing_article = SupportOps::Zendesk::Articles.get!(122)
|
82
|
+
# # existing_article.label_names = ['photo', 'tripod']
|
83
|
+
# #
|
84
|
+
# # existing_article.save!
|
85
|
+
# #
|
86
|
+
# # pp existing_article.label_names
|
87
|
+
# # # => ["photo", "tripod"]
|
88
|
+
# def save!; end
|
89
|
+
# @!parse
|
90
|
+
# # Deletes (archives) an article
|
91
|
+
# #
|
92
|
+
# # @author Jason Colyer
|
93
|
+
# # @since 1.0.0
|
94
|
+
# # @return [Boolean]
|
95
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
96
|
+
# # @see
|
97
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#archive-article
|
98
|
+
# # Zendesk API > Articles > Archive Article
|
99
|
+
# # @example
|
100
|
+
# # require 'support_ops_zendesk'
|
101
|
+
# #
|
102
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
103
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
104
|
+
# # config.username = 'jason@example.com'
|
105
|
+
# # config.token = 'abc123'
|
106
|
+
# # end
|
107
|
+
# #
|
108
|
+
# # existing_article = SupportOps::Zendesk::Articles.get!(122)
|
109
|
+
# # existing_article.delete!
|
110
|
+
# def delete!; end
|
111
|
+
# @!parse
|
112
|
+
# # Lists translations
|
113
|
+
# #
|
114
|
+
# # @author Jason Colyer
|
115
|
+
# # @since 1.0.0
|
116
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#translations}
|
117
|
+
# # @see
|
118
|
+
# # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#list-translations
|
119
|
+
# # Zendesk API > Translations > Show Translations
|
120
|
+
# # @example
|
121
|
+
# # require 'support_ops_zendesk'
|
122
|
+
# #
|
123
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
124
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
125
|
+
# # config.username = 'jason@example.com'
|
126
|
+
# # config.token = 'abc123'
|
127
|
+
# # end
|
128
|
+
# #
|
129
|
+
# # existing_article = SupportOps::Zendesk::Articles.get!(122)
|
130
|
+
# # translations = existing_article.translations
|
131
|
+
# # pp translations.count
|
132
|
+
# # # => 2
|
133
|
+
# def parent; end
|
134
|
+
define_attributes :author_id, :body, :comments_disabled, :content_tag_ids,
|
135
|
+
:created_at, :draft, :edited_at, :html_url, :id,
|
136
|
+
:label_names, :locale, :outdated_locales,
|
137
|
+
:permission_group_id, :position, :promoted, :section_id,
|
138
|
+
:source_locale, :title, :updated_at, :user_segment_id,
|
139
|
+
:user_segment_ids, :vote_count, :vote_sum
|
140
|
+
readonly_attributes :created_at, :edited_at, :html_url, :id,
|
141
|
+
:outdated_locales, :source_locale, :updated_at,
|
142
|
+
:vote_count, :vote_sum
|
143
|
+
|
144
|
+
##
|
145
|
+
# Lists articles in the Zendesk system
|
146
|
+
#
|
147
|
+
# @author Jason Colyer
|
148
|
+
# @since 1.0.0
|
149
|
+
# @overload list(key: value)
|
150
|
+
# @param limit [Integer optional] The limit to the number of articles
|
151
|
+
# returned. Default to 0 (i.e. no limit)
|
152
|
+
# @return [Array]
|
153
|
+
# @see
|
154
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#list-articles
|
155
|
+
# Zendesk API > Articles > List Articles
|
156
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
157
|
+
# @example
|
158
|
+
# require 'support_ops_zendesk'
|
159
|
+
#
|
160
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
161
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
162
|
+
# config.username = 'jason@example.com'
|
163
|
+
# config.token = 'abc123'
|
164
|
+
# end
|
165
|
+
#
|
166
|
+
# articles = SupportOps::Zendesk::Articles.list(limit: 10)
|
167
|
+
# pp articles.count
|
168
|
+
# # => 10
|
169
|
+
# pp articles.last.title
|
170
|
+
# # => "I'm the 10th article"
|
171
|
+
def self.list(**args)
|
172
|
+
args[:limit] = 0 unless args[:limit]
|
173
|
+
array = []
|
174
|
+
opts = 'page[size]=100'
|
175
|
+
loop do
|
176
|
+
response = client.connection.get("help_center/articles?#{opts}")
|
177
|
+
body = Oj.load(response.body)
|
178
|
+
array += body['articles'].map { |a| Articles.new(a) }
|
179
|
+
break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
|
180
|
+
break unless body['meta']['has_more']
|
181
|
+
|
182
|
+
opts = body['links']['next'].split('?').last
|
183
|
+
end
|
184
|
+
return array if args[:limit].to_i.zero?
|
185
|
+
|
186
|
+
array.first(args[:limit].to_i)
|
187
|
+
end
|
188
|
+
|
189
|
+
##
|
190
|
+
# Locates an article within Zendesk by title. Can utilize a cache for quicker results
|
191
|
+
#
|
192
|
+
# @author Jason Colyer
|
193
|
+
# @since 1.0.0
|
194
|
+
# @overload find_by_name(key: value)
|
195
|
+
# @param title [String required] The title to search for
|
196
|
+
# @param cache [Array] An Array of SupportOps::Zendesk::Articles to use as a cache
|
197
|
+
# @return [Object] An instance of {SupportOps::Zendesk::Articles}
|
198
|
+
# @example
|
199
|
+
# require 'support_ops_zendesk'
|
200
|
+
#
|
201
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
202
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
203
|
+
# config.username = 'jason@example.com'
|
204
|
+
# config.token = 'abc123'
|
205
|
+
# end
|
206
|
+
#
|
207
|
+
# articles = SupportOps::Zendesk::Articles.list
|
208
|
+
# article = SupportOps::Zendesk::Articles.find_by_title(title: 'Test Article', cache: articles)
|
209
|
+
# pp article.title
|
210
|
+
# # => "Test Article"
|
211
|
+
# pp article.id
|
212
|
+
# # => 123456
|
213
|
+
def self.find_by_title(**args)
|
214
|
+
raise 'You have to provide a title' unless args[:title]
|
215
|
+
if args[:cache]
|
216
|
+
raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
|
217
|
+
articles = args[:cache]
|
218
|
+
else
|
219
|
+
articles = list
|
220
|
+
end
|
221
|
+
articles.detect { |s| s.title.downcase == args[:title].to_s.downcase }
|
222
|
+
end
|
223
|
+
|
224
|
+
##
|
225
|
+
# Locates a specific article in the Zendesk system
|
226
|
+
#
|
227
|
+
# @author Jason Colyer
|
228
|
+
# @since 1.0.0
|
229
|
+
# @see
|
230
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#show-article
|
231
|
+
# Zendesk API > Articles > Show Article
|
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
|
+
# article = SupportOps::Zendesk::Articles.get(123456)
|
243
|
+
# pp article.title
|
244
|
+
# # => "Test article"
|
245
|
+
def self.get(object)
|
246
|
+
if object.is_a? Articles
|
247
|
+
Articles.new(id: id).find
|
248
|
+
else
|
249
|
+
Articles.new(id: object).find
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
##
|
254
|
+
# Locates a specific article in the Zendesk system
|
255
|
+
#
|
256
|
+
# @author Jason Colyer
|
257
|
+
# @since 1.0.0
|
258
|
+
# @see
|
259
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#show-article
|
260
|
+
# Zendesk API > Articles > Show Article
|
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
|
+
# article = SupportOps::Zendesk::Articles.get!(123456)
|
272
|
+
# pp article.title
|
273
|
+
# # => "Test article"
|
274
|
+
def self.get!(object)
|
275
|
+
if object.is_a? Articles
|
276
|
+
Articles.new(id: id).find!
|
277
|
+
else
|
278
|
+
Articles.new(id: object).find!
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
private
|
283
|
+
|
284
|
+
##
|
285
|
+
# @private
|
286
|
+
def get_record
|
287
|
+
response = self.client.connection.get("help_center/articles//#{self.id}")
|
288
|
+
return nil if response.status != 200
|
289
|
+
|
290
|
+
Oj.load(response.body)['article']
|
291
|
+
end
|
292
|
+
|
293
|
+
##
|
294
|
+
# @private
|
295
|
+
def create_record
|
296
|
+
data = {
|
297
|
+
'body' => self.body,
|
298
|
+
'locale' => self.locale,
|
299
|
+
'permission_group_id' => self.permission_group_id,
|
300
|
+
'title' => self.title
|
301
|
+
}
|
302
|
+
data['user_segment_id'] = self.user_segment_id unless self.user_segment_id.nil?
|
303
|
+
data['user_segment_ids'] = self.user_segment_ids unless self.user_segment_ids.nil?
|
304
|
+
data['author_id'] = self.author_id unless self.author_id.nil?
|
305
|
+
data['comments_disabled'] = self.comments_disabled unless self.comments_disabled.nil?
|
306
|
+
data['content_tag_ids'] = self.content_tag_ids unless self.content_tag_ids.nil?
|
307
|
+
data['draft'] = self.draft unless self.draft.nil?
|
308
|
+
data['label_names'] = self.label_names unless self.label_names.nil?
|
309
|
+
data['position'] = self.position unless self.position.nil?
|
310
|
+
data['promoted'] = self.promoted unless self.promoted.nil?
|
311
|
+
data['source_locale'] = self.source_locale unless self.source_locale.nil?
|
312
|
+
unless data.keys.include?('user_segment_id') || data.keys.include?('user_segment_ids')
|
313
|
+
data['user_segment_id'] = nil
|
314
|
+
end
|
315
|
+
response = self.client.connection.post("help_center/sections/#{self.section_id}/articles", { article: data }.to_json)
|
316
|
+
body = Oj.load(response.body)
|
317
|
+
raise "Failed to create article => #{body}" if response.status != 201
|
318
|
+
body['article']
|
319
|
+
end
|
320
|
+
|
321
|
+
##
|
322
|
+
# @private
|
323
|
+
def update_record
|
324
|
+
data = {
|
325
|
+
'permission_group_id' => self.permission_group_id
|
326
|
+
}
|
327
|
+
data['user_segment_id'] = self.user_segment_id unless self.user_segment_id.nil?
|
328
|
+
data['user_segment_ids'] = self.user_segment_ids unless self.user_segment_ids.nil?
|
329
|
+
data['author_id'] = self.author_id unless self.author_id.nil?
|
330
|
+
data['comments_disabled'] = self.comments_disabled unless self.comments_disabled.nil?
|
331
|
+
data['content_tag_ids'] = self.content_tag_ids unless self.content_tag_ids.nil?
|
332
|
+
data['draft'] = self.draft unless self.draft.nil?
|
333
|
+
data['label_names'] = self.label_names unless self.label_names.nil?
|
334
|
+
data['position'] = self.position unless self.position.nil?
|
335
|
+
data['promoted'] = self.promoted unless self.promoted.nil?
|
336
|
+
data['source_locale'] = self.source_locale unless self.source_locale.nil?
|
337
|
+
unless data.keys.include?('user_segment_id') || data.keys.include?('user_segment_ids')
|
338
|
+
data['user_segment_id'] = nil
|
339
|
+
end
|
340
|
+
raise "Failed to update article => You didn't change anything in the object" if attributes_for_save.keys == [:id]
|
341
|
+
response = self.client.connection.put("help_center/articles", { article: attributes_for_save }.to_json)
|
342
|
+
body = Oj.load(response.body)
|
343
|
+
raise "Failed to update article #{self.id} => #{body}" if response.status != 200
|
344
|
+
body['article']
|
345
|
+
end
|
346
|
+
|
347
|
+
##
|
348
|
+
# @private
|
349
|
+
def delete_record
|
350
|
+
response = self.client.connection.delete("help_center/articles/#{self.id}")
|
351
|
+
raise "Failed to delete article #{self.id} => #{body}" if response.status != 204
|
352
|
+
true
|
353
|
+
end
|
354
|
+
|
355
|
+
##
|
356
|
+
# @private
|
357
|
+
def translations_record
|
358
|
+
Translations.list(self)
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
@@ -0,0 +1,166 @@
|
|
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 AuditLogs within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] action Type of change made, possible values are "create", "destroy", "exported", "login", and "update"
|
13
|
+
# @attr [String] action_label Localized string of action field
|
14
|
+
# @attr [Integer] actor_id id of the user or system that initiated the change
|
15
|
+
# @attr [String] actor_name Name of the user or system that initiated the change
|
16
|
+
# @attr [String] change_description The description of the change that occurred
|
17
|
+
# @attr [String] created_at The time the audit got created
|
18
|
+
# @attr [Integer] id The id automatically assigned upon creation
|
19
|
+
# @attr [String] ip_address The IP address of the user doing the audit
|
20
|
+
# @attr [Integer] source_id The id of the item being audited
|
21
|
+
# @attr [String] source_label The name of the item being audited
|
22
|
+
# @attr [String] source_type Item type being audited; typically describes the system where the change was initiated; possible values vary based on your account's Zendesk products and activity; common values include "apitoken", "rule", "ticket", "user", and "zendesk/app_market/app"; The "rule" value is used for automations, macros, triggers, views, and other automated business rules
|
23
|
+
# @todo Export Aduit Logs => https://developer.zendesk.com/api-reference/ticketing/account-configuration/audit_logs/#export-audit-logs
|
24
|
+
class AuditLogs < SupportOps::Zendesk::Base
|
25
|
+
define_attributes :action, :action_label, :actor_id, :actor_name,
|
26
|
+
:change_description, :created_at, :id, :ip_address,
|
27
|
+
:source_id, :source_label, :source_type
|
28
|
+
readonly_attributes :action, :action_label, :actor_id, :actor_name,
|
29
|
+
:change_description, :created_at, :id, :ip_address,
|
30
|
+
:source_id, :source_label, :source_type
|
31
|
+
|
32
|
+
##
|
33
|
+
# Lists asudit logs in the Zendesk system
|
34
|
+
#
|
35
|
+
# @author Jason Colyer
|
36
|
+
# @since 1.0.0
|
37
|
+
# @overload list(key: value)
|
38
|
+
# @param action [String optional] Filter audit logs by the action
|
39
|
+
# @param actor_id [Integer optional] Filter audit logs by the actor id
|
40
|
+
# @param start_time [String optional] Filter audit logs by the time of
|
41
|
+
# creation. This specifies the time to look after. Must be paired with
|
42
|
+
# end_time. If the other is missing this will be ignored.
|
43
|
+
# @param end_time [String optional] ilter audit logs by the time of
|
44
|
+
# creation. This specifies the time to look before. Must be paired with
|
45
|
+
# start_time. If the other is missing this will be ignored.
|
46
|
+
# @param ip_address [String optional] TBD
|
47
|
+
# @param source_id [Integer optional] TBD
|
48
|
+
# @param source_type [TBD optional] TBD
|
49
|
+
# @param limit [Integer optional] The limit to the number of audit logs
|
50
|
+
# returned. Default to 0 (i.e. no limit)
|
51
|
+
# @return [Array]
|
52
|
+
# @see
|
53
|
+
# https://developer.zendesk.com/api-reference/ticketing/account-configuration/audit_logs/#list-audit-logs
|
54
|
+
# Zendesk API > Audit Logs > List Audit Logs
|
55
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
56
|
+
# @example
|
57
|
+
# require 'support_ops_zendesk'
|
58
|
+
#
|
59
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
60
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
61
|
+
# config.username = 'jason@example.com'
|
62
|
+
# config.token = 'abc123'
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# logs = SupportOps::Zendesk::AuditLogs.list(limit: 10)
|
66
|
+
# pp logs.count
|
67
|
+
# # => 10
|
68
|
+
def self.list(**args)
|
69
|
+
args[:limit] = 0 unless args[:limit]
|
70
|
+
sort_order = (args[:sort_order] == 'desc' ? '-' : '')
|
71
|
+
array = []
|
72
|
+
opts = 'page[size]=100'
|
73
|
+
opts += "&filter[action]=#{args[:action]}" if args[:action]
|
74
|
+
opts += "&filter[actor_id]=#{args[:actor_id]}" if args[:actor_id]
|
75
|
+
opts += "&filter[ip_address]=#{args[:ip_address]}" if args[:ip_address]
|
76
|
+
opts += "&filter[source_id]=#{args[:source_id]}" if args[:source_id]
|
77
|
+
opts += "&filter[source_type]=#{args[:source_type]}" if args[:source_type]
|
78
|
+
if args[:start_time] && args[:end_time]
|
79
|
+
opts += "&filter[created_at]=#{args[:start_time]}"
|
80
|
+
opts += "&filter[created_at]=#{args[:end_time]}"
|
81
|
+
end
|
82
|
+
loop do
|
83
|
+
response = client.connection.get("audit_logs?#{opts}")
|
84
|
+
body = Oj.load(response.body)
|
85
|
+
array += body['audit_logs'].map { |a| AuditLogs.new(a) }
|
86
|
+
break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
|
87
|
+
break unless body['meta']['has_more']
|
88
|
+
|
89
|
+
opts = body['links']['next'].split('?').last
|
90
|
+
end
|
91
|
+
return array if args[:limit].to_i.zero?
|
92
|
+
|
93
|
+
array.first(args[:limit].to_i)
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# Locates a specific audit log in the Zendesk system
|
98
|
+
#
|
99
|
+
# @author Jason Colyer
|
100
|
+
# @since 1.0.0
|
101
|
+
# @see
|
102
|
+
# https://developer.zendesk.com/api-reference/ticketing/account-configuration/audit_logs/#show-audit-log
|
103
|
+
# Zendesk API > Audit Logs > Show Audit Log
|
104
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
105
|
+
# @example
|
106
|
+
# require 'support_ops_zendesk'
|
107
|
+
#
|
108
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
109
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
110
|
+
# config.username = 'jason@example.com'
|
111
|
+
# config.token = 'abc123'
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# log = SupportOps::Zendesk::AuditLogs.get(25)
|
115
|
+
# pp log.action
|
116
|
+
# # => "update"
|
117
|
+
def self.get(object)
|
118
|
+
if object.is_a? AuditLogs
|
119
|
+
AuditLogs.new(id: id).find
|
120
|
+
else
|
121
|
+
AuditLogs.new(id: object).find
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Locates a specific audit log in the Zendesk system
|
127
|
+
#
|
128
|
+
# @author Jason Colyer
|
129
|
+
# @since 1.0.0
|
130
|
+
# @see
|
131
|
+
# https://developer.zendesk.com/api-reference/ticketing/account-configuration/audit_logs/#show-audit-log
|
132
|
+
# Zendesk API > Audit Logs > Show Audit Log
|
133
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
134
|
+
# @example
|
135
|
+
# require 'support_ops_zendesk'
|
136
|
+
#
|
137
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
138
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
139
|
+
# config.username = 'jason@example.com'
|
140
|
+
# config.token = 'abc123'
|
141
|
+
# end
|
142
|
+
#
|
143
|
+
# log = SupportOps::Zendesk::AuditLogs.get!(25)
|
144
|
+
# pp log.action
|
145
|
+
# # => "update"
|
146
|
+
def self.get!(object)
|
147
|
+
if object.is_a? AuditLogs
|
148
|
+
AuditLogs.new(id: id).find!
|
149
|
+
else
|
150
|
+
AuditLogs.new(id: object).find!
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
##
|
157
|
+
# @private
|
158
|
+
def get_record
|
159
|
+
response = self.client.connection.get("audit_logs/#{self.id}")
|
160
|
+
return nil if response.status != 200
|
161
|
+
|
162
|
+
Oj.load(response.body)['audit_log']
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|