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,332 @@
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 HelpCenterCategories within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at The time at which the category was created
13
+ # @attr [String] description The description of the category
14
+ # @attr [String] html_url The url of this category in Help Center
15
+ # @attr [Integer] id Automatically assigned when creating categories
16
+ # @attr [String] locale The locale where the category is displayed
17
+ # @attr [String] name The name of the category
18
+ # @attr [Boolean] outdated Whether the category is out of date
19
+ # @attr [Integer] position The position of this category relative to other categories
20
+ # @attr [String] source_locale The source (default) locale of the category
21
+ # @attr [String] updated_at The time at which the category was last updated
22
+ # @todo Update Category Source Locale > https://developer.zendesk.com/api-reference/help_center/help-center-api/categories/#update-category-source-locale
23
+ class HelpCenterCategories < SupportOps::Zendesk::Base
24
+ # @!parse
25
+ # # Creates/updates a category
26
+ # #
27
+ # # @author Jason Colyer
28
+ # # @since 1.0.0
29
+ # # @return [Object] Instance of {SupportOps::Zendesk::HelpCenterSections}
30
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
31
+ # # @see
32
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/categories/#create-category
33
+ # # Zendesk API > Categories > Create Category
34
+ # # @see
35
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/categories/#update-category
36
+ # # Zendesk API > Categories > Update Category
37
+ # # @example
38
+ # # require 'support_ops_zendesk'
39
+ # #
40
+ # # SupportOps::Zendesk::Configuration.configure do |config|
41
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
42
+ # # config.username = 'jason@example.com'
43
+ # # config.token = 'abc123'
44
+ # # end
45
+ # #
46
+ # # new_category = SupportOps::Zendesk::HelpCenterCategories.new
47
+ # # new_category.name = 'Docker'
48
+ # # new_category.locale = 'en-us'
49
+ # # new_category.position = 4
50
+ # # new_category.description = 'This is for Docker articles'
51
+ # #
52
+ # # new_category.save!
53
+ # #
54
+ # # pp new_category.id
55
+ # # # => 122
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
+ # # existing_category = SupportOps::Zendesk::HelpCenterCategories.get!(122)
66
+ # # existing_category.position = existing_category.position + 1
67
+ # #
68
+ # # existing_category.save!
69
+ # #
70
+ # # pp existing_category.position
71
+ # # # => 5
72
+ # def save!; end
73
+ # @!parse
74
+ # # Deletes a category
75
+ # #
76
+ # # @author Jason Colyer
77
+ # # @since 1.0.0
78
+ # # @return [Boolean]
79
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
80
+ # # @see
81
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/categories/#delete-category
82
+ # # Zendesk API > Categories > Delete Category
83
+ # # @example
84
+ # # require 'support_ops_zendesk'
85
+ # #
86
+ # # SupportOps::Zendesk::Configuration.configure do |config|
87
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
88
+ # # config.username = 'jason@example.com'
89
+ # # config.token = 'abc123'
90
+ # # end
91
+ # #
92
+ # # existing_category = SupportOps::Zendesk::HelpCenterCategories.get!(122)
93
+ # # existing_category.delete!
94
+ # def delete!; end
95
+ # @!parse
96
+ # # Lists translations
97
+ # #
98
+ # # @author Jason Colyer
99
+ # # @since 1.0.0
100
+ # # @note This is inherited from {SupportOps::Zendesk::Base#translations}
101
+ # # @see
102
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#list-translations
103
+ # # Zendesk API > Translations > Show Translations
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_category = SupportOps::Zendesk::HelpCenterCategories.get!(122)
114
+ # # translations = existing_category.translations
115
+ # # pp translations.count
116
+ # # # => 2
117
+ # def parent; end
118
+ define_attributes :created_at, :description, :html_url, :id, :locale,
119
+ :name, :outdated, :position, :source_locale, :updated_at
120
+ readonly_attributes :created_at, :html_url, :id, :outdated,
121
+ :source_locale, :updated_at
122
+
123
+ ##
124
+ # Lists Help Center categories in the Zendesk system
125
+ #
126
+ # @author Jason Colyer
127
+ # @since 1.0.0
128
+ # @overload list(key: value)
129
+ # @param locale [String optional] Filter sections by a specific locale
130
+ # @param sort_by [String optional] Possible values are "position",
131
+ # "created_at", "updated_at" (defauls to "position")
132
+ # @param sort_order [String optional] One of "asc" or "desc"
133
+ # @param limit [Integer optional] The limit to the number of sections
134
+ # returned. Default to 0 (i.e. no limit)
135
+ # @return [Array]
136
+ # @see
137
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/categories/#list-categories
138
+ # Zendesk API > Categories > List Categories
139
+ # @see SupportOps::Zendesk::Configuration Setting up a client
140
+ # @example
141
+ # require 'support_ops_zendesk'
142
+ #
143
+ # SupportOps::Zendesk::Configuration.configure do |config|
144
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
145
+ # config.username = 'jason@example.com'
146
+ # config.token = 'abc123'
147
+ # end
148
+ #
149
+ # categories = SupportOps::Zendesk::HelpCenterCategories.list(limit: 10)
150
+ # pp categories.count
151
+ # # => 10
152
+ # pp categories.last.name
153
+ # # => "I'm the 10th category"
154
+ def self.list(**args)
155
+ args[:limit] = 0 unless args[:limit]
156
+ array = []
157
+ opts = 'page[size]=100'
158
+ opts += "&sort_by=#{args[:sort_by]}" if args[:sort_by]
159
+ opts += "&sort_order=#{args[:sort_order]}" if args[:sort_order]
160
+ locale = if args[:locale].to_s != ''
161
+ "#{args[:locale].to_s}/"
162
+ else
163
+ ''
164
+ end
165
+ url = "help_center/#{locale}categories"
166
+ loop do
167
+ response = client.connection.get("#{url}?#{opts}")
168
+ body = Oj.load(response.body)
169
+ array += body['categories'].map { |c| HelpCenterCategories.new(c) }
170
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
171
+ break unless body['meta']['has_more']
172
+
173
+ opts = body['links']['next'].split('?').last
174
+ end
175
+ return array if args[:limit].to_i.zero?
176
+
177
+ array.first(args[:limit].to_i)
178
+ end
179
+
180
+ ##
181
+ # Locates a category within Zendesk by name. Can utilize a cache for quicker results
182
+ #
183
+ # @author Jason Colyer
184
+ # @since 1.0.0
185
+ # @overload find_by_name(key: value)
186
+ # @param name [String required] The name to search for
187
+ # @param cache [Array] An Array of SupportOps::Zendesk::HelpCenterCategories to use as a cache
188
+ # @return [Object] An instance of {SupportOps::Zendesk::HelpCenterCategories}
189
+ # @example
190
+ # require 'support_ops_zendesk'
191
+ #
192
+ # SupportOps::Zendesk::Configuration.configure do |config|
193
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
194
+ # config.username = 'jason@example.com'
195
+ # config.token = 'abc123'
196
+ # end
197
+ #
198
+ # categories = SupportOps::Zendesk::HelpCenterCategories.list
199
+ # category = SupportOps::Zendesk::HelpCenterCategories.find_by_name(name: 'Test category', cache: categories)
200
+ # pp category.name
201
+ # # => "Test category"
202
+ # pp category.id
203
+ # # => 123456
204
+ def self.find_by_name(**args)
205
+ raise 'You have to provide a name' unless args[:name]
206
+ if args[:cache]
207
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
208
+ categories = args[:cache]
209
+ else
210
+ categories = list
211
+ end
212
+ categories.detect { |s| s.name.downcase == args[:name].to_s.downcase }
213
+ end
214
+
215
+ ##
216
+ # Locates a specific category in the Zendesk system
217
+ #
218
+ # @author Jason Colyer
219
+ # @since 1.0.0
220
+ # @see
221
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/categories/#show-category
222
+ # Zendesk API > Categories > Show Category
223
+ # @see SupportOps::Zendesk::Configuration Setting up a client
224
+ # @example
225
+ # require 'support_ops_zendesk'
226
+ #
227
+ # SupportOps::Zendesk::Configuration.configure do |config|
228
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
229
+ # config.username = 'jason@example.com'
230
+ # config.token = 'abc123'
231
+ # end
232
+ #
233
+ # category = SupportOps::Zendesk::HelpCenterCategories.get(123456)
234
+ # pp category.name
235
+ # # => "Test category"
236
+ def self.get(object)
237
+ if object.is_a? HelpCenterCategories
238
+ HelpCenterCategories.new(id: id).find
239
+ else
240
+ HelpCenterCategories.new(id: object).find
241
+ end
242
+ end
243
+
244
+ ##
245
+ # Locates a specific category in the Zendesk system
246
+ #
247
+ # @author Jason Colyer
248
+ # @since 1.0.0
249
+ # @see
250
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/categories/#show-category
251
+ # Zendesk API > Categories > Show Category
252
+ # @see SupportOps::Zendesk::Configuration Setting up a client
253
+ # @example
254
+ # require 'support_ops_zendesk'
255
+ #
256
+ # SupportOps::Zendesk::Configuration.configure do |config|
257
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
258
+ # config.username = 'jason@example.com'
259
+ # config.token = 'abc123'
260
+ # end
261
+ #
262
+ # category = SupportOps::Zendesk::HelpCenterCategories.get!(123456)
263
+ # pp category.name
264
+ # # => "Test category"
265
+ def self.get!(object)
266
+ if object.is_a? HelpCenterCategories
267
+ HelpCenterCategories.new(id: id).find!
268
+ else
269
+ HelpCenterCategories.new(id: object).find!
270
+ end
271
+ end
272
+
273
+ private
274
+
275
+ ##
276
+ # @private
277
+ def get_record
278
+ response = self.client.connection.get("help_center/categories/#{self.id}")
279
+ return nil if response.status != 200
280
+
281
+ Oj.load(response.body)['category']
282
+ end
283
+
284
+ ##
285
+ # @private
286
+ def create_record
287
+ data = {
288
+ 'description' => self.description,
289
+ 'name' => self.name,
290
+ 'position' => self.position,
291
+ 'locale' => self.locale
292
+ }
293
+ data.delete('position') if data['position'].nil?
294
+ response = self.client.connection.post("help_center/categories", { category: data }.to_json)
295
+ body = Oj.load(response.body)
296
+ raise "Failed to create category => #{body}" if response.status != 201
297
+ body['category']
298
+ end
299
+
300
+ ##
301
+ # @private
302
+ def update_record
303
+ raise "Failed to update category => You didn't change anything in the object" if attributes_for_save.keys == [:id]
304
+ data = {
305
+ 'description' => self.description,
306
+ 'locale' => self.locale,
307
+ 'name' => self.name,
308
+ 'position' => self.position
309
+ }
310
+ data.delete('position') if data['position'].nil?
311
+ response = self.client.connection.put("help_center/categories/#{self.id}", { category: data }.to_json)
312
+ body = Oj.load(response.body)
313
+ raise "Failed to update category #{self.id} => #{body}" if response.status != 200
314
+ body['category']
315
+ end
316
+
317
+ ##
318
+ # @private
319
+ def delete_record
320
+ response = self.client.connection.delete("help_center/categories/#{self.id}")
321
+ raise "Failed to delete category #{self.id} => #{body}" if response.status != 204
322
+ true
323
+ end
324
+
325
+ ##
326
+ # @private
327
+ def translations_record
328
+ Translations.list(self)
329
+ end
330
+ end
331
+ end
332
+ end
@@ -0,0 +1,237 @@
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 HelpCenterContentTags within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at When the content tag was created
13
+ # @attr [String] id Automatically assigned when the content tag is created
14
+ # @attr [String] name The name of the content tag
15
+ # @attr [String] updated_at When the content tag was last updated
16
+ # @todo Count Content Tags > https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#count-content-tags
17
+ # @todo Create Content Tags Job > https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#create-content-tags-job
18
+ class HelpCenterContentTags < SupportOps::Zendesk::Base
19
+ # @!parse
20
+ # # Creates/updates a content tag
21
+ # #
22
+ # # @author Jason Colyer
23
+ # # @since 1.0.0
24
+ # # @return [Object] Instance of {SupportOps::Zendesk::HelpCenterUserSegments}
25
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
26
+ # # @see
27
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#create-content-tag
28
+ # # Zendesk API > Content Tags > Create Content Tag
29
+ # # @see
30
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#update-content-tag
31
+ # # Zendesk API > Content Tags > Update Content Tag
32
+ # # @example
33
+ # # require 'support_ops_zendesk'
34
+ # #
35
+ # # SupportOps::Zendesk::Configuration.configure do |config|
36
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
37
+ # # config.username = 'jason@example.com'
38
+ # # config.token = 'abc123'
39
+ # # end
40
+ # #
41
+ # # new_tag = SupportOps::Zendesk::HelpCenterContentTags.new
42
+ # # new_tag.name = 'Runner'
43
+ # #
44
+ # # new_tag.save!
45
+ # #
46
+ # # pp new_tag.id
47
+ # # # => 122
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
+ # # existing_tag = SupportOps::Zendesk::HelpCenterContentTags.get!(122)
58
+ # # existing_tag.name = 'Runners'
59
+ # #
60
+ # # existing_tag.save!
61
+ # #
62
+ # # pp existing_tag.name
63
+ # # # => "Runners"
64
+ # def save!; end
65
+ # @!parse
66
+ # # Deletes a content tag
67
+ # #
68
+ # # @author Jason Colyer
69
+ # # @since 1.0.0
70
+ # # @return [Boolean]
71
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
72
+ # # @see
73
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#delete-content-tag
74
+ # # Zendesk API > Content Tags > Delete Content Tag
75
+ # # @example
76
+ # # require 'support_ops_zendesk'
77
+ # #
78
+ # # SupportOps::Zendesk::Configuration.configure do |config|
79
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
80
+ # # config.username = 'jason@example.com'
81
+ # # config.token = 'abc123'
82
+ # # end
83
+ # #
84
+ # # existing_tag = SupportOps::Zendesk::HelpCenterContentTags.get!(122)
85
+ # # existing_tag.delete!
86
+ # def delete!; end
87
+ define_attributes :created_at, :id, :name, :updated_at
88
+ readonly_attributes :created_at, :id, :updated_at
89
+
90
+ ##
91
+ # Lists Help Center content tags in the Zendesk system (API docs call it "search")
92
+ #
93
+ # @author Jason Colyer
94
+ # @since 1.0.0
95
+ # @overload list(key: value)
96
+ # @param name_prefix [String optional] A filter to use in listing out
97
+ # tags; requests using the parameter only show content tags with names
98
+ # that start with a specified prefix; if a prefix is not provided or
99
+ # is set to an empty string, the endpoint returns all content tags.
100
+ # @param limit [Integer optional] The limit to the number of user
101
+ # segments returned. Default to 0 (i.e. no limit)
102
+ # @return [Array]
103
+ # @see
104
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#search-content-tags
105
+ # Zendesk API > Content Tags > Search Content Tags
106
+ # @see SupportOps::Zendesk::Configuration Setting up a client
107
+ # @example
108
+ # require 'support_ops_zendesk'
109
+ #
110
+ # SupportOps::Zendesk::Configuration.configure do |config|
111
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
112
+ # config.username = 'jason@example.com'
113
+ # config.token = 'abc123'
114
+ # end
115
+ #
116
+ # tags = SupportOps::Zendesk::HelpCenterContentTags.list(limit: 10)
117
+ # pp tags.count
118
+ # # => 10
119
+ # pp tags.last.name
120
+ # # => "Docker"
121
+ def self.list(**args)
122
+ args[:limit] = 0 unless args[:limit]
123
+ array = []
124
+ opts = 'page[size]=30'
125
+ opts += "&filter[name_prefix]=#{args[:name_prefix]}" unless args[:name_prefix].to_s == ''
126
+ loop do
127
+ response = client.connection.get("guide/content_tags?#{opts}")
128
+ body = Oj.load(response.body)
129
+ array += body['records'].map { |r| HelpCenterContentTags.new(r) }
130
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
131
+ break unless body['meta']['has_more']
132
+
133
+ opts = body['links']['next'].split('?').last
134
+ end
135
+ return array if args[:limit].to_i.zero?
136
+
137
+ array.first(args[:limit].to_i)
138
+ end
139
+
140
+ ##
141
+ # Locates a specific content tag in the Zendesk system
142
+ #
143
+ # @author Jason Colyer
144
+ # @since 1.0.0
145
+ # @see
146
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#show-content-tag
147
+ # Zendesk API > Content Tags > Show Content Tag
148
+ # @see SupportOps::Zendesk::Configuration Setting up a client
149
+ # @example
150
+ # require 'support_ops_zendesk'
151
+ #
152
+ # SupportOps::Zendesk::Configuration.configure do |config|
153
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
154
+ # config.username = 'jason@example.com'
155
+ # config.token = 'abc123'
156
+ # end
157
+ #
158
+ # tag = SupportOps::Zendesk::HelpCenterContentTags.get(123456)
159
+ # pp tag.name
160
+ # # => "Geo"
161
+ def self.get(object)
162
+ if object.is_a? HelpCenterContentTags
163
+ HelpCenterContentTags.new(id: id).find
164
+ else
165
+ HelpCenterContentTags.new(id: object).find
166
+ end
167
+ end
168
+
169
+ ##
170
+ # Locates a specific content tag in the Zendesk system
171
+ #
172
+ # @author Jason Colyer
173
+ # @since 1.0.0
174
+ # @see
175
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/content_tags/#show-content-tag
176
+ # Zendesk API > Content Tags > Show Content Tag
177
+ # @see SupportOps::Zendesk::Configuration Setting up a client
178
+ # @example
179
+ # require 'support_ops_zendesk'
180
+ #
181
+ # SupportOps::Zendesk::Configuration.configure do |config|
182
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
183
+ # config.username = 'jason@example.com'
184
+ # config.token = 'abc123'
185
+ # end
186
+ #
187
+ # tag = SupportOps::Zendesk::HelpCenterContentTags.get!(123456)
188
+ # pp tag.name
189
+ # # => "Geo"
190
+ def self.get!(object)
191
+ if object.is_a? HelpCenterContentTags
192
+ HelpCenterContentTags.new(id: id).find!
193
+ else
194
+ HelpCenterContentTags.new(id: object).find!
195
+ end
196
+ end
197
+
198
+ private
199
+
200
+ ##
201
+ # @private
202
+ def get_record
203
+ response = self.client.connection.get("guide/content_tags/#{self.id}")
204
+ return nil if response.status != 200
205
+
206
+ Oj.load(response.body)['content_tag']
207
+ end
208
+
209
+ ##
210
+ # @private
211
+ def create_record
212
+ response = self.client.connection.post("guide/content_tags", { content_tag: attributes_for_save }.to_json)
213
+ body = Oj.load(response.body)
214
+ raise "Failed to create content tag => #{body}" if response.status != 201
215
+ body['content_tag']
216
+ end
217
+
218
+ ##
219
+ # @private
220
+ def update_record
221
+ raise "Failed to update user segment => You didn't change anything in the object" if attributes_for_save.keys == [:id]
222
+ response = self.client.connection.put("guide/content_tags/#{self.id}", { content_tag: attributes_for_save }.to_json)
223
+ body = Oj.load(response.body)
224
+ raise "Failed to update content tag #{self.id} => #{body}" if response.status != 200
225
+ body['content_tag']
226
+ end
227
+
228
+ ##
229
+ # @private
230
+ def delete_record
231
+ response = self.client.connection.delete("guide/content_tags/#{self.id}")
232
+ raise "Failed to delete content tag #{self.id} => #{body}" if response.status != 204
233
+ true
234
+ end
235
+ end
236
+ end
237
+ end