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,302 @@
|
|
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 SLAs within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] created_at The time the SLA policy was created
|
13
|
+
# @attr [String] description The description of the SLA policy
|
14
|
+
# @attr [Hash] filter An object that describes the conditions that a ticket must match in order for an SLA policy to be applied to that ticket.
|
15
|
+
# @attr [Integer] id Automatically assigned when created
|
16
|
+
# @attr [Array] policy_metrics Array of Policy Metric objects
|
17
|
+
# @attr [Integer] position Position of the SLA policy that determines the order they will be matched. If not specified, the SLA policy is added as the last position
|
18
|
+
# @attr [String] title The title of the SLA policy
|
19
|
+
# @attr [String] updated_at The time of the last update of the SLA policy
|
20
|
+
# @todo Retrieve Supported Filter Definition Items => https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#retrieve-supported-filter-definition-items
|
21
|
+
class SLAs < SupportOps::Zendesk::Base
|
22
|
+
# @!parse
|
23
|
+
# # Creates/updates a SLA
|
24
|
+
# #
|
25
|
+
# # @author Jason Colyer
|
26
|
+
# # @since 1.0.0
|
27
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::SLAs}
|
28
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#save!}
|
29
|
+
# # @see
|
30
|
+
# # https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#create-sla-policy
|
31
|
+
# # Zendesk API > SLA Policies > Create SLA Policy
|
32
|
+
# # @see
|
33
|
+
# # https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#update-sla-policy
|
34
|
+
# # Zendesk API > SLA Policies > Update SLA Policy
|
35
|
+
# # @example
|
36
|
+
# # require 'support_ops_zendesk'
|
37
|
+
# #
|
38
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
39
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
40
|
+
# # config.username = 'jason@example.com'
|
41
|
+
# # config.token = 'abc123'
|
42
|
+
# # end
|
43
|
+
# #
|
44
|
+
# # new_policy = SupportOps::Zendesk::SLAs.new
|
45
|
+
# # new_policy.title = 'Incidents'
|
46
|
+
# # new_policy.description = 'For urgent incidents, we will respond to tickets in 10 minutes'
|
47
|
+
# # new_policy.position = 3
|
48
|
+
# # new_policy.filter = {
|
49
|
+
# # all: [
|
50
|
+
# # { field: 'type', operator: 'is', value: 'incident' }
|
51
|
+
# # ],
|
52
|
+
# # any: []
|
53
|
+
# # }
|
54
|
+
# # new_policy.policy_metrics = [
|
55
|
+
# # { priority: 'normal', metric: 'first_reply_time', target: 30, business_hours: false },
|
56
|
+
# # { priority: 'urgent', metric: 'first_reply_time', target: 10, business_hours: false },
|
57
|
+
# # { priority: 'low', metric: 'requester_wait_time', target: 180, business_hours: false },
|
58
|
+
# # { priority: 'normal', metric: 'requester_wait_time', target: 160, business_hours: false },
|
59
|
+
# # { priority: 'high', metric: 'requester_wait_time', target: 140, business_hours: false },
|
60
|
+
# # { priority: 'urgent', metric: 'requester_wait_time', target: 120, business_hours: false }
|
61
|
+
# # ]
|
62
|
+
# #
|
63
|
+
# # new_policy.save!
|
64
|
+
# #
|
65
|
+
# # pp new_policy.id
|
66
|
+
# # # => 36
|
67
|
+
# # @example
|
68
|
+
# # require 'support_ops_zendesk'
|
69
|
+
# #
|
70
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
71
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
72
|
+
# # config.username = 'jason@example.com'
|
73
|
+
# # config.token = 'abc123'
|
74
|
+
# # end
|
75
|
+
# #
|
76
|
+
# # existing_policy = SupportOps::Zendesk::SLAs.get!(36)
|
77
|
+
# # existing_policy.title = 'Urgent Incidents'
|
78
|
+
# #
|
79
|
+
# # existing_policy.save!
|
80
|
+
# #
|
81
|
+
# # pp existing_policy.title
|
82
|
+
# # # => "Urgent Incidents"
|
83
|
+
# def save!; end
|
84
|
+
# @!parse
|
85
|
+
# # Deletes a SLA
|
86
|
+
# #
|
87
|
+
# # @author Jason Colyer
|
88
|
+
# # @since 1.0.0
|
89
|
+
# # @return [Boolean]
|
90
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
91
|
+
# # @see
|
92
|
+
# # https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#delete-sla-policy
|
93
|
+
# # Zendesk API > SLA Policies > Delete SLA Policy
|
94
|
+
# # @example
|
95
|
+
# # require 'support_ops_zendesk'
|
96
|
+
# #
|
97
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
98
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
99
|
+
# # config.username = 'jason@example.com'
|
100
|
+
# # config.token = 'abc123'
|
101
|
+
# # end
|
102
|
+
# #
|
103
|
+
# # existing_policy = SupportOps::Zendesk::SLAs.get!(36)
|
104
|
+
# # existing_policy.delete!
|
105
|
+
# def delete!; end
|
106
|
+
define_attributes :created_at, :description, :filter, :id,
|
107
|
+
:policy_metrics, :position, :title, :updated_at
|
108
|
+
readonly_attributes :created_at, :id, :updated_at
|
109
|
+
|
110
|
+
##
|
111
|
+
# Lists SLAs in the Zendesk system
|
112
|
+
#
|
113
|
+
# @author Jason Colyer
|
114
|
+
# @since 1.0.0
|
115
|
+
# @return [Array]
|
116
|
+
# @see
|
117
|
+
# https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#list-sla-policies
|
118
|
+
# Zendesk API > SLA Policies > List SLA Policies
|
119
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
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
|
+
# policies = SupportOps::Zendesk::SLAs.list
|
130
|
+
# pp policies.count
|
131
|
+
# # => 17
|
132
|
+
def self.list
|
133
|
+
response = client.connection.get('slas/policies')
|
134
|
+
body = Oj.load(response.body)
|
135
|
+
body['sla_policies'].map { |s| SLAs.new(s) }
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Locates a SLA within Zendesk by name. Can utilize a cache for quicker results
|
140
|
+
#
|
141
|
+
# @author Jason Colyer
|
142
|
+
# @since 1.0.0
|
143
|
+
# @overload find_by_name(key: value)
|
144
|
+
# @param name [String required] The name to search for
|
145
|
+
# @param cache [Array] An Array of SupportOps::Zendesk::SLAs to use as a cache
|
146
|
+
# @return [Object] An instance of {SupportOps::Zendesk::SLAs}
|
147
|
+
# @example
|
148
|
+
# require 'support_ops_zendesk'
|
149
|
+
#
|
150
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
151
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
152
|
+
# config.username = 'jason@example.com'
|
153
|
+
# config.token = 'abc123'
|
154
|
+
# end
|
155
|
+
#
|
156
|
+
# policies = SupportOps::Zendesk::SLAs.list
|
157
|
+
# policy = SupportOps::Zendesk::SLAs.find_by_name(name: 'Emergency Support', cache: policies)
|
158
|
+
# pp policy.name
|
159
|
+
# # => "Emergency Support"
|
160
|
+
# pp policy.id
|
161
|
+
# # => 12510663676700
|
162
|
+
def self.find_by_name(**args)
|
163
|
+
raise 'You have to provide a name' unless args[:name]
|
164
|
+
if args[:cache]
|
165
|
+
raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
|
166
|
+
policies = args[:cache]
|
167
|
+
else
|
168
|
+
policies = list
|
169
|
+
end
|
170
|
+
policies.detect { |c| c.title.downcase == args[:name].to_s.downcase }
|
171
|
+
end
|
172
|
+
|
173
|
+
##
|
174
|
+
# Locates a specific SLA in the Zendesk system
|
175
|
+
#
|
176
|
+
# @author Jason Colyer
|
177
|
+
# @since 1.0.0
|
178
|
+
# @see
|
179
|
+
# https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#show-sla-policy
|
180
|
+
# Zendesk API > SLA Policies > Show SLA Policy
|
181
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
182
|
+
# @example
|
183
|
+
# require 'support_ops_zendesk'
|
184
|
+
#
|
185
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
186
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
187
|
+
# config.username = 'jason@example.com'
|
188
|
+
# config.token = 'abc123'
|
189
|
+
# end
|
190
|
+
#
|
191
|
+
# policy = SupportOps::Zendesk::SLAs.get(12510663676700)
|
192
|
+
# pp policy.name
|
193
|
+
# # => "Emergency Support"
|
194
|
+
def self.get(object)
|
195
|
+
if object.is_a? SLAs
|
196
|
+
SLAs.new(id: id).find
|
197
|
+
else
|
198
|
+
SLAs.new(id: object).find
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
##
|
203
|
+
# Locates a specific SLA in the Zendesk system
|
204
|
+
#
|
205
|
+
# @author Jason Colyer
|
206
|
+
# @since 1.0.0
|
207
|
+
# @see
|
208
|
+
# https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#show-sla-policy
|
209
|
+
# Zendesk API > SLA Policies > Show SLA Policy
|
210
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
211
|
+
# @example
|
212
|
+
# require 'support_ops_zendesk'
|
213
|
+
#
|
214
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
215
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
216
|
+
# config.username = 'jason@example.com'
|
217
|
+
# config.token = 'abc123'
|
218
|
+
# end
|
219
|
+
#
|
220
|
+
# policy = SupportOps::Zendesk::SLAs.get!(12510663676700)
|
221
|
+
# pp policy.name
|
222
|
+
# # => "Emergency Support"
|
223
|
+
def self.get!(object)
|
224
|
+
if object.is_a? SLAs
|
225
|
+
SLAs.new(id: id).find!
|
226
|
+
else
|
227
|
+
SLAs.new(id: object).find!
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
##
|
232
|
+
# Reorders the SLAs positions in Zendesk. Must include all of them.
|
233
|
+
#
|
234
|
+
# @author Jason Colyer
|
235
|
+
# @since 1.0.0
|
236
|
+
# @param sla_ids [Array] The IDs of SLAs in the new order
|
237
|
+
# @see
|
238
|
+
# https://developer.zendesk.com/api-reference/ticketing/business-rules/sla_policies/#reorder-sla-policies
|
239
|
+
# Zendesk API > SLA Policies > Reorder SLA Policies
|
240
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
241
|
+
# @example
|
242
|
+
# require 'support_ops_zendesk'
|
243
|
+
#
|
244
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
245
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
246
|
+
# config.username = 'jason@example.com'
|
247
|
+
# config.token = 'abc123'
|
248
|
+
# end
|
249
|
+
#
|
250
|
+
# pp SupportOps::Zendesk::SLAs.reorder!([25, 38, 24, 37])
|
251
|
+
# # => true
|
252
|
+
def self.reorder!(sla_ids)
|
253
|
+
current_order = list.sort_by { |l| l.position }.map { |l| l.id }
|
254
|
+
raise 'You must include all SLA IDs here' unless sla_ids.count == current_order.count
|
255
|
+
raise 'You did not make any changes' if current_order == sla_ids
|
256
|
+
data = { sla_policy_ids: sla_ids }.to_json
|
257
|
+
response = client.connection.put('slas/policies/reorder', data)
|
258
|
+
body = Oj.load(response.body)
|
259
|
+
raise "Unable to reorder SLAs => #{body}" if response.status != 200
|
260
|
+
true
|
261
|
+
end
|
262
|
+
|
263
|
+
private
|
264
|
+
|
265
|
+
##
|
266
|
+
# @private
|
267
|
+
def get_record
|
268
|
+
response = self.client.connection.get("slas/policies/#{self.id}")
|
269
|
+
return nil if response.status != 200
|
270
|
+
|
271
|
+
Oj.load(response.body)['sla_policy']
|
272
|
+
end
|
273
|
+
|
274
|
+
##
|
275
|
+
# @private
|
276
|
+
def create_record
|
277
|
+
response = self.client.connection.post('slas/policies', { sla_policy: attributes_for_save }.to_json)
|
278
|
+
body = Oj.load(response.body)
|
279
|
+
raise "Failed to create SLA => #{body}" if response.status != 201
|
280
|
+
body['sla_policy']
|
281
|
+
end
|
282
|
+
|
283
|
+
##
|
284
|
+
# @private
|
285
|
+
def update_record
|
286
|
+
raise "Failed to update SLA => You didn't change anything in the object" if attributes_for_save.keys == [:id]
|
287
|
+
response = self.client.connection.put("slas/policies/#{self.id}", { sla_policy: attributes_for_save }.to_json)
|
288
|
+
body = Oj.load(response.body)
|
289
|
+
raise "Failed to update SLA #{self.id} => #{body['details']}" if response.status != 200
|
290
|
+
body['sla_policy']
|
291
|
+
end
|
292
|
+
|
293
|
+
##
|
294
|
+
# @private
|
295
|
+
def delete_record
|
296
|
+
response = self.client.connection.delete("slas/policies/#{self.id}")
|
297
|
+
raise "Failed to delete SLA => #{body['details']}" if response.status != 204
|
298
|
+
true
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
@@ -0,0 +1,96 @@
|
|
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 Targets within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [Boolean] active Whether or not the target is activated
|
13
|
+
# @attr [String] created_at The time the target was created
|
14
|
+
# @attr [String] email The email address to send to
|
15
|
+
# @attr [Integer] id Automatically assigned when created
|
16
|
+
# @attr [String] subject The subject of the email
|
17
|
+
# @attr [String] title A name for the target
|
18
|
+
# @attr [String] type A pre-defined target, such as "email"
|
19
|
+
# @todo Show Target => https://developer.zendesk.com/api-reference/ticketing/targets/targets/#show-target
|
20
|
+
# @todo Create Target => https://developer.zendesk.com/api-reference/ticketing/targets/targets/#create-target
|
21
|
+
# @todo Update Target => https://developer.zendesk.com/api-reference/ticketing/targets/targets/#update-target
|
22
|
+
# @todo Delete Target => https://developer.zendesk.com/api-reference/ticketing/targets/targets/#delete-target
|
23
|
+
# @todo Add other attributes for other target types
|
24
|
+
class Targets < SupportOps::Zendesk::Base
|
25
|
+
define_attributes :active, :created_at, :email, :id, :subject, :title,
|
26
|
+
:type
|
27
|
+
readonly_attributes :created_at, :id
|
28
|
+
|
29
|
+
|
30
|
+
##
|
31
|
+
# Lists targets in the Zendesk system
|
32
|
+
#
|
33
|
+
# @author Jason Colyer
|
34
|
+
# @since 1.0.0
|
35
|
+
# @return [Array]
|
36
|
+
# @see
|
37
|
+
# https://developer.zendesk.com/api-reference/ticketing/targets/targets/#list-targets
|
38
|
+
# Zendesk API > Targets > List Targets
|
39
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
40
|
+
# @example
|
41
|
+
# require 'support_ops_zendesk'
|
42
|
+
#
|
43
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
44
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
45
|
+
# config.username = 'jason@example.com'
|
46
|
+
# config.token = 'abc123'
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# targets = SupportOps::Zendesk::Targets.list
|
50
|
+
# pp targets.count
|
51
|
+
# # => 3
|
52
|
+
def self.list
|
53
|
+
response = client.connection.get('targets')
|
54
|
+
body = Oj.load(response.body)
|
55
|
+
body['targets'].map { |t| Targets.new(t) }
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Locates a target within Zendesk by name. Can utilize a cache for quicker results
|
60
|
+
#
|
61
|
+
# @author Jason Colyer
|
62
|
+
# @since 1.0.0
|
63
|
+
# @overload find_by_name(key: value)
|
64
|
+
# @param name [String required] The name to search for
|
65
|
+
# @param cache [Array] An Array of SupportOps::Zendesk::Targets to use as a cache
|
66
|
+
# @return [Object] An instance of {SupportOps::Zendesk::Targets}
|
67
|
+
# @example
|
68
|
+
# require 'support_ops_zendesk'
|
69
|
+
#
|
70
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
71
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
72
|
+
# config.username = 'jason@example.com'
|
73
|
+
# config.token = 'abc123'
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# targets = SupportOps::Zendesk::Targets.list
|
77
|
+
# target = SupportOps::Zendesk::Targets.find_by_name(name: 'Fancy box', cache: targets)
|
78
|
+
# pp target.name
|
79
|
+
# # => "Fancy box"
|
80
|
+
# pp target.id
|
81
|
+
# # => 211
|
82
|
+
def self.find_by_name(**args)
|
83
|
+
raise 'You have to provide a name' unless args[:name]
|
84
|
+
if args[:cache]
|
85
|
+
raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
|
86
|
+
targets = args[:cache]
|
87
|
+
else
|
88
|
+
targets = list
|
89
|
+
end
|
90
|
+
targets.detect { |c| c.title.downcase == args[:name].to_s.downcase }
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,154 @@
|
|
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 ThemeJobStatuses within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [Hash] data Job-specific data provided on job creation
|
13
|
+
# @attr [String] id Automatically assigned when the job is queued
|
14
|
+
# @attr [Array] errors An array of errors if the job failed. Returns null if the job is pending or successful.
|
15
|
+
# @attr [String] status The current status of the job; possible values:
|
16
|
+
# "pending", "completed", or "failed"
|
17
|
+
class ThemeJobStatuses < SupportOps::Zendesk::Base
|
18
|
+
# @!parse
|
19
|
+
# # Waits for a theme job to complete. Be mindful of API limits when setting the wait interval
|
20
|
+
# #
|
21
|
+
# # @author Jason Colyer
|
22
|
+
# # @since 1.0.0
|
23
|
+
# # @overload wait_for_completetion(key: value)
|
24
|
+
# # @param interval [Integer optional] The time to wait between checks. Defaults to 5
|
25
|
+
# # @param verbose [Boolean optional] If you want info lines output. Defaults to false
|
26
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::JobStatuses}
|
27
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#wait_for_completetion}
|
28
|
+
# # @example
|
29
|
+
# # require 'support_ops_zendesk'
|
30
|
+
# #
|
31
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
32
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
33
|
+
# # config.username = 'jason@example.com'
|
34
|
+
# # config.token = 'abc123'
|
35
|
+
# # end
|
36
|
+
# #
|
37
|
+
# # job = SupportOps::Zendesk::ThemeJobStatuses.get!('8b726e606741012ffc2d782bcb7848fe')
|
38
|
+
# # job.wait_for_completetion(interval: 10, verbose: true)
|
39
|
+
# # # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
40
|
+
# # # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is queued
|
41
|
+
# # # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
42
|
+
# # # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is working
|
43
|
+
# # # => Waiting 10 seconds before checking 8b726e606741012ffc2d782bcb7848fe
|
44
|
+
# # # => Rechecking status of 8b726e606741012ffc2d782bcb7848fe...status is completed
|
45
|
+
# # # => Job is finished with status of completed
|
46
|
+
# # pp job.status
|
47
|
+
# # # => "completed"
|
48
|
+
# # @example
|
49
|
+
# # require 'support_ops_zendesk'
|
50
|
+
# #
|
51
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
52
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
53
|
+
# # config.username = 'jason@example.com'
|
54
|
+
# # config.token = 'abc123'
|
55
|
+
# # end
|
56
|
+
# #
|
57
|
+
# # job = SupportOps::Zendesk::ThemeJobStatuses.get!('8b726e606741012ffc2d782bcb7848fe')
|
58
|
+
# # job.wait_for_completetion(interval: 5, verbose: false)
|
59
|
+
# # pp job.status
|
60
|
+
# # # => "completed"
|
61
|
+
# def wait_for_completetion; end
|
62
|
+
define_attributes :data, :id, :errors, :status
|
63
|
+
readonly_attributes :data, :id, :errors, :status
|
64
|
+
|
65
|
+
##
|
66
|
+
# Locates a specific theme job status in the Zendesk system
|
67
|
+
#
|
68
|
+
# @author Jason Colyer
|
69
|
+
# @since 1.0.0
|
70
|
+
# @see
|
71
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#json-format-for-jobs
|
72
|
+
# Zendesk API > Theme > Show Job
|
73
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
74
|
+
# @example
|
75
|
+
# require 'support_ops_zendesk'
|
76
|
+
#
|
77
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
78
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
79
|
+
# config.username = 'jason@example.com'
|
80
|
+
# config.token = 'abc123'
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# job_status = SupportOps::Zendesk::ThemeJobStatuses.get('82de0b044094f0c67893ac9fe64f1a99')
|
84
|
+
# pp job_status.status
|
85
|
+
# # => "queued"
|
86
|
+
def self.get(object)
|
87
|
+
if object.is_a? ThemeJobStatuses
|
88
|
+
ThemeJobStatuses.new(id: id).find
|
89
|
+
else
|
90
|
+
ThemeJobStatuses.new(id: object).find
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Locates a specific theme job status in the Zendesk system
|
96
|
+
#
|
97
|
+
# @author Jason Colyer
|
98
|
+
# @since 1.0.0
|
99
|
+
# @see
|
100
|
+
# https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#json-format-for-jobs
|
101
|
+
# Zendesk API > Theme > Show Job
|
102
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
103
|
+
# @example
|
104
|
+
# require 'support_ops_zendesk'
|
105
|
+
#
|
106
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
107
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
108
|
+
# config.username = 'jason@example.com'
|
109
|
+
# config.token = 'abc123'
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# job_status = SupportOps::Zendesk::ThemeJobStatuses.get('82de0b044094f0c67893ac9fe64f1a99')
|
113
|
+
# pp job_status.status
|
114
|
+
# # => "queued"
|
115
|
+
def self.get!(object)
|
116
|
+
if object.is_a? ThemeJobStatuses
|
117
|
+
ThemeJobStatuses.new(id: id).find!
|
118
|
+
else
|
119
|
+
ThemeJobStatuses.new(id: object).find!
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
##
|
126
|
+
# @private
|
127
|
+
def get_record
|
128
|
+
response = self.client.connection.get("guide/theming/jobs/#{self.id}")
|
129
|
+
return nil if response.status != 200
|
130
|
+
|
131
|
+
data = Oj.load(response.body)['job']
|
132
|
+
data['id'] = self.id if data['id'].nil?
|
133
|
+
data
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# @private
|
138
|
+
def wait_for_completetion_record(**args)
|
139
|
+
job_to_check = ThemeJobStatuses.get!(self.id)
|
140
|
+
verbose = (args[:verbose] ? true : false)
|
141
|
+
interval = (args[:interval].to_i.zero? ? 5 : args[:interval].to_i)
|
142
|
+
loop do
|
143
|
+
puts "Waiting #{interval} seconds before checking #{job_to_check.id}" if verbose
|
144
|
+
sleep interval
|
145
|
+
job_to_check = ThemeJobStatuses.get!(job_to_check.id)
|
146
|
+
puts "status is #{job_to_check.status}" if verbose
|
147
|
+
break if %w[failed completed].include? job_to_check.status
|
148
|
+
end
|
149
|
+
puts "Job is finished with status of #{job_to_check.status}" if verbose
|
150
|
+
job_to_check
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|