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,297 @@
|
|
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 DynamicContent within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [String] created_at When this record was created
|
13
|
+
# @attr [Integer] default_locale_id The default locale for the item
|
14
|
+
# @attr [Integer] id Automatically assigned when creating items
|
15
|
+
# @attr [String] name The unique name of the item
|
16
|
+
# @attr [Boolean] outdated Indicates the item has outdated variants within it
|
17
|
+
# @attr [String] placeholder Automatically generated placeholder for the item, derived from name
|
18
|
+
# @attr [String] updated_at When this record was last updated
|
19
|
+
# @attr [Array] variants All variants within this item
|
20
|
+
class DynamicContent < SupportOps::Zendesk::Base
|
21
|
+
# @!parse
|
22
|
+
# # Creates/updates a dynamic content item
|
23
|
+
# #
|
24
|
+
# # @author Jason Colyer
|
25
|
+
# # @since 1.0.0
|
26
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::DynamicContent}
|
27
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#save!}
|
28
|
+
# # @see
|
29
|
+
# # https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#create-item
|
30
|
+
# # Zendesk API > Dynamic Content > Create Item
|
31
|
+
# # @see
|
32
|
+
# # https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#update-item
|
33
|
+
# # Zendesk API > Dynamic Content > Update Item
|
34
|
+
# # @example
|
35
|
+
# # require 'support_ops_zendesk'
|
36
|
+
# #
|
37
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
38
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
39
|
+
# # config.username = 'jason@example.com'
|
40
|
+
# # config.token = 'abc123'
|
41
|
+
# # end
|
42
|
+
# #
|
43
|
+
# # new_item = SupportOps::Zendesk::DynamicContent.new
|
44
|
+
# # new_item.name = 'Support description'
|
45
|
+
# # new_item.default_locale_id: 16
|
46
|
+
# # new_item.variants = [
|
47
|
+
# # { 'locale_id' => 16, "default" => true, "content" => "Description du support" },
|
48
|
+
# # { 'locale_id' => 2, "default" => true, "content" => "Support description" }
|
49
|
+
# # ]
|
50
|
+
# #
|
51
|
+
# # new_item.save!
|
52
|
+
# #
|
53
|
+
# # pp new_item.id
|
54
|
+
# # # => 23409462
|
55
|
+
# # @example
|
56
|
+
# # require 'support_ops_zendesk'
|
57
|
+
# #
|
58
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
59
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
60
|
+
# # config.username = 'jason@example.com'
|
61
|
+
# # config.token = 'abc123'
|
62
|
+
# # end
|
63
|
+
# #
|
64
|
+
# # existing_item = SupportOps::Zendesk::DynamicContent.get!(23409462)
|
65
|
+
# # existing_item.name = 'Support description (text)'
|
66
|
+
# #
|
67
|
+
# # existing_item.save!
|
68
|
+
# #
|
69
|
+
# # pp existing_item.title
|
70
|
+
# # # => "Support description (text)"
|
71
|
+
# def save!; end
|
72
|
+
# @!parse
|
73
|
+
# # Deletes a dynamic content item
|
74
|
+
# #
|
75
|
+
# # @author Jason Colyer
|
76
|
+
# # @since 1.0.0
|
77
|
+
# # @return [Boolean]
|
78
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
79
|
+
# # @see
|
80
|
+
# # https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#delete-item
|
81
|
+
# # Zendesk API > Dynamic Content > Delete Item
|
82
|
+
# # @example
|
83
|
+
# # require 'support_ops_zendesk'
|
84
|
+
# #
|
85
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
86
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
87
|
+
# # config.username = 'jason@example.com'
|
88
|
+
# # config.token = 'abc123'
|
89
|
+
# # end
|
90
|
+
# #
|
91
|
+
# # existing_item = SupportOps::Zendesk::DynamicContent.get!(23409462)
|
92
|
+
# # existing_item.delete!
|
93
|
+
# def delete!; end
|
94
|
+
# @!parse
|
95
|
+
# # Lists dynamic content variants for a dynamic content item
|
96
|
+
# #
|
97
|
+
# # @author Jason Colyer
|
98
|
+
# # @since 1.0.0
|
99
|
+
# # @return [Boolean]
|
100
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#item_variants}
|
101
|
+
# # @see
|
102
|
+
# # https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#list-variants
|
103
|
+
# # Zendesk API > Dynamic Content Variants > List Variants
|
104
|
+
# # @example
|
105
|
+
# # require 'support_ops_zendesk'
|
106
|
+
# #
|
107
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
108
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
109
|
+
# # config.username = 'jason@example.com'
|
110
|
+
# # config.token = 'abc123'
|
111
|
+
# # end
|
112
|
+
# #
|
113
|
+
# # existing_item = SupportOps::Zendesk::DynamicContent.get!(23409462)
|
114
|
+
# # variants = existing_item.item_variants
|
115
|
+
# # pp variants.count
|
116
|
+
# # # => 3
|
117
|
+
define_attributes :created_at, :default_locale_id, :id, :name, :outdated,
|
118
|
+
:placeholder, :updated_at, :variants
|
119
|
+
readonly_attributes :created_at, :id, :outdated, :placehodler, :updated_at
|
120
|
+
|
121
|
+
##
|
122
|
+
# Lists dynamic content items in the Zendesk system
|
123
|
+
#
|
124
|
+
# @author Jason Colyer
|
125
|
+
# @since 1.0.0
|
126
|
+
# @overload list(key: value)
|
127
|
+
# @param limit [Integer optional] The limit to the number of dynamic
|
128
|
+
# content returned. Default to 0 (i.e. no limit)
|
129
|
+
# @return [Array]
|
130
|
+
# @see
|
131
|
+
# https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#list-items
|
132
|
+
# Zendesk API > Dynamic Content > List Items
|
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
|
+
# items = SupportOps::Zendesk::DynamicContent.list(limit: 10)
|
144
|
+
# pp items.count
|
145
|
+
# # => 10
|
146
|
+
# pp items.last.name
|
147
|
+
# # => "I'm the 10th dynamic content item"
|
148
|
+
def self.list(**args)
|
149
|
+
args[:limit] = 0 unless args[:limit]
|
150
|
+
array = []
|
151
|
+
opts = 'page[size]=100'
|
152
|
+
loop do
|
153
|
+
response = client.connection.get("dynamic_content/items?#{opts}")
|
154
|
+
body = Oj.load(response.body)
|
155
|
+
array += body['items'].map { |i| DynamicContent.new(i) }
|
156
|
+
break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
|
157
|
+
break unless body['meta']['has_more']
|
158
|
+
|
159
|
+
opts = body['links']['next'].split('?').last
|
160
|
+
end
|
161
|
+
return array if args[:limit].to_i.zero?
|
162
|
+
|
163
|
+
array.first(args[:limit].to_i)
|
164
|
+
end
|
165
|
+
|
166
|
+
##
|
167
|
+
# Locates a specific dynamic content item in the Zendesk system
|
168
|
+
#
|
169
|
+
# @author Jason Colyer
|
170
|
+
# @since 1.0.0
|
171
|
+
# @see
|
172
|
+
# https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#show-item
|
173
|
+
# Zendesk API > Dynamic Content > Show Item
|
174
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
175
|
+
# @example
|
176
|
+
# require 'support_ops_zendesk'
|
177
|
+
#
|
178
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
179
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
180
|
+
# config.username = 'jason@example.com'
|
181
|
+
# config.token = 'abc123'
|
182
|
+
# end
|
183
|
+
#
|
184
|
+
# item = SupportOps::Zendesk::DynamicContent.get(25)
|
185
|
+
# pp item.name
|
186
|
+
# # => "I'm the 25th dynamic content item"
|
187
|
+
def self.get(object)
|
188
|
+
if object.is_a? DynamicContent
|
189
|
+
DynamicContent.new(id: id).find
|
190
|
+
else
|
191
|
+
DynamicContent.new(id: object).find
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# Locates a specific dynamic content item in the Zendesk system
|
197
|
+
#
|
198
|
+
# @author Jason Colyer
|
199
|
+
# @since 1.0.0
|
200
|
+
# @see
|
201
|
+
# https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#show-item
|
202
|
+
# Zendesk API > Dynamic Content > Show Item
|
203
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
204
|
+
# @example
|
205
|
+
# require 'support_ops_zendesk'
|
206
|
+
#
|
207
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
208
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
209
|
+
# config.username = 'jason@example.com'
|
210
|
+
# config.token = 'abc123'
|
211
|
+
# end
|
212
|
+
#
|
213
|
+
# item = SupportOps::Zendesk::DynamicContent.get!(25)
|
214
|
+
# pp item.name
|
215
|
+
# # => "I'm the 25th dynamic content item"
|
216
|
+
def self.get!(object)
|
217
|
+
if object.is_a? DynamicContent
|
218
|
+
DynamicContent.new(id: id).find!
|
219
|
+
else
|
220
|
+
DynamicContent.new(id: object).find!
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
##
|
225
|
+
# Locates up to 100 dynamic content items within Zendesk.
|
226
|
+
#
|
227
|
+
# @author Jason Colyer
|
228
|
+
# @since 1.0.0
|
229
|
+
# @param item_ids [Array] The dynamic content IDs to find
|
230
|
+
# @return [Array]
|
231
|
+
# @see
|
232
|
+
# https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content/#show-many-items
|
233
|
+
# Zendesk API > Dynamic Content > Show Many Items
|
234
|
+
# @example
|
235
|
+
# require 'support_ops_zendesk'
|
236
|
+
#
|
237
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
238
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
239
|
+
# config.username = 'jason@example.com'
|
240
|
+
# config.token = 'abc123'
|
241
|
+
# end
|
242
|
+
#
|
243
|
+
# items = SupportOps::Zendesk::DynamicContent.get_many([255, 256])
|
244
|
+
# pp items.map { |t| t.name }
|
245
|
+
# # => ["Subject", "Description"]
|
246
|
+
def self.get_many(item_ids)
|
247
|
+
raise 'The parameter must be an Array' unless item_ids.is_a? Array
|
248
|
+
raise 'You can only get a maximum of 100 dyncamic content items at a time' if item_ids.count > 100
|
249
|
+
|
250
|
+
response = client.connection.get("dynamic_content/items/show_many?ids=#{item_ids.join(',')}")
|
251
|
+
Oj.load(response.body)['items'].map { |i| DynamicContent.new(i) }
|
252
|
+
end
|
253
|
+
|
254
|
+
private
|
255
|
+
|
256
|
+
def get_record
|
257
|
+
response = self.client.connection.get("dynamic_content/items/#{self.id}")
|
258
|
+
return nil if response.status != 200
|
259
|
+
|
260
|
+
Oj.load(response.body)['item']
|
261
|
+
end
|
262
|
+
|
263
|
+
##
|
264
|
+
# @private
|
265
|
+
def create_record
|
266
|
+
response = self.client.connection.post("dynamic_content/items", { item: attributes_for_save }.to_json)
|
267
|
+
body = Oj.load(response.body)
|
268
|
+
raise "Failed to create dynamic content item => #{body}" if response.status != 201
|
269
|
+
body['item']
|
270
|
+
end
|
271
|
+
|
272
|
+
##
|
273
|
+
# @private
|
274
|
+
def update_record
|
275
|
+
raise "Failed to update dynamic content item => You didn't change anything in the object" if attributes_for_save.keys == [:id]
|
276
|
+
response = self.client.connection.put("dynamic_content/items/#{self.id}", { item: attributes_for_save }.to_json)
|
277
|
+
body = Oj.load(response.body)
|
278
|
+
raise "Failed to update dynamic content item #{self.id} => #{body}" if response.status != 200
|
279
|
+
body['item']
|
280
|
+
end
|
281
|
+
|
282
|
+
##
|
283
|
+
# @private
|
284
|
+
def delete_record
|
285
|
+
response = self.client.connection.delete("dynamic_content/items/#{self.id}")
|
286
|
+
raise "Failed to delete dynamic content item => #{body}" if response.status != 204
|
287
|
+
true
|
288
|
+
end
|
289
|
+
|
290
|
+
##
|
291
|
+
# @private
|
292
|
+
def item_variants_record
|
293
|
+
DynamicContentVariants.list(item_id: self.id)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
@@ -0,0 +1,309 @@
|
|
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 DynamicContentVariants within the module {SupportOps::Zendesk}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @attr [Boolean] active If the variant is active and useable
|
13
|
+
# @attr [String] content The content of the variant
|
14
|
+
# @attr [String] created_at When the variant was created
|
15
|
+
# @attr [Boolean] default If the variant is the default for the item it belongs to
|
16
|
+
# @attr [Integer] id Automatically assigned when the variant is created
|
17
|
+
# @attr [Integer] locale_id An active locale
|
18
|
+
# @attr [Boolean] outdated If the variant is outdated
|
19
|
+
# @attr [String] updated_at When the variant was last updated
|
20
|
+
# @todo Show Variant => https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#show-variant
|
21
|
+
class DynamicContentVariants < SupportOps::Zendesk::Base
|
22
|
+
# @!parse
|
23
|
+
# # Creates/updates a dynamic content item variant
|
24
|
+
# #
|
25
|
+
# # @author Jason Colyer
|
26
|
+
# # @since 1.0.0
|
27
|
+
# # @return [Object] Instance of {SupportOps::Zendesk::DynamicContentVariants}
|
28
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#save!}
|
29
|
+
# # @see
|
30
|
+
# # https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#create-variant
|
31
|
+
# # Zendesk API > Dynamic Content Variants > Create Variant
|
32
|
+
# # @see
|
33
|
+
# # https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#update-variant
|
34
|
+
# # Zendesk API > Dynamic Content Variants > Update Variant
|
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
|
+
# # item = SupportOps::Zendesk::DynamicContent.get!(50)
|
45
|
+
# # new_variant = SupportOps::Zendesk::DynamicContentVariants.new
|
46
|
+
# # new_variant.active = true
|
47
|
+
# # new_variant.content = 'Greetings!'
|
48
|
+
# # new_variant.default = true
|
49
|
+
# # new_variant.locale_id = '2'
|
50
|
+
# # new_variant.item_id = item.id
|
51
|
+
# #
|
52
|
+
# # new_variant.save!
|
53
|
+
# #
|
54
|
+
# # pp new_variant.id
|
55
|
+
# # # => 35436
|
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
|
+
# # item = SupportOps::Zendesk::DynamicContent.get!(50)
|
66
|
+
# # variants = item.list_variants
|
67
|
+
# # existing_variant = variants.last
|
68
|
+
# # existing_variant.content = 'Greetings customer!'
|
69
|
+
# #
|
70
|
+
# # existing_variant.save!
|
71
|
+
# #
|
72
|
+
# # pp existing_variant.content
|
73
|
+
# # # => "Greetings customer!"
|
74
|
+
# def save!; end
|
75
|
+
# @!parse
|
76
|
+
# # Deletes a dynamic content item
|
77
|
+
# #
|
78
|
+
# # @author Jason Colyer
|
79
|
+
# # @since 1.0.0
|
80
|
+
# # @return [Boolean]
|
81
|
+
# # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
|
82
|
+
# # @see
|
83
|
+
# # https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#delete-variant
|
84
|
+
# # Zendesk API > Dynamic Content Variants > Delete Variant
|
85
|
+
# # @example
|
86
|
+
# # require 'support_ops_zendesk'
|
87
|
+
# #
|
88
|
+
# # SupportOps::Zendesk::Configuration.configure do |config|
|
89
|
+
# # config.url = 'https://gitlab.zendesk.com/api/v2'
|
90
|
+
# # config.username = 'jason@example.com'
|
91
|
+
# # config.token = 'abc123'
|
92
|
+
# # end
|
93
|
+
# #
|
94
|
+
# # existing_item = SupportOps::Zendesk::DynamicContent.get!(23409462)
|
95
|
+
# # existing_variant = existing_item.item_variants.last
|
96
|
+
# # existing_variant.delete!
|
97
|
+
# def delete!; end
|
98
|
+
define_attributes :active, :content, :created_at, :default, :id, :item_id,
|
99
|
+
:locale_id, :outdated, :updated_at
|
100
|
+
readonly_attributes :created_at, :id, :item_id, :outdated, :updated_at
|
101
|
+
|
102
|
+
##
|
103
|
+
# Lists dynamic content item variants in the Zendesk system
|
104
|
+
#
|
105
|
+
# @author Jason Colyer
|
106
|
+
# @since 1.0.0
|
107
|
+
# @overload list(key: value)
|
108
|
+
# @param item_id [Integer required] The dynamic content item to find the options for
|
109
|
+
# @param limit [Integer optional] The limit to the number of variants
|
110
|
+
# returned. Default to 0 (i.e. no limit)
|
111
|
+
# @return [Array]
|
112
|
+
# @see
|
113
|
+
# https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#list-variants
|
114
|
+
# Zendesk API > Dynamic Content Variants > List Variants
|
115
|
+
# @see SupportOps::Zendesk::Configuration Setting up a client
|
116
|
+
# @example
|
117
|
+
# require 'support_ops_zendesk'
|
118
|
+
#
|
119
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
120
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
121
|
+
# config.username = 'jason@example.com'
|
122
|
+
# config.token = 'abc123'
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# item = SupportOps::Zendesk::DynamicContent.get!(50)
|
126
|
+
# variants = SupportOps::Zendesk::DynamicContentVariants.list(item_id: item.id)
|
127
|
+
# pp variants.count
|
128
|
+
# # => 3
|
129
|
+
# pp variants.first.name
|
130
|
+
# # => "Hello"
|
131
|
+
def self.list(**args)
|
132
|
+
raise 'You must provide a item_id value' unless args[:item_id]
|
133
|
+
args[:limit] = 0 unless args[:limit]
|
134
|
+
array = []
|
135
|
+
opts = 'page[size]=100'
|
136
|
+
loop do
|
137
|
+
response = client.connection.get("dynamic_content/items/#{args[:item_id]}/variants?#{opts}")
|
138
|
+
body = Oj.load(response.body)
|
139
|
+
body['variants'].each do |c|
|
140
|
+
c['item_id'] = args[:item_id]
|
141
|
+
end
|
142
|
+
body['variants'].each { |v| v['item_id'] = args[:item_id] }
|
143
|
+
array += body['variants'].map { |v| DynamicContentVariants.new(v) }
|
144
|
+
break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
|
145
|
+
break unless body['meta']['has_more']
|
146
|
+
|
147
|
+
opts = body['links']['next'].split('?').last
|
148
|
+
end
|
149
|
+
return array if args[:limit].to_i.zero?
|
150
|
+
|
151
|
+
array.first(args[:limit].to_i)
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Creates multiple dynamic content item variants
|
156
|
+
#
|
157
|
+
# @author Jason Colyer
|
158
|
+
# @since 1.0.0
|
159
|
+
# @param variants [Array] An array of {SupportOps::Zendesk::DynamicContentVariants} instances
|
160
|
+
# @return [Array] An array of {SupportOps::Zendesk::DynamicContentVariants} instances
|
161
|
+
# @see
|
162
|
+
# https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#create-many-variants
|
163
|
+
# Zendesk API > Dynamic Content Variants > Create Many Variants
|
164
|
+
# @example
|
165
|
+
# require 'support_ops_zendesk'
|
166
|
+
#
|
167
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
168
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
169
|
+
# config.username = 'jason@example.com'
|
170
|
+
# config.token = 'abc123'
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
# item = SupportOps::Zendesk::DynamicContent.get!(50)
|
174
|
+
# variant1 = SupportOps::Zendesk::DynamicContentVariants.new
|
175
|
+
# variant1.active = true
|
176
|
+
# variant1.content = 'Greetings!'
|
177
|
+
# variant1.default = true
|
178
|
+
# variant1.locale_id = '2'
|
179
|
+
# variant1.item_id = item.id
|
180
|
+
# variant2 = SupportOps::Zendesk::DynamicContentVariants.new
|
181
|
+
# variant2.active = true
|
182
|
+
# variant2.content = '¡Saludos!'
|
183
|
+
# variant2.default = true
|
184
|
+
# variant2.locale_id = '126'
|
185
|
+
# variant2.item_id = item.id
|
186
|
+
# creates = SupportOps::Zendesk::DynamicContentVariants.create_many!([variant1, variant2])
|
187
|
+
# pp creates.first.content
|
188
|
+
# # => "Greetings!"
|
189
|
+
def self.create_many!(variants)
|
190
|
+
raise 'The parameter must be an Array' unless variants.is_a? Array
|
191
|
+
raise 'You can only create a maximum of 100 dynamic content variants at a time' if variants.count > 100
|
192
|
+
raise 'You can only use SupportOps::Zendesk::DynamicContentVariants instances in the Array' unless variants.reject { |t| t.is_a? SupportOps::Zendesk::DynamicContentVariants }.count.zero?
|
193
|
+
raise 'You can only do this on one dynamic content item' unless variants.map { |v| v.item_id }.uniq.count == 1
|
194
|
+
|
195
|
+
item_id = variants.first.item_id
|
196
|
+
data = { 'variants' => [] }
|
197
|
+
variants.each do |v|
|
198
|
+
object = {
|
199
|
+
'active' => v.active,
|
200
|
+
'content' => v.content,
|
201
|
+
'default' => v.default,
|
202
|
+
'locale_id' => v.locale_id
|
203
|
+
}
|
204
|
+
data['variants'].push(object)
|
205
|
+
end
|
206
|
+
response = client.connection.post("dynamic_content/items/#{item_id}/variants/create_many", data.to_json)
|
207
|
+
body = Oj.load(Response.body)
|
208
|
+
raise "Failed to create dynamic content variants => #{body['details']}" if response.status != 201
|
209
|
+
body['variants'].each { |b| b['item_id'] = item_id }
|
210
|
+
body['variants'].map { |v| SupportOps::Zendesk::DynamicContentVariants.new(v) }
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# Updates multiple dynamic content item variants
|
215
|
+
#
|
216
|
+
# @author Jason Colyer
|
217
|
+
# @since 1.0.0
|
218
|
+
# @param variants [Array] An array of {SupportOps::Zendesk::DynamicContentVariants} instances
|
219
|
+
# @return [Array] An array of {SupportOps::Zendesk::DynamicContentVariants} instances
|
220
|
+
# @see
|
221
|
+
# https://developer.zendesk.com/api-reference/ticketing/ticket-management/dynamic_content_item_variants/#update-many-variants
|
222
|
+
# Zendesk API > Dynamic Content Variants > Update Many Variants
|
223
|
+
# @example
|
224
|
+
# require 'support_ops_zendesk'
|
225
|
+
#
|
226
|
+
# SupportOps::Zendesk::Configuration.configure do |config|
|
227
|
+
# config.url = 'https://gitlab.zendesk.com/api/v2'
|
228
|
+
# config.username = 'jason@example.com'
|
229
|
+
# config.token = 'abc123'
|
230
|
+
# end
|
231
|
+
#
|
232
|
+
# item = SupportOps::Zendesk::DynamicContent.get!(50)
|
233
|
+
# variants = item.item_variants
|
234
|
+
# variant1 = variants.first
|
235
|
+
# variant1.content = 'Greetings customer!'
|
236
|
+
# variant2.content = '¡Saludos cliente!'
|
237
|
+
# updates = SupportOps::Zendesk::DynamicContentVariants.update_many!([variant1, variant2])
|
238
|
+
# pp updates.first.content
|
239
|
+
# # => "Greetings customer!"
|
240
|
+
def self.update_many!(variants)
|
241
|
+
raise 'The parameter must be an Array' unless variants.is_a? Array
|
242
|
+
raise 'You can only update a maximum of 100 dynamic content variants at a time' if variants.count > 100
|
243
|
+
raise 'You can only use SupportOps::Zendesk::DynamicContentVariants instances in the Array' unless variants.reject { |t| t.is_a? SupportOps::Zendesk::DynamicContentVariants }.count.zero?
|
244
|
+
raise 'You can only do this on one dynamic content item' unless variants.map { |v| v.item_id }.uniq.count == 1
|
245
|
+
|
246
|
+
item_id = variants.first.item_id
|
247
|
+
data = { 'variants' => [] }
|
248
|
+
variants.each do |v|
|
249
|
+
object = {
|
250
|
+
'id' => v.id,
|
251
|
+
'active' => v.active,
|
252
|
+
'content' => v.content,
|
253
|
+
'default' => v.default,
|
254
|
+
'locale_id' => v.locale_id
|
255
|
+
}
|
256
|
+
data['variants'].push(object)
|
257
|
+
end
|
258
|
+
response = client.connection.put("dynamic_content/items/#{item_id}/variants/update_many", data.to_json)
|
259
|
+
body = Oj.load(Response.body)
|
260
|
+
raise "Failed to update dynamic content variants => #{body['details']}" if response.status != 200
|
261
|
+
body['variants'].each { |b| b['item_id'] = item_id }
|
262
|
+
body['variants'].map { |v| SupportOps::Zendesk::DynamicContentVariants.new(v) }
|
263
|
+
end
|
264
|
+
|
265
|
+
private
|
266
|
+
|
267
|
+
##
|
268
|
+
# @private
|
269
|
+
def create_record
|
270
|
+
data = {
|
271
|
+
'active' => self.active,
|
272
|
+
'content' => self.content,
|
273
|
+
'default' => self.default,
|
274
|
+
'locale_id' => self.locale_id
|
275
|
+
}.compact
|
276
|
+
response = self.client.connection.post("dynamic_content/items/#{self.item_id}/variants", { variant: data }.to_json)
|
277
|
+
body = Oj.load(response.body)
|
278
|
+
raise "Failed to create dynamic content variant => #{body}" unless response.status == 201
|
279
|
+
body['variant']['item_id'] = self.item_id
|
280
|
+
body['variant']
|
281
|
+
end
|
282
|
+
|
283
|
+
##
|
284
|
+
# @private
|
285
|
+
def update_record
|
286
|
+
data = {
|
287
|
+
'id' => self.id,
|
288
|
+
'active' => self.active,
|
289
|
+
'content' => self.content,
|
290
|
+
'default' => self.default,
|
291
|
+
'locale_id' => self.locale_id
|
292
|
+
}.compact
|
293
|
+
response = self.client.connection.put("dynamic_content/items/#{self.item_id}/variants/#{self.id}", { variant: data }.to_json)
|
294
|
+
body = Oj.load(response.body)
|
295
|
+
raise "Failed to update dynamic content variant #{self.id} => #{body}" unless response.status == 200
|
296
|
+
body['variant']['item_id'] = self.item_id
|
297
|
+
body['variant']
|
298
|
+
end
|
299
|
+
|
300
|
+
##
|
301
|
+
# @private
|
302
|
+
def delete_record
|
303
|
+
response = client.connection.delete("dynamic_content/items/#{self.item_id}/variants/#{self.id}")
|
304
|
+
raise "Failed to delete dynamic content item variant #{self.id} => #{body}" if response.status != 204
|
305
|
+
true
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|