gitlab_support_readiness 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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_readiness/client.rb +108 -0
  3. data/lib/support_readiness/gitlab/client.rb +64 -0
  4. data/lib/support_readiness/gitlab/configuration.rb +46 -0
  5. data/lib/support_readiness/gitlab/groups.rb +180 -0
  6. data/lib/support_readiness/gitlab/issues.rb +410 -0
  7. data/lib/support_readiness/gitlab/namespaces.rb +190 -0
  8. data/lib/support_readiness/gitlab/projects.rb +510 -0
  9. data/lib/support_readiness/gitlab/repositories.rb +267 -0
  10. data/lib/support_readiness/gitlab/users.rb +488 -0
  11. data/lib/support_readiness/gitlab.rb +19 -0
  12. data/lib/support_readiness/pagerduty/client.rb +66 -0
  13. data/lib/support_readiness/pagerduty/configuration.rb +43 -0
  14. data/lib/support_readiness/pagerduty/escalation_policies.rb +123 -0
  15. data/lib/support_readiness/pagerduty/schedules.rb +223 -0
  16. data/lib/support_readiness/pagerduty/services.rb +132 -0
  17. data/lib/support_readiness/pagerduty.rb +16 -0
  18. data/lib/support_readiness/redis.rb +90 -0
  19. data/lib/support_readiness/zendesk/articles.rb +210 -0
  20. data/lib/support_readiness/zendesk/automations.rb +304 -0
  21. data/lib/support_readiness/zendesk/client.rb +84 -0
  22. data/lib/support_readiness/zendesk/configuration.rb +49 -0
  23. data/lib/support_readiness/zendesk/group_memberships.rb +256 -0
  24. data/lib/support_readiness/zendesk/groups.rb +249 -0
  25. data/lib/support_readiness/zendesk/job_statuses.rb +188 -0
  26. data/lib/support_readiness/zendesk/macros.rb +267 -0
  27. data/lib/support_readiness/zendesk/organization_fields.rb +233 -0
  28. data/lib/support_readiness/zendesk/organization_memberships.rb +257 -0
  29. data/lib/support_readiness/zendesk/organizations.rb +515 -0
  30. data/lib/support_readiness/zendesk/roles.rb +194 -0
  31. data/lib/support_readiness/zendesk/search.rb +159 -0
  32. data/lib/support_readiness/zendesk/sla_policies.rb +232 -0
  33. data/lib/support_readiness/zendesk/ticket_fields.rb +222 -0
  34. data/lib/support_readiness/zendesk/ticket_forms.rb +290 -0
  35. data/lib/support_readiness/zendesk/tickets.rb +854 -0
  36. data/lib/support_readiness/zendesk/triggers.rb +269 -0
  37. data/lib/support_readiness/zendesk/users.rb +946 -0
  38. data/lib/support_readiness/zendesk/views.rb +469 -0
  39. data/lib/support_readiness/zendesk.rb +31 -0
  40. data/lib/support_readiness.rb +29 -0
  41. metadata +215 -0
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Articles within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Articles < Readiness::Client
13
+ attr_accessor :author_id, :body, :comments_disabled, :draft, :id, :label_names, :locale, :name, :permission_group_id, :position, :promoted, :section_id, :title, :user_segment_id
14
+
15
+ ##
16
+ # Creates a new {Readiness::Zendesk::Articles} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @param object [Object] An instance of {Readiness::Zendesk::Articles}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # Readiness::Zendesk::Articles.new
24
+ def initialize(object = {})
25
+ @author_id = object['author_id']
26
+ @body = object['body']
27
+ @comments_disabled = object['comments_disabled']
28
+ @draft = object['draft']
29
+ @id = object['id']
30
+ @label_names = object['label_names']
31
+ @locale = object['locale']
32
+ @name = object['name']
33
+ @permission_group_id = object['permission_group_id']
34
+ @position = object['position']
35
+ @promoted = object['promoted']
36
+ @section_id = object['section_id']
37
+ @title = object['title']
38
+ @user_segment_id = object['user_segment_id']
39
+ end
40
+
41
+ ##
42
+ # Lists articles
43
+ #
44
+ # @author Jason Colyer
45
+ # @since 1.0.0
46
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
47
+ # @return [Array]
48
+ # @see https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#list-articles Zendesk API > Articles > List Articles
49
+ # @example
50
+ # require 'support_readiness'
51
+ # config = Readiness::Zendesk::Configuration.new
52
+ # config.username = 'alice@example.com'
53
+ # config.token = 'test123abc'
54
+ # config.url = 'https://example.zendesk.com/api/v2'
55
+ # client = Readiness::Zendesk::Client.new(config)
56
+ # articles = Readiness::Zendesk::Articles.list(client)
57
+ # pp articles.first.id
58
+ # # => 35467
59
+ def self.list(client)
60
+ array = []
61
+ opts = "page[size]=100"
62
+ loop do
63
+ response = client.connection.get("help_center/articles?#{opts}")
64
+ handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
65
+ body = Oj.load(response.body)
66
+ array += body['articles'].map { |a| Articles.new(a) }
67
+ break unless body['meta']['has_more']
68
+
69
+ opts = body['links'] ['next'].split('?').last
70
+ end
71
+ array
72
+ end
73
+
74
+ ##
75
+ # Locates an article within Zendesk. This will not exit on error (except Authentication errors)
76
+ #
77
+ # @author Jason Colyer
78
+ # @since 1.0.0
79
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
80
+ # @param aid [Integer] The article ID to find
81
+ # @return [Hash]
82
+ # @see https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#show-article Zendesk API > Articles > Show Article
83
+ # @example
84
+ # require 'support_readiness'
85
+ # config = Readiness::Zendesk::Configuration.new
86
+ # config.username = 'alice@example.com'
87
+ # config.token = 'test123abc'
88
+ # config.url = 'https://example.zendesk.com/api/v2'
89
+ # client = Readiness::Zendesk::Client.new(config)
90
+ # article = Readiness::Zendesk::Articles.find(client, 35467)
91
+ # pp article.title
92
+ # # => "Article title"
93
+ def self.find(client, aid)
94
+ response = client.connection.get("help_center/articles/#{aid}")
95
+ handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: aid }) unless response.status == 200
96
+ return Articles.new(Oj.load(response.body)['article']) if response.status == 200
97
+
98
+ Oj.load(response.body)
99
+ end
100
+
101
+ ##
102
+ # Locates an article within Zendesk. This will exit on error
103
+ #
104
+ # @author Jason Colyer
105
+ # @since 1.0.0
106
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
107
+ # @param aid [Integer] The article ID to find
108
+ # @return [Object] An instance of {Readiness::Zendesk::Articles}
109
+ # @see https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#show-article Zendesk API > Articles > Show Article
110
+ # @example
111
+ # require 'support_readiness'
112
+ # config = Readiness::Zendesk::Configuration.new
113
+ # config.username = 'alice@example.com'
114
+ # config.token = 'test123abc'
115
+ # config.url = 'https://example.zendesk.com/api/v2'
116
+ # client = Readiness::Zendesk::Client.new(config)
117
+ # article = Readiness::Zendesk::Articles.find!(client, 35467)
118
+ # pp article.title
119
+ # # => "Article title"
120
+ def self.find!(client, aid)
121
+ response = client.connection.get("help_center/articles/#{aid}")
122
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Find article', id: aid }) unless response.status == 200
123
+ Articles.new(Oj.load(response.body)['article'])
124
+ end
125
+
126
+ ##
127
+ # Creates an article. Will exit if unsuccessful
128
+ #
129
+ # @author Jason Colyer
130
+ # @since 1.0.0
131
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
132
+ # @param article [Object] An instance of {Readiness::Zendesk::Articles}
133
+ # @return [Object] An instance of {Readiness::Zendesk::Articles}
134
+ # @see https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#create-article Zendesk API > Articles > Create Article
135
+ # @example
136
+ # require 'support_readiness'
137
+ # config = Readiness::Zendesk::Configuration.new
138
+ # config.username = 'alice@example.com'
139
+ # config.token = 'test123abc'
140
+ # config.url = 'https://example.zendesk.com/api/v2'
141
+ # client = Readiness::Zendesk::Client.new(config)
142
+ # article = Readiness::Zendesk::Articles.new
143
+ # article.title = 'Taking photos in low light'
144
+ # artricle.body = 'Use a tripod'
145
+ # article.section_id = 123
146
+ # article.locale = 'en-us'
147
+ # create = Readiness::Zendesk::Articles.create!(client, article)
148
+ # pp create.id
149
+ # # => 35468
150
+ def self.create!(client, article)
151
+ response = client.connection.post "help_center/sections/#{article.section_id}/articles", to_clean_json_with_key(article, 'article')
152
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Create article', message: Oj.load(response.body)}) unless response.status == 201
153
+ Articles.new(Oj.load(response.body)['article'])
154
+ end
155
+
156
+ ##
157
+ # Updates an article. Will exit if unsuccessful
158
+ #
159
+ # @author Jason Colyer
160
+ # @since 1.0.0
161
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
162
+ # @param article [Object] An instance of {Readiness::Zendesk::Articles}
163
+ # @return [Object] An instance of {Readiness::Zendesk::Articles}
164
+ # @see https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#update-article Zendesk API > Articles > Update Article
165
+ # @example
166
+ # require 'support_readiness'
167
+ # config = Readiness::Zendesk::Configuration.new
168
+ # config.username = 'alice@example.com'
169
+ # config.token = 'test123abc'
170
+ # config.url = 'https://example.zendesk.com/api/v2'
171
+ # client = Readiness::Zendesk::Client.new(config)
172
+ # article = Readiness::Zendesk::Articles.find!(client, 35468)
173
+ # artricle.body = 'Use a tripod and low light approved camera'
174
+ # update = Readiness::Zendesk::Articles.update!(client, article)
175
+ # pp update.body
176
+ # # => "Use a tripod and low light approved camera"
177
+ def self.update!(client, article)
178
+ response = client.connection.put "help_center/sections/#{article.section_id}/articles", to_clean_json_with_key(article, 'article')
179
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Update article', id: article.id, message: Oj.load(response.body)}) unless response.status == 200
180
+ Articles.new(Oj.load(response.body)['article'])
181
+ end
182
+
183
+ ##
184
+ # Archives an article. Will exit if unsuccessful
185
+ #
186
+ # @author Jason Colyer
187
+ # @since 1.0.0
188
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
189
+ # @param article [Object] An instance of {Readiness::Zendesk::Articles}
190
+ # @return [Boolean]
191
+ # @see https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#archive-article Zendesk API > Articles > Archive Article
192
+ # @example
193
+ # require 'support_readiness'
194
+ # config = Readiness::Zendesk::Configuration.new
195
+ # config.username = 'alice@example.com'
196
+ # config.token = 'test123abc'
197
+ # config.url = 'https://example.zendesk.com/api/v2'
198
+ # client = Readiness::Zendesk::Client.new(config)
199
+ # article = Readiness::Zendesk::Articles.find!(client, 35468)
200
+ # archive = Readiness::Zendesk::Articles.archive!(client, article)
201
+ # pp archive
202
+ # # => true
203
+ def self.archive!(client, article)
204
+ response = client.connection.delete "help_center/articles/#{article_id}"
205
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Archive article', id: article.id, message: Oj.load(response.body)}) unless response.status == 204
206
+ true
207
+ end
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,304 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Automations within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Automations < Readiness::Client
13
+ attr_accessor :actions, :active, :conditions, :default, :id, :position, :title
14
+
15
+ ##
16
+ # Creates a new {Readiness::Zendesk::Automations} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @param object [Object] An instance of {Readiness::Zendesk::Automations}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # Readiness::Zendesk::Automations.new
24
+ def initialize(object = {})
25
+ @actions = object['actions']
26
+ @active = object['active']
27
+ @conditions = object['conditions']
28
+ @default = object['default']
29
+ @id = object['id']
30
+ @position = object['position']
31
+ @title = object['title']
32
+ end
33
+
34
+ ##
35
+ # Lists automations.
36
+ #
37
+ # @author Jason Colyer
38
+ # @since 1.0.0
39
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
40
+ # @return [Array]
41
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#list-automations Zendesk API > Automations > List Automations
42
+ # @example
43
+ # require 'support_readiness'
44
+ # config = Readiness::Zendesk::Configuration.new
45
+ # config.username = 'alice@example.com'
46
+ # config.token = 'test123abc'
47
+ # config.url = 'https://example.zendesk.com/api/v2'
48
+ # client = Readiness::Zendesk::Client.new(config)
49
+ # automations = Readiness::Zendesk::Automations.list(client)
50
+ # pp automations.first.id
51
+ # # => 25
52
+ def self.list(client)
53
+ array = []
54
+ opts = "page[size]=100"
55
+ loop do
56
+ response = client.connection.get("automations?#{opts}")
57
+ handle_request_error(0, 'Zendesk', response.status) unless response.status == 200
58
+ body = Oj.load(response.body)
59
+ array += body['automations'].map { |a| Automations.new(a) }
60
+ break unless body['meta']['has_more']
61
+
62
+ opts = body['links'] ['next'].split('?').last
63
+ end
64
+ array
65
+ end
66
+
67
+ ##
68
+ # Locates an automation within Zendesk. This will not exit on error (except Authentication errors)
69
+ #
70
+ # @author Jason Colyer
71
+ # @since 1.0.0
72
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
73
+ # @param aid [Integer] The automation ID to find
74
+ # @return [Hash]
75
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#show-automation Zendesk API > Automations > Show Automation
76
+ # @example
77
+ # require 'support_readiness'
78
+ # config = Readiness::Zendesk::Configuration.new
79
+ # config.username = 'alice@example.com'
80
+ # config.token = 'test123abc'
81
+ # config.url = 'https://example.zendesk.com/api/v2'
82
+ # client = Readiness::Zendesk::Client.new(config)
83
+ # automation = Readiness::Zendesk::Automations.find(client, 25)
84
+ # pp automation.title
85
+ # # => "Close and Save"
86
+ def self.find(client, aid)
87
+ response = client.connection.get("automations/#{aid}")
88
+ handle_request_error(0, 'Zendesk', response.status, { action: 'get', id: aid }) unless response.status == 200
89
+ return Automations.new(Oj.load(response.body)['automation']) if response.status == 200
90
+
91
+ Oj.load(response.body)
92
+ end
93
+
94
+ ##
95
+ # Locates an automation within Zendesk. This will exit on error
96
+ #
97
+ # @author Jason Colyer
98
+ # @since 1.0.0
99
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
100
+ # @param aid [Integer] The automation ID to find
101
+ # @return [Object] An instance of {Readiness::Zendesk::Automations}
102
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#show-automation Zendesk API > Automations > Show Automation
103
+ # @example
104
+ # require 'support_readiness'
105
+ # config = Readiness::Zendesk::Configuration.new
106
+ # config.username = 'alice@example.com'
107
+ # config.token = 'test123abc'
108
+ # config.url = 'https://example.zendesk.com/api/v2'
109
+ # client = Readiness::Zendesk::Client.new(config)
110
+ # automation = Readiness::Zendesk::Automations.find!(client, 25)
111
+ # pp automation.title
112
+ # # => "Close and Save"
113
+ def self.find!(client, aid)
114
+ response = client.connection.get("automations/#{aid}")
115
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Find automation', id: aid }) unless response.status == 200
116
+ Automations.new(Oj.load(response.body)['automation'])
117
+ end
118
+
119
+ ##
120
+ # Creates an automation. Will exit if unsuccessful
121
+ #
122
+ # @author Jason Colyer
123
+ # @since 1.0.0
124
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
125
+ # @param automation [Object] An instance of {Readiness::Zendesk::Automations}
126
+ # @return [Object] An instance of {Readiness::Zendesk::Automations}
127
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#create-automation Zendesk API > Automations > Create Automation
128
+ # @example
129
+ # require 'support_readiness'
130
+ # config = Readiness::Zendesk::Configuration.new
131
+ # config.username = 'alice@example.com'
132
+ # config.token = 'test123abc'
133
+ # config.url = 'https://example.zendesk.com/api/v2'
134
+ # client = Readiness::Zendesk::Client.new(config)
135
+ # automation = Readiness::Zendesk::Automations.new
136
+ # automation.title = 'Change priority to low for solved tickets'
137
+ # automation.conditions = {
138
+ # all: [
139
+ # {
140
+ # field: 'status'
141
+ # operator: 'is'
142
+ # value: 'solved'
143
+ # },
144
+ # {
145
+ # field: 'priority'
146
+ # operator: 'is_not'
147
+ # value: 'low'
148
+ # }
149
+ # ]
150
+ # any: []
151
+ # }
152
+ # automation.actions = [
153
+ # {
154
+ # field: 'priority'
155
+ # value: 'low'
156
+ # }
157
+ # ]
158
+ # created = Readiness::Zendesk::Automations.create!(client, automation)
159
+ # pp created.id
160
+ # # => 26
161
+ def self.create!(client, automation)
162
+ response = client.connection.post 'automations', to_clean_json_with_key(automation, 'automation')
163
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Create automation', message: Oj.load(response.body)}) unless response.status == 201
164
+ Automations.new(Oj.load(response.body)['automation'])
165
+ end
166
+
167
+ ##
168
+ # Updates an automation. Will exit if unsuccessful
169
+ #
170
+ # @author Jason Colyer
171
+ # @since 1.0.0
172
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
173
+ # @param automation [Object] An instance of {Readiness::Zendesk::Automations}
174
+ # @return [Object] An instance of {Readiness::Zendesk::Automations}
175
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#update-automation Zendesk API > Automations > Update Automation
176
+ # @example
177
+ # require 'support_readiness'
178
+ # config = Readiness::Zendesk::Configuration.new
179
+ # config.username = 'alice@example.com'
180
+ # config.token = 'test123abc'
181
+ # config.url = 'https://example.zendesk.com/api/v2'
182
+ # client = Readiness::Zendesk::Client.new(config)
183
+ # automation = Readiness::Zendesk::Automations.find!(client, 26)
184
+ # automation.title = 'Change priority to medium for solved tickets'
185
+ # automation.conditions = {
186
+ # all: [
187
+ # {
188
+ # field: 'status'
189
+ # operator: 'is'
190
+ # value: 'solved'
191
+ # },
192
+ # {
193
+ # field: 'priority'
194
+ # operator: 'is_not'
195
+ # value: 'medium'
196
+ # }
197
+ # ]
198
+ # any: []
199
+ # }
200
+ # automation.actions = [
201
+ # {
202
+ # field: 'priority'
203
+ # value: 'medium'
204
+ # }
205
+ # ]
206
+ # updated = Readiness::Zendesk::Automations.update!(client, automation)
207
+ # pp updated.title
208
+ # # => "Change priority to medium for solved tickets"
209
+ def self.update!(client, automation)
210
+ response = client.connection.put "automations/#{automation.id}", to_clean_json_with_key(automation, 'automation')
211
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Update automation', id: automation.id, message: Oj.load(response.body)}) unless response.status == 200
212
+ Automations.new(Oj.load(response.body)['automation'])
213
+ end
214
+
215
+ ##
216
+ # Updates multiple automations via a batch job
217
+ #
218
+ # @author Jason Colyer
219
+ # @since 1.0.0
220
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
221
+ # @param automations [Array] An array of {Readiness::Zendesk::Automations} instances
222
+ # @return [Array]
223
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#update-many-automations Zendesk API > Automations > Update Many Automations
224
+ # @example
225
+ # require 'support_readiness'
226
+ # config = Readiness::Zendesk::Configuration.new
227
+ # config.username = 'alice@example.com'
228
+ # config.token = 'test123abc'
229
+ # config.url = 'https://example.zendesk.com/api/v2'
230
+ # client = Readiness::Zendesk::Client.new(config)
231
+ # automation1 = Readiness::Zendesk::Automations.find!(client, 1)
232
+ # automation2 = Readiness::Zendesk::Automations.find!(client, 2)
233
+ # automation3 = Readiness::Zendesk::Automations.find!(client, 3)
234
+ # automation1.position = 2
235
+ # automation2.position = 3
236
+ # automation3.position = 1
237
+ # automations = [automation1, automation2, automation3]
238
+ # updated = Readiness::Zendesk::Automations.update_many!(client, automation)
239
+ # pp updated.first.position
240
+ # # => 2
241
+ def self.update_many(client, automations)
242
+ data = { automations: automations.map { |t| to_hash(t).compact } }.to_json
243
+ response = client.connection.put('automations/update_many', data)
244
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Update many automations', message: Oj.load(response.body)}) unless response.status == 200
245
+ Oj.load(response.body).map { |a| Automations.new(a) }
246
+ end
247
+
248
+ ##
249
+ # Deletes an automation. Will exit if unsuccessful
250
+ #
251
+ # @author Jason Colyer
252
+ # @since 1.0.0
253
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
254
+ # @param automation [Object] An instance of {Readiness::Zendesk::Automations}
255
+ # @return [Boolean]
256
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#delete-automation Zendesk API > Automations > Delete Automation
257
+ # @example
258
+ # require 'support_readiness'
259
+ # config = Readiness::Zendesk::Configuration.new
260
+ # config.username = 'alice@example.com'
261
+ # config.token = 'test123abc'
262
+ # config.url = 'https://example.zendesk.com/api/v2'
263
+ # client = Readiness::Zendesk::Client.new(config)
264
+ # automation = Readiness::Zendesk::Automations.find!(client, 26)
265
+ # deleted = Readiness::Zendesk::Automations.delete!(client, automation)
266
+ # pp deleted
267
+ # # => true
268
+ def self.delete!(client, automation)
269
+ response = client.connection.delete "automations/#{automation.id}"
270
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Delete an automation', id: automation.id, message: Oj.load(response.body)}) unless response.status == 204
271
+ true
272
+ end
273
+
274
+ ##
275
+ # Deletes multiple automations via a batch job
276
+ #
277
+ # @author Jason Colyer
278
+ # @since 1.0.0
279
+ # @param client [Object] An instance of {Readiness::Zendesk::Client}
280
+ # @param aids [Array] An array of automation IDs
281
+ # @return [Boolean]
282
+ # @see https://developer.zendesk.com/api-reference/ticketing/business-rules/automations/#bulk-delete-automations Zendesk API > Automations > Bulk Delete Automations
283
+ # @example
284
+ # require 'support_readiness'
285
+ # config = Readiness::Zendesk::Configuration.new
286
+ # config.username = 'alice@example.com'
287
+ # config.token = 'test123abc'
288
+ # config.url = 'https://example.zendesk.com/api/v2'
289
+ # client = Readiness::Zendesk::Client.new(config)
290
+ # automation1 = Readiness::Zendesk::Automations.find!(client, 1)
291
+ # automation2 = Readiness::Zendesk::Automations.find!(client, 2)
292
+ # automation3 = Readiness::Zendesk::Automations.find!(client, 3)
293
+ # automations = [automation1, automation2, automation3]
294
+ # deleted = Readiness::Zendesk::Automations.delete_many!(client, automation)
295
+ # pp deleted
296
+ # # => true
297
+ def self.delete_many!(client, aids)
298
+ response = client.connection.delete("automations/destroy_many?ids=#{aids.join(',')}")
299
+ handle_request_error(1, 'Zendesk', response.status, { action: 'Delete many automations', message: Oj.load(response.body)}) unless response.status == 204
300
+ true
301
+ end
302
+ end
303
+ end
304
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Client within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Client
13
+ attr_reader :connection, :upload_connection
14
+
15
+ ##
16
+ # Creates a new {Readiness::Zendesk::Client} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @param config [Object] An instance of {Readiness::Zendesk::Configuration}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # config = Readiness::Zendesk::Configuration.new
24
+ # config.username = 'alice@example.com'
25
+ # config.token = 'test123abc'
26
+ # config.url = 'https://example.zendesk.com/api/v2'
27
+ # client = Readiness::Zendesk::Client.new(config)
28
+ def initialize(config = Readiness::Zendesk::Configuration.new)
29
+ @connection = generate_connection(config)
30
+ @upload_connection = generate_upload_connection(config)
31
+ end
32
+
33
+ ##
34
+ # Used to generate the retry options passed to Faraday via faraday-retry
35
+ #
36
+ # @author Jason Colyer
37
+ # @since 1.0.0
38
+ # @param config [Object] An instance of {Readiness::Zendesk::Configuration}
39
+ # @return [Hash]
40
+ def retry_options(config)
41
+ {
42
+ max: config.retry_max,
43
+ interval: config.retry_interval,
44
+ interval_randomness: config.retry_randomness,
45
+ backoff_factor: config.retry_backoff,
46
+ exceptions: config.retry_exceptions
47
+ }
48
+ end
49
+
50
+ ##
51
+ # Used to generate a Faraday connection
52
+ #
53
+ # @author Jason Colyer
54
+ # @since 1.0.0
55
+ # @param config [Object] An instance of {Readiness::Zendesk::Configuration}
56
+ # @return [Object]
57
+ def generate_connection(config)
58
+ Faraday.new(config.url) do |c|
59
+ c.request :retry, retry_options(config)
60
+ c.adapter Faraday.default_adapter
61
+ c.headers['Content-Type'] = 'application/json'
62
+ c.headers['Authorization'] = "Basic " + Base64.encode64("#{config.username}/token:#{config.token}").gsub("\n", '')
63
+ end
64
+ end
65
+
66
+ ##
67
+ # Used to generate a Faraday connection for uploads
68
+ #
69
+ # @author Jason Colyer
70
+ # @since 1.0.0
71
+ # @param config [Object] An instance of {Readiness::Zendesk::Configuration}
72
+ # @return [Object]
73
+ def generate_upload_connection(config)
74
+ Faraday.new(config.url) do |c|
75
+ c.request :retry, retry_options(config)
76
+ c.request :multipart
77
+ c.request :url_encoded
78
+ c.adapter Faraday.default_adapter
79
+ c.headers['Authorization'] = "Basic " + Base64.encode64("#{config.username}/token:#{config.token}").gsub("\n", '')
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Zendesk
6
+ module Zendesk
7
+ ##
8
+ # Defines the class Configuration within the module {Readiness::Zendesk}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Configuration
13
+ attr_accessor :url, :username, :token, :retry_options, :retry_max, :retry_interval, :retry_randomness, :retry_backoff, :retry_exceptions
14
+
15
+ ##
16
+ # Creates a new {Readiness::Zendesk::Configuration} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @example
21
+ # require 'support_readiness'
22
+ # config = Readiness::Zendesk::Configuration.new
23
+ # config.username = 'alice@example.com'
24
+ # config.token = 'test123abc'
25
+ # config.url = 'https://example.zendesk.com/api/v2'
26
+ # pp config
27
+ # # => #<Readiness::Zendesk::Configuration:0x00007f352fdd1420
28
+ # @retry_backoff=2,
29
+ # @retry_exceptions=
30
+ # [Errno::ETIMEDOUT, "Timeout::Error", Faraday::TimeoutError, Faraday::RetriableResponse, Faraday::ConnectionFailed],
31
+ # @retry_interval=1,
32
+ # @retry_max=5,
33
+ # @retry_randomness=0.5,
34
+ # @token="test123abc",
35
+ # @url="https://example.zendesk.com/api/v2",
36
+ # @username="alice@example.com">
37
+ def initialize
38
+ @url = ''
39
+ @username = ''
40
+ @token = ''
41
+ @retry_max = 5
42
+ @retry_interval = 1
43
+ @retry_randomness = 0.5
44
+ @retry_backoff = 2
45
+ @retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed]
46
+ end
47
+ end
48
+ end
49
+ end