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,271 @@
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 HelpCenterManagementPermissionGroups within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Boolean] built_in Whether the permission group is built-in; built-in permission groups cannot be modified
13
+ # @attr [String] created_at When the permission group was created
14
+ # @attr [Array] edit The ids of user segments that have edit privileges
15
+ # @attr [Integer] id Automatically assigned when the permission group is created
16
+ # @attr [String] name Permission group name
17
+ # @attr [Array] publish The ids of user segments that have publish privileges
18
+ # @attr [String] updated_at When the permission group was last updated
19
+ class HelpCenterManagementPermissionGroups < SupportOps::Zendesk::Base
20
+ # @!parse
21
+ # # Creates/updates a management permission group
22
+ # #
23
+ # # @author Jason Colyer
24
+ # # @since 1.0.0
25
+ # # @return [Object] Instance of {SupportOps::Zendesk::HelpCenterManagementPermissionGroups}
26
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
27
+ # # @see
28
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/permission_groups/#create-permission-group
29
+ # # Zendesk API > Management Permission Groups > Create Permission Group
30
+ # # @see
31
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/permission_groups/#update-permission-group
32
+ # # Zendesk API > Management Permission Groups > Update Permission Group
33
+ # # @example
34
+ # # require 'support_ops_zendesk'
35
+ # #
36
+ # # SupportOps::Zendesk::Configuration.configure do |config|
37
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
38
+ # # config.username = 'jason@example.com'
39
+ # # config.token = 'abc123'
40
+ # # end
41
+ # #
42
+ # # new_group = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.new
43
+ # # new_group.name = 'Publisher'
44
+ # # new_group.edit = [123456]
45
+ # # new_group.publish = [123456]
46
+ # #
47
+ # # new_group.save!
48
+ # #
49
+ # # pp new_group.id
50
+ # # # => 122
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
+ # # existing_group = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.new
61
+ # # existing_group.name = 'Publishers'
62
+ # #
63
+ # # existing_group.save!
64
+ # #
65
+ # # pp existing_group.name
66
+ # # # => "Publishers"
67
+ # def save!; end
68
+ # @!parse
69
+ # # Deletes a management permission group
70
+ # #
71
+ # # @author Jason Colyer
72
+ # # @since 1.0.0
73
+ # # @return [Boolean]
74
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
75
+ # # @see
76
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/permission_groups/#delete-permission-group
77
+ # # Zendesk API > Management Permission Groups > Delete Permission Group
78
+ # # @example
79
+ # # require 'support_ops_zendesk'
80
+ # #
81
+ # # SupportOps::Zendesk::Configuration.configure do |config|
82
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
83
+ # # config.username = 'jason@example.com'
84
+ # # config.token = 'abc123'
85
+ # # end
86
+ # #
87
+ # # existing_group = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.get!(122)
88
+ # # existing_group.delete!
89
+ # def delete!; end
90
+ define_attributes :built_in, :created_at, :edit, :id, :name, :publish,
91
+ :updated_at
92
+ readonly_attributes :built_in, :created_at, :id, :updated_at
93
+
94
+ ##
95
+ # Lists Help Center management permission groups in the Zendesk system
96
+ #
97
+ # @author Jason Colyer
98
+ # @since 1.0.0
99
+ # @overload list(key: value)
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/permission_groups/#list-permission-groups
105
+ # Zendesk API > Management Permission Groups > List Permission Groups
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
+ # groups = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.list(limit: 10)
117
+ # pp groups.count
118
+ # # => 5
119
+ # pp groups.last.name
120
+ # # => "5th management permission group"
121
+ def self.list(**args)
122
+ args[:limit] = 0 unless args[:limit]
123
+ array = []
124
+ page = 1
125
+ loop do
126
+ response = client.connection.get("guide/permission_groups?page=#{page}")
127
+ body = Oj.load(response.body)
128
+ array += body['permission_groups'].map { |p| HelpCenterManagementPermissionGroups.new(p) }
129
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
130
+ break unless body['permission_groups'].count == 100
131
+
132
+ page += 1
133
+ end
134
+ return array if args[:limit].to_i.zero?
135
+
136
+ array.first(args[:limit].to_i)
137
+ end
138
+
139
+ ##
140
+ # Locates a management permission group within Zendesk by name. Can utilize a cache for quicker results
141
+ #
142
+ # @author Jason Colyer
143
+ # @since 1.0.0
144
+ # @overload find_by_name(key: value)
145
+ # @param name [String required] The name to search for
146
+ # @param cache [Array] An Array of SupportOps::Zendesk::HelpCenterManagementPermissionGroups to use as a cache
147
+ # @return [Object] An instance of {SupportOps::Zendesk::HelpCenterManagementPermissionGroups}
148
+ # @example
149
+ # require 'support_ops_zendesk'
150
+ #
151
+ # SupportOps::Zendesk::Configuration.configure do |config|
152
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
153
+ # config.username = 'jason@example.com'
154
+ # config.token = 'abc123'
155
+ # end
156
+ #
157
+ # groups = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.list
158
+ # group = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.find_by_name(name: 'Admins', cache: groups)
159
+ # pp group.name
160
+ # # => "Admins"
161
+ # pp segment.id
162
+ # # => 123456
163
+ def self.find_by_name(**args)
164
+ raise 'You have to provide a name' unless args[:name]
165
+ if args[:cache]
166
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
167
+ groups = args[:cache]
168
+ else
169
+ groups = list
170
+ end
171
+ groups.detect { |s| s.name.downcase == args[:name].to_s.downcase }
172
+ end
173
+
174
+ ##
175
+ # Locates a specific management permission group in the Zendesk system
176
+ #
177
+ # @author Jason Colyer
178
+ # @since 1.0.0
179
+ # @see
180
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/permission_groups/#show-permission-group
181
+ # Zendesk API > Management Permission Groups > Show Permission Group
182
+ # @see SupportOps::Zendesk::Configuration Setting up a client
183
+ # @example
184
+ # require 'support_ops_zendesk'
185
+ #
186
+ # SupportOps::Zendesk::Configuration.configure do |config|
187
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
188
+ # config.username = 'jason@example.com'
189
+ # config.token = 'abc123'
190
+ # end
191
+ #
192
+ # group = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.get(123456)
193
+ # pp group.name
194
+ # # => "Admins"
195
+ def self.get(object)
196
+ if object.is_a? HelpCenterManagementPermissionGroups
197
+ HelpCenterManagementPermissionGroups.new(id: id).find
198
+ else
199
+ HelpCenterManagementPermissionGroups.new(id: object).find
200
+ end
201
+ end
202
+
203
+ ##
204
+ # Locates a specific management permission group in the Zendesk system
205
+ #
206
+ # @author Jason Colyer
207
+ # @since 1.0.0
208
+ # @see
209
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/permission_groups/#show-permission-group
210
+ # Zendesk API > Management Permission Groups > Show Permission Group
211
+ # @see SupportOps::Zendesk::Configuration Setting up a client
212
+ # @example
213
+ # require 'support_ops_zendesk'
214
+ #
215
+ # SupportOps::Zendesk::Configuration.configure do |config|
216
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
217
+ # config.username = 'jason@example.com'
218
+ # config.token = 'abc123'
219
+ # end
220
+ #
221
+ # group = SupportOps::Zendesk::HelpCenterManagementPermissionGroups.get!(123456)
222
+ # pp group.name
223
+ # # => "Admins"
224
+ def self.get!(object)
225
+ if object.is_a? HelpCenterManagementPermissionGroups
226
+ HelpCenterManagementPermissionGroups.new(id: id).find!
227
+ else
228
+ HelpCenterManagementPermissionGroups.new(id: object).find!
229
+ end
230
+ end
231
+
232
+ private
233
+
234
+ ##
235
+ # @private
236
+ def get_record
237
+ response = self.client.connection.get("guide/permission_groups/#{self.id}")
238
+ return nil if response.status != 200
239
+
240
+ Oj.load(response.body)['permission_group']
241
+ end
242
+
243
+ ##
244
+ # @private
245
+ def create_record
246
+ response = self.client.connection.post("guide/permission_groups", { permission_group: attributes_for_save }.to_json)
247
+ body = Oj.load(response.body)
248
+ raise "Failed to create management permission group => #{body}" if response.status != 201
249
+ body['permission_group']
250
+ end
251
+
252
+ ##
253
+ # @private
254
+ def update_record
255
+ raise "Failed to update user segment => You didn't change anything in the object" if attributes_for_save.keys == [:id]
256
+ response = self.client.connection.put("guide/permission_groups/#{self.id}", { permission_group: attributes_for_save }.to_json)
257
+ body = Oj.load(response.body)
258
+ raise "Failed to update management permission group #{self.id} => #{body}" if response.status != 200
259
+ body['permission_group']
260
+ end
261
+
262
+ ##
263
+ # @private
264
+ def delete_record
265
+ response = self.client.connection.delete("guide/permission_groups/#{self.id}")
266
+ raise "Failed to delete management permission group #{self.id} => #{body}" if response.status != 204
267
+ true
268
+ end
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,378 @@
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 HelpCenterSections within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Integer] category_id The id of the category to which this section belongs
13
+ # @attr [String] created_at The time at which the section was created
14
+ # @attr [String] description The description of the section
15
+ # @attr [String] html_url The url of this section in HC
16
+ # @attr [Integer] id Automatically assigned when creating subscriptions
17
+ # @attr [String] locale The locale in which the section is displayed
18
+ # @attr [String] name The name of the section
19
+ # @attr [Boolean] outdated Whether the section is out of date
20
+ # @attr [Integer] parent_section_id The id of the section to which this section belongs
21
+ # @attr [Integer] position The position of this section in the section list; used when sorting is set to 'manual'; by default the section is added to the end of the list
22
+ # @attr [String] source_locale The source (default) locale of the section
23
+ # @attr [String] theme_template The theme template name used to display this section in Help Center
24
+ # @attr [String] updated_at The time at which the section was last updated
25
+ # @todo Update Section Source Locale > https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#update-section-source-locale
26
+ class HelpCenterSections < SupportOps::Zendesk::Base
27
+ # @!parse
28
+ # # Creates/updates a section
29
+ # #
30
+ # # @author Jason Colyer
31
+ # # @since 1.0.0
32
+ # # @return [Object] Instance of {SupportOps::Zendesk::HelpCenterSections}
33
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
34
+ # # @see
35
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#create-section
36
+ # # Zendesk API > Sections > Create Section
37
+ # # @see
38
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#update-section
39
+ # # Zendesk API > Sections > Update Section
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
+ # # new_section = SupportOps::Zendesk::HelpCenterSections.new
50
+ # # new_section.name = 'Docker'
51
+ # # new_section.category_id = 456
52
+ # # new_section.locale = 'en-us'
53
+ # # new_section.position = 4
54
+ # # new_section.description = 'This is for Docker articles'
55
+ # #
56
+ # # new_section.save!
57
+ # #
58
+ # # pp new_section.id
59
+ # # # => 122
60
+ # # @example
61
+ # # require 'support_ops_zendesk'
62
+ # #
63
+ # # SupportOps::Zendesk::Configuration.configure do |config|
64
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
65
+ # # config.username = 'jason@example.com'
66
+ # # config.token = 'abc123'
67
+ # # end
68
+ # #
69
+ # # existing_section = SupportOps::Zendesk::HelpCenterSections.get!(122)
70
+ # # existing_section.position = existing_section.position + 1
71
+ # #
72
+ # # existing_section.save!
73
+ # #
74
+ # # pp existing_section.position
75
+ # # # => 5
76
+ # def save!; end
77
+ # @!parse
78
+ # # Deletes a section
79
+ # #
80
+ # # @author Jason Colyer
81
+ # # @since 1.0.0
82
+ # # @return [Boolean]
83
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
84
+ # # @see
85
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#delete-section
86
+ # # Zendesk API > Sections > Delete Section
87
+ # # @example
88
+ # # require 'support_ops_zendesk'
89
+ # #
90
+ # # SupportOps::Zendesk::Configuration.configure do |config|
91
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
92
+ # # config.username = 'jason@example.com'
93
+ # # config.token = 'abc123'
94
+ # # end
95
+ # #
96
+ # # existing_section = SupportOps::Zendesk::HelpCenterSections.get!(122)
97
+ # # existing_section.delete!
98
+ # def delete!; end
99
+ # @!parse
100
+ # # Shows info on the parent section (if one exists)
101
+ # #
102
+ # # @author Jason Colyer
103
+ # # @since 1.0.0
104
+ # # @note This is inherited from {SupportOps::Zendesk::Base#parent}
105
+ # # @see
106
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#show-section
107
+ # # Zendesk API > Sections > Show Section
108
+ # # @example
109
+ # # require 'support_ops_zendesk'
110
+ # #
111
+ # # SupportOps::Zendesk::Configuration.configure do |config|
112
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
113
+ # # config.username = 'jason@example.com'
114
+ # # config.token = 'abc123'
115
+ # # end
116
+ # #
117
+ # # existing_section = SupportOps::Zendesk::HelpCenterSections.get!(122)
118
+ # # parent = existing_section.parent
119
+ # # pp parent.name
120
+ # # # => "Support Pages"
121
+ # def parent; end
122
+ # @!parse
123
+ # # Lists translations
124
+ # #
125
+ # # @author Jason Colyer
126
+ # # @since 1.0.0
127
+ # # @note This is inherited from {SupportOps::Zendesk::Base#translations}
128
+ # # @see
129
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/translations/#list-translations
130
+ # # Zendesk API > Translations > Show Translations
131
+ # # @example
132
+ # # require 'support_ops_zendesk'
133
+ # #
134
+ # # SupportOps::Zendesk::Configuration.configure do |config|
135
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
136
+ # # config.username = 'jason@example.com'
137
+ # # config.token = 'abc123'
138
+ # # end
139
+ # #
140
+ # # existing_section = SupportOps::Zendesk::HelpCenterSections.get!(122)
141
+ # # translations = existing_section.translations
142
+ # # pp translations.count
143
+ # # # => 2
144
+ # def parent; end
145
+ define_attributes :category_id, :created_at, :description, :html_url, :id,
146
+ :locale, :name, :outdated, :parent_section_id,
147
+ :position, :source_locale, :theme_template, :updated_at
148
+ readonly_attributes :created_at, :html_url, :id, :outdated,
149
+ :source_locale, :updated_at
150
+
151
+ ##
152
+ # Lists Help Center sections in the Zendesk system
153
+ #
154
+ # @author Jason Colyer
155
+ # @since 1.0.0
156
+ # @overload list(key: value)
157
+ # @param locale [String optional] Filter sections by a specific locale
158
+ # @param category_id [Integer optional] Filter sections by a category
159
+ # @param sort_by [String optional] Possible values are "position",
160
+ # "created_at", "updated_at" (defauls to "position")
161
+ # @param sort_order [String optional] One of "asc" or "desc"
162
+ # @param limit [Integer optional] The limit to the number of sections
163
+ # returned. Default to 0 (i.e. no limit)
164
+ # @return [Array]
165
+ # @see
166
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#list-sections
167
+ # Zendesk API > Sections > List Sections
168
+ # @see SupportOps::Zendesk::Configuration Setting up a client
169
+ # @example
170
+ # require 'support_ops_zendesk'
171
+ #
172
+ # SupportOps::Zendesk::Configuration.configure do |config|
173
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
174
+ # config.username = 'jason@example.com'
175
+ # config.token = 'abc123'
176
+ # end
177
+ #
178
+ # sections = SupportOps::Zendesk::HelpCenterSections.list(limit: 10)
179
+ # pp sections.count
180
+ # # => 10
181
+ # pp sections.last.name
182
+ # # => "I'm the 10th section"
183
+ def self.list(**args)
184
+ args[:limit] = 0 unless args[:limit]
185
+ array = []
186
+ opts = 'page[size]=100'
187
+ opts += "&sort_by=#{args[:sort_by]}" if args[:sort_by]
188
+ opts += "&sort_order=#{args[:sort_order]}" if args[:sort_order]
189
+ locale = if args[:locale].to_s != ''
190
+ "#{args[:locale].to_s}/"
191
+ else
192
+ ''
193
+ end
194
+ category = if args[:category_id].to_i != 0
195
+ "categories/#{args[:category_id].to_i}/"
196
+ else
197
+ ''
198
+ end
199
+ url = "help_center/#{locale}#{category}sections"
200
+ loop do
201
+ response = client.connection.get("#{url}?#{opts}")
202
+ body = Oj.load(response.body)
203
+ array += body['sections'].map { |s| HelpCenterSections.new(s) }
204
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
205
+ break unless body['meta']['has_more']
206
+
207
+ opts = body['links']['next'].split('?').last
208
+ end
209
+ return array if args[:limit].to_i.zero?
210
+
211
+ array.first(args[:limit].to_i)
212
+ end
213
+
214
+ ##
215
+ # Locates a section within Zendesk by name. Can utilize a cache for quicker results
216
+ #
217
+ # @author Jason Colyer
218
+ # @since 1.0.0
219
+ # @overload find_by_name(key: value)
220
+ # @param name [String required] The name to search for
221
+ # @param cache [Array] An Array of SupportOps::Zendesk::HelpCenterSections to use as a cache
222
+ # @return [Object] An instance of {SupportOps::Zendesk::HelpCenterSections}
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
+ # sections = SupportOps::Zendesk::HelpCenterSections.list
233
+ # section = SupportOps::Zendesk::HelpCenterSections.find_by_name(name: 'Test Section', cache: sections)
234
+ # pp section.name
235
+ # # => "Test Section"
236
+ # pp section.id
237
+ # # => 123456
238
+ def self.find_by_name(**args)
239
+ raise 'You have to provide a name' unless args[:name]
240
+ if args[:cache]
241
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
242
+ sections = args[:cache]
243
+ else
244
+ sections = list
245
+ end
246
+ sections.detect { |s| s.name.downcase == args[:name].to_s.downcase }
247
+ end
248
+
249
+ ##
250
+ # Locates a specific section in the Zendesk system
251
+ #
252
+ # @author Jason Colyer
253
+ # @since 1.0.0
254
+ # @see
255
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#show-section
256
+ # Zendesk API > Sections > Show Section
257
+ # @see SupportOps::Zendesk::Configuration Setting up a client
258
+ # @example
259
+ # require 'support_ops_zendesk'
260
+ #
261
+ # SupportOps::Zendesk::Configuration.configure do |config|
262
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
263
+ # config.username = 'jason@example.com'
264
+ # config.token = 'abc123'
265
+ # end
266
+ #
267
+ # section = SupportOps::Zendesk::HelpCenterSections.get(123456)
268
+ # pp section.name
269
+ # # => "Test Section"
270
+ def self.get(object)
271
+ if object.is_a? HelpCenterSections
272
+ HelpCenterSections.new(id: id).find
273
+ else
274
+ HelpCenterSections.new(id: object).find
275
+ end
276
+ end
277
+
278
+ ##
279
+ # Locates a specific section in the Zendesk system
280
+ #
281
+ # @author Jason Colyer
282
+ # @since 1.0.0
283
+ # @see
284
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/#show-section
285
+ # Zendesk API > Sections > Show Section
286
+ # @see SupportOps::Zendesk::Configuration Setting up a client
287
+ # @example
288
+ # require 'support_ops_zendesk'
289
+ #
290
+ # SupportOps::Zendesk::Configuration.configure do |config|
291
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
292
+ # config.username = 'jason@example.com'
293
+ # config.token = 'abc123'
294
+ # end
295
+ #
296
+ # section = SupportOps::Zendesk::HelpCenterSections.get!(123456)
297
+ # pp section.name
298
+ # # => "Test Section"
299
+ def self.get!(object)
300
+ if object.is_a? HelpCenterSections
301
+ HelpCenterSections.new(id: id).find!
302
+ else
303
+ HelpCenterSections.new(id: object).find!
304
+ end
305
+ end
306
+
307
+ private
308
+
309
+ ##
310
+ # @private
311
+ def get_record
312
+ response = self.client.connection.get("help_center/sections/#{self.id}")
313
+ return nil if response.status != 200
314
+
315
+ Oj.load(response.body)['section']
316
+ end
317
+
318
+ ##
319
+ # @private
320
+ def create_record
321
+ data = {
322
+ 'name' => self.name,
323
+ 'description' => self.description,
324
+ 'position' => self.position,
325
+ 'locale' => self.locale,
326
+ 'parent_section_id' => self.parent_section_id,
327
+ 'theme_template' => self.theme_template
328
+ }
329
+ data.delete('position') if data['position'].nil?
330
+ response = self.client.connection.post("help_center/categories/#{self.category_id}/sections", { section: data }.to_json)
331
+ body = Oj.load(response.body)
332
+ raise "Failed to create section => #{body}" if response.status != 201
333
+ body['section']
334
+ end
335
+
336
+ ##
337
+ # @private
338
+ def update_record
339
+ raise "Failed to update section => You didn't change anything in the object" if attributes_for_save.keys == [:id]
340
+ data = {
341
+ 'name' => self.name,
342
+ 'description' => self.description,
343
+ 'position' => self.position,
344
+ 'category_id' => self.category_id,
345
+ 'parent_section_id' => self.parent_section_id,
346
+ 'theme_template' => self.theme_template
347
+ }
348
+ data.delete('position') if data['position'].nil?
349
+ response = self.client.connection.put("help_center/#{self.locale}/sections/#{self.id}", { section: data }.to_json)
350
+ body = Oj.load(response.body)
351
+ raise "Failed to update section #{self.id} => #{body}" if response.status != 200
352
+ body['section']
353
+ end
354
+
355
+ ##
356
+ # @private
357
+ def delete_record
358
+ response = self.client.connection.delete("help_center/sections/#{self.id}")
359
+ raise "Failed to delete section #{self.id} => #{body}" if response.status != 204
360
+ true
361
+ end
362
+
363
+ ##
364
+ # @private
365
+ def parent_record
366
+ return nil if self.parent_section_id.nil?
367
+
368
+ HelpCenterSections.get(self.parent_section_id)
369
+ end
370
+
371
+ ##
372
+ # @private
373
+ def translations_record
374
+ Translations.list(self)
375
+ end
376
+ end
377
+ end
378
+ end