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,274 @@
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 HelpCenterTopics within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at When the topic was created
13
+ # @attr [String] description The description of the topic. By default an empty string
14
+ # @attr [Integer] follower_count The number of users following the topic
15
+ # @attr [String] html_url The community url of the topic
16
+ # @attr [Integer] id Automatically assigned when the topic is created
17
+ # @attr [String] manageable_by The set of users who can manage this topic; allowed values are "staff", or "managers".
18
+ # @attr [String] name The name of the topic
19
+ # @attr [Integer] position The position of the topic relative to other topics in the community
20
+ # @attr [String] updated_at When the topic was last updated
21
+ # @attr [Integer] user_segment_id The id of the user segment to which this topic belongs
22
+ class HelpCenterTopics < SupportOps::Zendesk::Base
23
+ # @!parse
24
+ # # Creates/updates a topic
25
+ # #
26
+ # # @author Jason Colyer
27
+ # # @since 1.0.0
28
+ # # @return [Object] Instance of {SupportOps::Zendesk::HelpCenterSections}
29
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
30
+ # # @see
31
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/topics/#create-topic
32
+ # # Zendesk API > Topics > Create Topic
33
+ # # @see
34
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/topics/#update-topic
35
+ # # Zendesk API > Topics > Update Topic
36
+ # # @example
37
+ # # require 'support_ops_zendesk'
38
+ # #
39
+ # # SupportOps::Zendesk::Configuration.configure do |config|
40
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
41
+ # # config.username = 'jason@example.com'
42
+ # # config.token = 'abc123'
43
+ # # end
44
+ # #
45
+ # # new_topic = SupportOps::Zendesk::HelpCenterTopics.new
46
+ # # new_topic.name = 'Backups'
47
+ # #
48
+ # # new_topic.save!
49
+ # #
50
+ # # pp new_topic.id
51
+ # # # => 122
52
+ # # @example
53
+ # # require 'support_ops_zendesk'
54
+ # #
55
+ # # SupportOps::Zendesk::Configuration.configure do |config|
56
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
57
+ # # config.username = 'jason@example.com'
58
+ # # config.token = 'abc123'
59
+ # # end
60
+ # #
61
+ # # existing_topic = SupportOps::Zendesk::HelpCenterTopics.get!(122)
62
+ # # existing_topic.name = 'Backups and Restores'
63
+ # #
64
+ # # existing_topic.save!
65
+ # #
66
+ # # pp existing_topic.name
67
+ # # # => "Backups and Restores"
68
+ # def save!; end
69
+ # @!parse
70
+ # # Deletes a topic
71
+ # #
72
+ # # @author Jason Colyer
73
+ # # @since 1.0.0
74
+ # # @return [Boolean]
75
+ # # @note This is inherited from {SupportOps::Zendesk::Base#delete!}
76
+ # # @see
77
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/topics/#delete-topic
78
+ # # Zendesk API > Topics > Delete Topic
79
+ # # @example
80
+ # # require 'support_ops_zendesk'
81
+ # #
82
+ # # SupportOps::Zendesk::Configuration.configure do |config|
83
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
84
+ # # config.username = 'jason@example.com'
85
+ # # config.token = 'abc123'
86
+ # # end
87
+ # #
88
+ # # existing_topic = SupportOps::Zendesk::HelpCenterTopics.get!(122)
89
+ # # existing_topic.delete!
90
+ # def delete!; end
91
+ define_attributes :created_at, :description, :follower_count, :html_url,
92
+ :id, :manageable_by, :name, :position, :updated_at,
93
+ :user_segment_id
94
+ readonly_attributes :created_at, :follower_count, :html_url, :id,
95
+ :updated_at
96
+
97
+ ##
98
+ # Lists Help Center topics in the Zendesk system
99
+ #
100
+ # @author Jason Colyer
101
+ # @since 1.0.0
102
+ # @overload list(key: value)
103
+ # @param limit [Integer optional] The limit to the number of sections
104
+ # returned. Default to 0 (i.e. no limit)
105
+ # @return [Array]
106
+ # @see
107
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/topics/#list-topics
108
+ # Zendesk API > Topics > List Topics
109
+ # @see SupportOps::Zendesk::Configuration Setting up a client
110
+ # @example
111
+ # require 'support_ops_zendesk'
112
+ #
113
+ # SupportOps::Zendesk::Configuration.configure do |config|
114
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
115
+ # config.username = 'jason@example.com'
116
+ # config.token = 'abc123'
117
+ # end
118
+ #
119
+ # topcis = SupportOps::Zendesk::HelpCenterTopics.list(limit: 10)
120
+ # pp topcis.count
121
+ # # => 10
122
+ # pp topcis.last.name
123
+ # # => "I'm the 10th topic"
124
+ def self.list(**args)
125
+ args[:limit] = 0 unless args[:limit]
126
+ array = []
127
+ opts = 'page[size]=100'
128
+ loop do
129
+ response = client.connection.get("community/topics?#{opts}")
130
+ body = Oj.load(response.body)
131
+ array += body['topics'].map { |t| HelpCenterTopics.new(t) }
132
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
133
+ break unless body['meta']['has_more']
134
+
135
+ opts = body['links']['next'].split('?').last
136
+ end
137
+ return array if args[:limit].to_i.zero?
138
+
139
+ array.first(args[:limit].to_i)
140
+ end
141
+
142
+ ##
143
+ # Locates a topic within Zendesk by name. Can utilize a cache for quicker results
144
+ #
145
+ # @author Jason Colyer
146
+ # @since 1.0.0
147
+ # @overload find_by_name(key: value)
148
+ # @param name [String required] The name to search for
149
+ # @param cache [Array] An Array of SupportOps::Zendesk::HelpCenterTopics to use as a cache
150
+ # @return [Object] An instance of {SupportOps::Zendesk::HelpCenterTopics}
151
+ # @example
152
+ # require 'support_ops_zendesk'
153
+ #
154
+ # SupportOps::Zendesk::Configuration.configure do |config|
155
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
156
+ # config.username = 'jason@example.com'
157
+ # config.token = 'abc123'
158
+ # end
159
+ #
160
+ # topics = SupportOps::Zendesk::HelpCenterTopics.list
161
+ # topic = SupportOps::Zendesk::HelpCenterTopics.find_by_name(name: 'Test topic', cache: topics)
162
+ # pp topic.name
163
+ # # => "Test topic"
164
+ # pp topic.id
165
+ # # => 123456
166
+ def self.find_by_name(**args)
167
+ raise 'You have to provide a name' unless args[:name]
168
+ if args[:cache]
169
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
170
+ topics = args[:cache]
171
+ else
172
+ topics = list
173
+ end
174
+ topics.detect { |s| s.name.downcase == args[:name].to_s.downcase }
175
+ end
176
+
177
+ ##
178
+ # Locates a specific topic in the Zendesk system
179
+ #
180
+ # @author Jason Colyer
181
+ # @since 1.0.0
182
+ # @see
183
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/topics/#show-topic
184
+ # Zendesk API > Topics > Show Topic
185
+ # @see SupportOps::Zendesk::Configuration Setting up a client
186
+ # @example
187
+ # require 'support_ops_zendesk'
188
+ #
189
+ # SupportOps::Zendesk::Configuration.configure do |config|
190
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
191
+ # config.username = 'jason@example.com'
192
+ # config.token = 'abc123'
193
+ # end
194
+ #
195
+ # topic = SupportOps::Zendesk::HelpCenterTopics.get(123456)
196
+ # pp topic.name
197
+ # # => "Test topic"
198
+ def self.get(object)
199
+ if object.is_a? HelpCenterTopics
200
+ HelpCenterTopics.new(id: id).find
201
+ else
202
+ HelpCenterTopics.new(id: object).find
203
+ end
204
+ end
205
+
206
+ ##
207
+ # Locates a specific topic in the Zendesk system
208
+ #
209
+ # @author Jason Colyer
210
+ # @since 1.0.0
211
+ # @see
212
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/topics/#show-topic
213
+ # Zendesk API > Topics > Show Topic
214
+ # @see SupportOps::Zendesk::Configuration Setting up a client
215
+ # @example
216
+ # require 'support_ops_zendesk'
217
+ #
218
+ # SupportOps::Zendesk::Configuration.configure do |config|
219
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
220
+ # config.username = 'jason@example.com'
221
+ # config.token = 'abc123'
222
+ # end
223
+ #
224
+ # topic = SupportOps::Zendesk::HelpCenterTopics.get!(123456)
225
+ # pp topic.name
226
+ # # => "Test topic"
227
+ def self.get!(object)
228
+ if object.is_a? HelpCenterTopics
229
+ HelpCenterTopics.new(id: id).find!
230
+ else
231
+ HelpCenterTopics.new(id: object).find!
232
+ end
233
+ end
234
+
235
+ private
236
+
237
+ ##
238
+ # @private
239
+ def get_record
240
+ response = self.client.connection.get("community/topics/#{self.id}")
241
+ return nil if response.status != 200
242
+
243
+ Oj.load(response.body)['topic']
244
+ end
245
+
246
+ ##
247
+ # @private
248
+ def create_record
249
+ response = self.client.connection.post('community/topics', { topic: attributes_for_save.compact }.to_json)
250
+ body = Oj.load(response.body)
251
+ raise "Failed to create topic => #{body}" if response.status != 201
252
+ body['topic']
253
+ end
254
+
255
+ ##
256
+ # @private
257
+ def update_record
258
+ raise "Failed to update topic => You didn't change anything in the object" if attributes_for_save.keys == [:id]
259
+ response = self.client.connection.put("community/topics/#{self.id}", { topic: attributes_for_save }.to_json)
260
+ body = Oj.load(response.body)
261
+ raise "Failed to update topic #{self.id} => #{body}" if response.status != 200
262
+ body['topic']
263
+ end
264
+
265
+ ##
266
+ # @private
267
+ def delete_record
268
+ response = self.client.connection.delete("community/topics/#{self.id}")
269
+ raise "Failed to delete topic => #{body}" if response.status != 204
270
+ true
271
+ end
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,279 @@
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 HelpCenterUserSegments within the module {SupportOps::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Array] added_user_ids The ids of users added specifically to this user segment, regardless of matching tags or other criteria
13
+ # @attr [Boolean] built_in Whether the user segment is built-in. Built-in user segments cannot be modified
14
+ # @attr [String] created_at When the user segment was created
15
+ # @attr [Array] group_ids The ids of the groups that have access
16
+ # @attr [Integer] id Automatically assigned when the user segment is created
17
+ # @attr [String] name User segment name (localized to the locale of the current user for built-in user segments)
18
+ # @attr [Array] or_tags A user must have at least one tag in the list to have access
19
+ # @attr [Array] organization_ids The ids of the organizations that have access
20
+ # @attr [Array] tags All the tags a user must have to have access
21
+ # @attr [String] updated_at When the user segment was last updated
22
+ # @attr [String] user_type The set of users who can view content
23
+ # @todo List Sections with User Segment > https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#list-sections-with-user-segment
24
+ # @todo List Topics with User Segment > https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#list-topics-with-user-segment
25
+ class HelpCenterUserSegments < SupportOps::Zendesk::Base
26
+ # @!parse
27
+ # # Creates/updates a user segment
28
+ # #
29
+ # # @author Jason Colyer
30
+ # # @since 1.0.0
31
+ # # @return [Object] Instance of {SupportOps::Zendesk::HelpCenterUserSegments}
32
+ # # @note This is inherited from {SupportOps::Zendesk::Base#save!}
33
+ # # @see
34
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#create-user-segment
35
+ # # Zendesk API > User Segments > Create User Segment
36
+ # # @see
37
+ # # https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#update-user-segment
38
+ # # Zendesk API > User Segments > Update User Segment
39
+ # # @example
40
+ # # require 'support_ops_zendesk'
41
+ # #
42
+ # # SupportOps::Zendesk::Configuration.configure do |config|
43
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
44
+ # # config.username = 'jason@example.com'
45
+ # # config.token = 'abc123'
46
+ # # end
47
+ # #
48
+ # # new_segment = SupportOps::Zendesk::HelpCenterUserSegments.new
49
+ # # new_segment.name = 'VIP agent'
50
+ # # new_segment.user_type = 'staff'
51
+ # # new_segment.group_ids = [12, 58]
52
+ # # new_segment.tags = ['vip']
53
+ # #
54
+ # # new_segment.save!
55
+ # #
56
+ # # pp new_segment.id
57
+ # # # => 122
58
+ # # @example
59
+ # # require 'support_ops_zendesk'
60
+ # #
61
+ # # SupportOps::Zendesk::Configuration.configure do |config|
62
+ # # config.url = 'https://gitlab.zendesk.com/api/v2'
63
+ # # config.username = 'jason@example.com'
64
+ # # config.token = 'abc123'
65
+ # # end
66
+ # #
67
+ # # existing_segment = SupportOps::Zendesk::HelpCenterUserSegments.get!(122)
68
+ # # existing_segment.name = 'VIP agents'
69
+ # #
70
+ # # existing_segment.save!
71
+ # #
72
+ # # pp existing_segment.name
73
+ # # # => "VIP agents"
74
+ # def save!; end
75
+ # @!parse
76
+ # # Deletes a user segment
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/help_center/help-center-api/user_segments/#delete-user-segment
84
+ # # Zendesk API > User Segments > Delete User Segment
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_segment = SupportOps::Zendesk::HelpCenterUserSegments.get!(122)
95
+ # # existing_segment.delete!
96
+ # def delete!; end
97
+ define_attributes :added_user_ids, :built_in, :created_at, :group_ids,
98
+ :id, :name, :or_tags, :organization_ids, :tags,
99
+ :updated_at, :user_type
100
+ readonly_attributes :built_in, :created_at, :id, :updated_at
101
+
102
+ ##
103
+ # Lists Help Center user segments in the Zendesk system
104
+ #
105
+ # @author Jason Colyer
106
+ # @since 1.0.0
107
+ # @overload list(key: value)
108
+ # @param limit [Integer optional] The limit to the number of user
109
+ # segments returned. Default to 0 (i.e. no limit)
110
+ # @return [Array]
111
+ # @see
112
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#list-user-segments
113
+ # Zendesk API > User Segments > List User Segments
114
+ # @see SupportOps::Zendesk::Configuration Setting up a client
115
+ # @example
116
+ # require 'support_ops_zendesk'
117
+ #
118
+ # SupportOps::Zendesk::Configuration.configure do |config|
119
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
120
+ # config.username = 'jason@example.com'
121
+ # config.token = 'abc123'
122
+ # end
123
+ #
124
+ # segments = SupportOps::Zendesk::HelpCenterUserSegments.list(limit: 10)
125
+ # pp segments.count
126
+ # # => 3
127
+ # pp segments.last.name
128
+ # # => "Publishers"
129
+ def self.list(**args)
130
+ args[:limit] = 0 unless args[:limit]
131
+ array = []
132
+ opts = 'page[size]=100'
133
+ loop do
134
+ response = client.connection.get("help_center/user_segments?#{opts}")
135
+ body = Oj.load(response.body)
136
+ array += body['user_segments'].map { |u| HelpCenterUserSegments.new(u) }
137
+ break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
138
+ break unless body['meta']['has_more']
139
+
140
+ opts = body['links']['next'].split('?').last
141
+ end
142
+ return array if args[:limit].to_i.zero?
143
+
144
+ array.first(args[:limit].to_i)
145
+ end
146
+
147
+ ##
148
+ # Locates a user segment within Zendesk by name. Can utilize a cache for quicker results
149
+ #
150
+ # @author Jason Colyer
151
+ # @since 1.0.0
152
+ # @overload find_by_name(key: value)
153
+ # @param name [String required] The name to search for
154
+ # @param cache [Array] An Array of SupportOps::Zendesk::HelpCenterUserSegments to use as a cache
155
+ # @return [Object] An instance of {SupportOps::Zendesk::HelpCenterUserSegments}
156
+ # @example
157
+ # require 'support_ops_zendesk'
158
+ #
159
+ # SupportOps::Zendesk::Configuration.configure do |config|
160
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
161
+ # config.username = 'jason@example.com'
162
+ # config.token = 'abc123'
163
+ # end
164
+ #
165
+ # segments = SupportOps::Zendesk::HelpCenterUserSegments.list
166
+ # segment = SupportOps::Zendesk::HelpCenterUserSegments.find_by_name(name: 'Publishers', cache: segments)
167
+ # pp segment.name
168
+ # # => "Publishers"
169
+ # pp segment.id
170
+ # # => 123456
171
+ def self.find_by_name(**args)
172
+ raise 'You have to provide a name' unless args[:name]
173
+ if args[:cache]
174
+ raise 'Provided cache is not an Array' unless args[:cache].is_a? Array
175
+ segments = args[:cache]
176
+ else
177
+ segments = list
178
+ end
179
+ segments.detect { |s| s.name.downcase == args[:name].to_s.downcase }
180
+ end
181
+
182
+ ##
183
+ # Locates a specific user segment in the Zendesk system
184
+ #
185
+ # @author Jason Colyer
186
+ # @since 1.0.0
187
+ # @see
188
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#show-user-segment
189
+ # Zendesk API > User Segments > Show User Segment
190
+ # @see SupportOps::Zendesk::Configuration Setting up a client
191
+ # @example
192
+ # require 'support_ops_zendesk'
193
+ #
194
+ # SupportOps::Zendesk::Configuration.configure do |config|
195
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
196
+ # config.username = 'jason@example.com'
197
+ # config.token = 'abc123'
198
+ # end
199
+ #
200
+ # segment = SupportOps::Zendesk::HelpCenterUserSegments.get(123456)
201
+ # pp section.name
202
+ # # => "Publishers"
203
+ def self.get(object)
204
+ if object.is_a? HelpCenterUserSegments
205
+ HelpCenterUserSegments.new(id: id).find
206
+ else
207
+ HelpCenterUserSegments.new(id: object).find
208
+ end
209
+ end
210
+
211
+ ##
212
+ # Locates a specific user segment in the Zendesk system
213
+ #
214
+ # @author Jason Colyer
215
+ # @since 1.0.0
216
+ # @see
217
+ # https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#show-user-segment
218
+ # Zendesk API > User Segments > Show User Segment
219
+ # @see SupportOps::Zendesk::Configuration Setting up a client
220
+ # @example
221
+ # require 'support_ops_zendesk'
222
+ #
223
+ # SupportOps::Zendesk::Configuration.configure do |config|
224
+ # config.url = 'https://gitlab.zendesk.com/api/v2'
225
+ # config.username = 'jason@example.com'
226
+ # config.token = 'abc123'
227
+ # end
228
+ #
229
+ # segment = SupportOps::Zendesk::HelpCenterUserSegments.get!(123456)
230
+ # pp section.name
231
+ # # => "Publishers"
232
+ def self.get!(object)
233
+ if object.is_a? HelpCenterUserSegments
234
+ HelpCenterUserSegments.new(id: id).find!
235
+ else
236
+ HelpCenterUserSegments.new(id: object).find!
237
+ end
238
+ end
239
+
240
+ private
241
+
242
+ ##
243
+ # @private
244
+ def get_record
245
+ response = self.client.connection.get("help_center/user_segments/#{self.id}")
246
+ return nil if response.status != 200
247
+
248
+ Oj.load(response.body)['user_segment']
249
+ end
250
+
251
+ ##
252
+ # @private
253
+ def create_record
254
+ response = self.client.connection.post("help_center/user_segments", { user_segment: attributes_for_save }.to_json)
255
+ body = Oj.load(response.body)
256
+ raise "Failed to create user segment => #{body}" if response.status != 201
257
+ body['user_segment']
258
+ end
259
+
260
+ ##
261
+ # @private
262
+ def update_record
263
+ raise "Failed to update user segment => You didn't change anything in the object" if attributes_for_save.keys == [:id]
264
+ response = self.client.connection.put("help_center/user_segments/#{self.id}", { user_segment: attributes_for_save }.to_json)
265
+ body = Oj.load(response.body)
266
+ raise "Failed to update user segment #{self.id} => #{body}" if response.status != 200
267
+ body['user_segment']
268
+ end
269
+
270
+ ##
271
+ # @private
272
+ def delete_record
273
+ response = self.client.connection.delete("help_center/user_segments/#{self.id}")
274
+ raise "Failed to delete user segment #{self.id} => #{body}" if response.status != 204
275
+ true
276
+ end
277
+ end
278
+ end
279
+ end