gitlab_support_readiness 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/support_readiness/calendly/client.rb +64 -0
- data/lib/support_readiness/calendly/configuration.rb +45 -0
- data/lib/support_readiness/calendly/organization_memberships.rb +67 -0
- data/lib/support_readiness/calendly/organizations.rb +123 -0
- data/lib/support_readiness/calendly/users.rb +105 -0
- data/lib/support_readiness/calendly.rb +16 -0
- data/lib/support_readiness/client.rb +88 -1
- data/lib/support_readiness/dates.rb +90 -0
- data/lib/support_readiness/gitlab/configuration.rb +0 -1
- data/lib/support_readiness/gitlab/groups.rb +35 -0
- data/lib/support_readiness/gitlab/markdown.rb +37 -0
- data/lib/support_readiness/gitlab/merge_requests.rb +127 -0
- data/lib/support_readiness/gitlab/namespaces.rb +22 -0
- data/lib/support_readiness/gitlab/projects.rb +36 -1
- data/lib/support_readiness/gitlab/repositories.rb +174 -0
- data/lib/support_readiness/gitlab/users.rb +24 -0
- data/lib/support_readiness/gitlab.rb +2 -0
- data/lib/support_readiness/google_calendar/client.rb +59 -0
- data/lib/support_readiness/google_calendar/configuration.rb +39 -0
- data/lib/support_readiness/google_calendar/events.rb +169 -0
- data/lib/support_readiness/google_calendar.rb +14 -0
- data/lib/support_readiness/mailgun/bounces.rb +103 -0
- data/lib/support_readiness/mailgun/client.rb +65 -0
- data/lib/support_readiness/mailgun/configuration.rb +46 -0
- data/lib/support_readiness/mailgun/emails.rb +95 -0
- data/lib/support_readiness/mailgun.rb +15 -0
- data/lib/support_readiness/pagerduty/escalation_policies.rb +1 -1
- data/lib/support_readiness/pagerduty/schedules.rb +27 -3
- data/lib/support_readiness/pagerduty/services.rb +1 -1
- data/lib/support_readiness/pagerduty/users.rb +197 -0
- data/lib/support_readiness/pagerduty.rb +1 -0
- data/lib/support_readiness/repos/articles.rb +335 -0
- data/lib/support_readiness/repos/automations.rb +247 -0
- data/lib/support_readiness/repos/groups.rb +188 -0
- data/lib/support_readiness/repos/macros.rb +224 -0
- data/lib/support_readiness/repos/organization_fields.rb +193 -0
- data/lib/support_readiness/repos/sla_policies.rb +192 -0
- data/lib/support_readiness/repos/ticket_fields.rb +200 -0
- data/lib/support_readiness/repos/ticket_forms.rb +200 -0
- data/lib/support_readiness/repos/triggers.rb +255 -0
- data/lib/support_readiness/repos/user_fields.rb +201 -0
- data/lib/support_readiness/repos/views.rb +362 -0
- data/lib/support_readiness/repos.rb +22 -0
- data/lib/support_readiness/salesforce/accounts.rb +109 -0
- data/lib/support_readiness/salesforce/cases.rb +109 -0
- data/lib/support_readiness/salesforce/client.rb +64 -0
- data/lib/support_readiness/salesforce/configuration.rb +49 -0
- data/lib/support_readiness/salesforce/queries.rb +62 -0
- data/lib/support_readiness/salesforce.rb +16 -0
- data/lib/support_readiness/slack/client.rb +63 -0
- data/lib/support_readiness/slack/configuration.rb +43 -0
- data/lib/support_readiness/slack/messages.rb +37 -0
- data/lib/support_readiness/slack.rb +14 -0
- data/lib/support_readiness/zendesk/app_job_statuses.rb +140 -0
- data/lib/support_readiness/zendesk/apps.rb +209 -0
- data/lib/support_readiness/zendesk/automations.rb +1 -2
- data/lib/support_readiness/zendesk/macros.rb +1 -3
- data/lib/support_readiness/zendesk/organization_fields.rb +1 -1
- data/lib/support_readiness/zendesk/theme_job_statuses.rb +136 -0
- data/lib/support_readiness/zendesk/themes.rb +303 -0
- data/lib/support_readiness/zendesk/ticket_field_options.rb +110 -0
- data/lib/support_readiness/zendesk/ticket_fields.rb +85 -16
- data/lib/support_readiness/zendesk/ticket_forms.rb +65 -2
- data/lib/support_readiness/zendesk/tickets.rb +77 -0
- data/lib/support_readiness/zendesk/triggers.rb +1 -2
- data/lib/support_readiness/zendesk/user_field_options.rb +110 -0
- data/lib/support_readiness/zendesk/user_fields.rb +257 -0
- data/lib/support_readiness/zendesk/views.rb +49 -2
- data/lib/support_readiness/zendesk.rb +7 -0
- data/lib/support_readiness.rb +16 -0
- metadata +120 -2
@@ -0,0 +1,362 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Repos
|
6
|
+
module Repos
|
7
|
+
##
|
8
|
+
# Defines the class Views within the module {Readiness::Repos}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class Views < Readiness::Client
|
13
|
+
##
|
14
|
+
# Compares the repo view files to the Zendesk instance Views
|
15
|
+
#
|
16
|
+
# @author Jason Colyer
|
17
|
+
# @since 1.0.12
|
18
|
+
# @param config [Object] An instance of {Readiness::Zendesk::Configuration}
|
19
|
+
# @param zendesk_client [Object] An instance of {Readiness::Zendesk::Client}
|
20
|
+
# @param location [String] The location (relative or absolute) of the repo's data folder
|
21
|
+
# @param verbose [Boolean] Whether you want a detailed report or not
|
22
|
+
# @return [Hash]
|
23
|
+
# @example
|
24
|
+
# require 'support_readiness'
|
25
|
+
# config = Readiness::Zendesk::Configuration.new
|
26
|
+
# config.username = 'alice@example.com'
|
27
|
+
# config.token = 'test123abc'
|
28
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
29
|
+
# client = Readiness::Zendesk::Client.new(config)
|
30
|
+
# diffs = Readiness::Repos::Views.compare(config, client, 'views/data', false)
|
31
|
+
# pp diffs[:updates.count]
|
32
|
+
# # => 5
|
33
|
+
# @example
|
34
|
+
# require 'support_readiness'
|
35
|
+
# config = Readiness::Zendesk::Configuration.new
|
36
|
+
# config.username = 'alice@example.com'
|
37
|
+
# config.token = 'test123abc'
|
38
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
39
|
+
# client = Readiness::Zendesk::Client.new(config)
|
40
|
+
# diffs = Readiness::Repos::Views.compare(config, client, 'views/data', true)
|
41
|
+
# # => Detailed diff of Status::Close::Close solved tickets after 7 days
|
42
|
+
# # => - @default Repo:
|
43
|
+
# # => false
|
44
|
+
# # => @default Zendesk:
|
45
|
+
# # => true
|
46
|
+
# # => Compare report:
|
47
|
+
# # => - Creates: 0
|
48
|
+
# # => - Updates: 1
|
49
|
+
# pp diffs[:updates.count]
|
50
|
+
# # => 1
|
51
|
+
def self.compare(config, zendesk_client, location = 'data', verbose = false)
|
52
|
+
diffs = {
|
53
|
+
updates: [],
|
54
|
+
creates: []
|
55
|
+
}
|
56
|
+
from_repo = gather(config, location)
|
57
|
+
from_zendesk = Zendesk::Views.list(zendesk_client)
|
58
|
+
from_repo.each do |repo|
|
59
|
+
zd = from_zendesk.detect { |z| z.title == repo.title }
|
60
|
+
if zd.nil?
|
61
|
+
diffs[:creates].push(repo)
|
62
|
+
else
|
63
|
+
comparable = zd.dup
|
64
|
+
comparable.id = nil
|
65
|
+
diffs[:updates].push(update_object(repo, zd)) if to_clean_json(repo) != to_clean_json(comparable)
|
66
|
+
detailed_diff(repo, comparable) if verbose && to_clean_json(repo) != to_clean_json(comparable)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
report_diffs(diffs) if verbose
|
70
|
+
diffs
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Outputs a comparison report
|
75
|
+
#
|
76
|
+
# @author Jason Colyer
|
77
|
+
# @since 1.0.12
|
78
|
+
# @param diffs [Hash] The returned value of {compare}
|
79
|
+
def self.report_diffs(diffs)
|
80
|
+
puts 'Compare report:'
|
81
|
+
puts "- Creates: #{diffs[:creates].count}"
|
82
|
+
puts "- Updates: #{diffs[:updates].count}"
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Outputs a comparison report
|
87
|
+
#
|
88
|
+
# @author Jason Colyer
|
89
|
+
# @since 1.0.12
|
90
|
+
# @param repo [Object] An instance of {Readiness::Zendesk::Views}
|
91
|
+
# @param zendesk [Object] An instance of {Readiness::Zendesk::Views}
|
92
|
+
def self.detailed_diff(repo, zendesk)
|
93
|
+
puts "Detailed diff of #{repo.title}"
|
94
|
+
repo.instance_variables.each do |v|
|
95
|
+
next if v == :@id
|
96
|
+
|
97
|
+
if repo.instance_variable_get(v) != zendesk.instance_variable_get(v)
|
98
|
+
puts "- #{v} Repo:"
|
99
|
+
pp repo.instance_variable_get(v)
|
100
|
+
puts " #{v} Zendesk:"
|
101
|
+
pp zendesk.instance_variable_get(v)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Creates an instance of {Readiness::Zendesk::Views} to use for updates
|
108
|
+
#
|
109
|
+
# @author Jason Colyer
|
110
|
+
# @since 1.0.12
|
111
|
+
# @param repo [Object] An instance of {Readiness::Zendesk::Views}
|
112
|
+
# @param zendesk [Object] An instance of {Readiness::Zendesk::Views}
|
113
|
+
# @return [Object]
|
114
|
+
def self.update_object(repo, zendesk)
|
115
|
+
object = repo
|
116
|
+
object.id = zendesk.id
|
117
|
+
object
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Parses repo view files
|
122
|
+
#
|
123
|
+
# @author Jason Colyer
|
124
|
+
# @since 1.0.12
|
125
|
+
# @param config [Object] An instance of {Readiness::Zendesk::Configuration}
|
126
|
+
# @param location [String] The location (relative or absolute) of the repo's data folder
|
127
|
+
# @return [Array]
|
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
|
+
# repo = Readiness::Repos::Views.gather(config, 'views/data')
|
135
|
+
# pp repo.count
|
136
|
+
# # => 35
|
137
|
+
def self.gather(config, location = 'data')
|
138
|
+
@errors = []
|
139
|
+
@location = location
|
140
|
+
array = []
|
141
|
+
Dir["#{@location}/{active,inactive}/*.yaml"].each do |f|
|
142
|
+
object = YAML.safe_load_file(f)
|
143
|
+
object = convert_managed_content(config, object)
|
144
|
+
validity_check(f, object)
|
145
|
+
object['id'] = nil
|
146
|
+
array.push(Zendesk::Views.new(object))
|
147
|
+
end
|
148
|
+
repo_check(array)
|
149
|
+
report_errors unless @errors.count.zero?
|
150
|
+
array
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Outputs an error report and exits with a status code of 1
|
155
|
+
#
|
156
|
+
# @author Jason Colyer
|
157
|
+
# @since 1.0.12
|
158
|
+
def self.report_errors
|
159
|
+
puts 'The following errors were found in the repo files:'
|
160
|
+
@errors.each do |e|
|
161
|
+
puts "- #{e}"
|
162
|
+
end
|
163
|
+
puts 'Rectify the errors and retry. We cannot proceed with those errors occurring.'
|
164
|
+
exit 1
|
165
|
+
end
|
166
|
+
|
167
|
+
##
|
168
|
+
# Performs basic checks on a repo file
|
169
|
+
#
|
170
|
+
# @author Jason Colyer
|
171
|
+
# @since 1.0.12
|
172
|
+
# @param file [String] The path to the repo file
|
173
|
+
# @param object [Hash] The Hash derived from parsing a YAML file
|
174
|
+
def self.validity_check(file, object)
|
175
|
+
folder = file.split("#{@location}/").last.split('/').first
|
176
|
+
@errors.push("Missing position: #{file}") if object['position'].nil?
|
177
|
+
@errors.push("Missing title: #{file}") if object['title'].nil?
|
178
|
+
@errors.push("Inactive view in active folder: #{file}") if folder == 'active' && !object['active']
|
179
|
+
@errors.push("Active view in inactive folder: #{file}") if folder == 'inactive' && object['active']
|
180
|
+
end
|
181
|
+
|
182
|
+
##
|
183
|
+
# Performs basic checks on the repo
|
184
|
+
#
|
185
|
+
# @author Jason Colyer
|
186
|
+
# @since 1.0.12
|
187
|
+
# @param objects [Array] The Array of Hashes derived from parsing the repo files
|
188
|
+
def self.repo_check(objects)
|
189
|
+
duplicate_names = objects.group_by { |o| o.title }.select { |k, v| v.size > 1 }.map(&:first)
|
190
|
+
unless duplicate_names.count.zero?
|
191
|
+
duplicate_names.each do |d|
|
192
|
+
@errors.push("The title '#{d}' is used in multiple files")
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
##
|
198
|
+
# Performs conversions for a repo file if using managed content
|
199
|
+
#
|
200
|
+
# @author Jason Colyer
|
201
|
+
# @since 1.0.12
|
202
|
+
# @param config [Object] An instance of {Readiness::Zendesk::Configuration}
|
203
|
+
# @param object [Hash] The Hash derived from parsing a YAML file
|
204
|
+
def self.convert_managed_content(config, object)
|
205
|
+
path = "#{@location}/managed_content/#{object['active'] ? '' : 'in'}active/#{object['title'].gsub('/', '_')}.yaml"
|
206
|
+
handle_request_error(1, 'Repos', 404, { action: 'Get managed content', id: object['title'] }) unless File.exist?(path)
|
207
|
+
conversion = YAML.safe_load_file("#{@location}/managed_content/fields.yaml")
|
208
|
+
data = YAML.safe_load_file(path)
|
209
|
+
object['execution'] = {
|
210
|
+
"group_by" => (data['group_by'].nil? ? nil : conversion.detect { |c| c['name'] == data['group_by'] }['id'].to_s),
|
211
|
+
"group_order" => data['group_order'],
|
212
|
+
"sort_by" => (data['sort_by'].nil? ? nil : conversion.detect { |c| c['name'] == data['sort_by'] }['id'].to_s),
|
213
|
+
"sort_order" => data['sort_order'],
|
214
|
+
"group" => convert_group(config, data, conversion),
|
215
|
+
"sort" => convert_sort(config, data, conversion),
|
216
|
+
"columns" => convert_columns(config, data, conversion),
|
217
|
+
"fields" => convert_fields(data, conversion),
|
218
|
+
"custom_fields" => convert_custom_fields(config, data, conversion),
|
219
|
+
}
|
220
|
+
object
|
221
|
+
end
|
222
|
+
|
223
|
+
##
|
224
|
+
# Performs conversions for a repo file using managed content
|
225
|
+
#
|
226
|
+
# @author Jason Colyer
|
227
|
+
# @since 1.0.12
|
228
|
+
def self.convert_columns(config, object, conversion)
|
229
|
+
array = []
|
230
|
+
object['fields'].each do |f|
|
231
|
+
c = conversion.detect { |c| c['name'] == f }
|
232
|
+
o = {
|
233
|
+
"id" => c['id'],
|
234
|
+
"title" => c['name'],
|
235
|
+
"type" => nil,
|
236
|
+
"url" => nil,
|
237
|
+
"filterable" => filterable?(c),
|
238
|
+
"sortable" => sortable?(c),
|
239
|
+
}
|
240
|
+
o['type'] = c['type'] if c['custom']
|
241
|
+
o['url'] = "#{config.url}/ticket_fields/#{c['id']}.json" if c['custom']
|
242
|
+
array.push(o.compact)
|
243
|
+
end
|
244
|
+
array
|
245
|
+
end
|
246
|
+
|
247
|
+
##
|
248
|
+
# Performs conversions for a repo file using managed content
|
249
|
+
#
|
250
|
+
# @author Jason Colyer
|
251
|
+
# @since 1.0.12
|
252
|
+
def self.convert_fields(object, conversion)
|
253
|
+
array = []
|
254
|
+
object['fields'].each do |f|
|
255
|
+
c = conversion.detect { |c| c['name'] == f }
|
256
|
+
next if c['custom']
|
257
|
+
o = {
|
258
|
+
"id" => c['id'],
|
259
|
+
"title" => c['name'],
|
260
|
+
"filterable" => filterable?(c),
|
261
|
+
"sortable" => sortable?(c),
|
262
|
+
}
|
263
|
+
array.push(o)
|
264
|
+
end
|
265
|
+
array
|
266
|
+
end
|
267
|
+
|
268
|
+
##
|
269
|
+
# Performs conversions for a repo file using managed content
|
270
|
+
#
|
271
|
+
# @author Jason Colyer
|
272
|
+
# @since 1.0.12
|
273
|
+
def self.convert_custom_fields(config, object, conversion)
|
274
|
+
array = []
|
275
|
+
object['fields'].each do |f|
|
276
|
+
c = conversion.detect { |c| c['name'] == f }
|
277
|
+
next unless c['custom']
|
278
|
+
o = {
|
279
|
+
"id" => c['id'],
|
280
|
+
"title" => c['name'],
|
281
|
+
"type" => c['type'],
|
282
|
+
"url" => "#{config.url}/ticket_fields/#{c['id']}.json",
|
283
|
+
"filterable" => filterable?(c),
|
284
|
+
"sortable" => sortable?(c)
|
285
|
+
}
|
286
|
+
array.push(o.compact)
|
287
|
+
end
|
288
|
+
array.sort_by { |a| a['id'] }
|
289
|
+
end
|
290
|
+
|
291
|
+
##
|
292
|
+
# Performs conversions for a repo file using managed content
|
293
|
+
#
|
294
|
+
# @author Jason Colyer
|
295
|
+
# @since 1.0.12
|
296
|
+
def self.convert_sort(config, object, conversion)
|
297
|
+
return nil if object['sort_by'].nil?
|
298
|
+
|
299
|
+
c = conversion.detect { |c| c['name'] == object['sort_by'] }
|
300
|
+
sort = {
|
301
|
+
"id" => c['id'],
|
302
|
+
"title" => c['name'],
|
303
|
+
"type" => nil,
|
304
|
+
"url" => nil,
|
305
|
+
"filterable" => filterable?(c),
|
306
|
+
"sortable" => sortable?(c),
|
307
|
+
"order" => object['sort_order']
|
308
|
+
}
|
309
|
+
sort['type'] = c['type'] if c['custom']
|
310
|
+
sort['url'] = "#{config.url}/ticket_fields/#{c['id']}.json" if c['custom']
|
311
|
+
sort.compact
|
312
|
+
end
|
313
|
+
|
314
|
+
##
|
315
|
+
# Performs conversions for a repo file using managed content
|
316
|
+
#
|
317
|
+
# @author Jason Colyer
|
318
|
+
# @since 1.0.12
|
319
|
+
def self.convert_group(config, object, conversion)
|
320
|
+
return nil if object['group_by'].nil?
|
321
|
+
|
322
|
+
c = conversion.detect { |c| c['name'] == object['group_by'] }
|
323
|
+
group = {
|
324
|
+
"id" => c['id'],
|
325
|
+
"title" => c['name'],
|
326
|
+
"type" => nil,
|
327
|
+
"url" => nil,
|
328
|
+
"filterable" => filterable?(c),
|
329
|
+
"sortable" => sortable?(c),
|
330
|
+
"order" => object['group_order']
|
331
|
+
}
|
332
|
+
group['type'] = c['type'] if c['custom']
|
333
|
+
group['url'] = "#{config.url}/ticket_fields/#{c['id']}.json" if c['custom']
|
334
|
+
group.compact
|
335
|
+
end
|
336
|
+
|
337
|
+
##
|
338
|
+
# Performs conversions for a repo file using managed content
|
339
|
+
#
|
340
|
+
# @author Jason Colyer
|
341
|
+
# @since 1.0.12
|
342
|
+
def self.sortable?(data)
|
343
|
+
return false if data['name'] == 'Subject'
|
344
|
+
|
345
|
+
true
|
346
|
+
end
|
347
|
+
|
348
|
+
##
|
349
|
+
# Performs conversions for a repo file using managed content
|
350
|
+
#
|
351
|
+
# @author Jason Colyer
|
352
|
+
# @since 1.0.12
|
353
|
+
def self.filterable?(data)
|
354
|
+
return false if data['name'] == 'Subject'
|
355
|
+
return false if data['name'] == 'Requested'
|
356
|
+
return false if data['type'] == 'text'
|
357
|
+
|
358
|
+
true
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the module Repos
|
7
|
+
# @author Jason Colyer
|
8
|
+
# @since 1.0.12
|
9
|
+
module Repos
|
10
|
+
require "#{__dir__}/repos/articles"
|
11
|
+
require "#{__dir__}/repos/automations"
|
12
|
+
require "#{__dir__}/repos/groups"
|
13
|
+
require "#{__dir__}/repos/macros"
|
14
|
+
require "#{__dir__}/repos/organization_fields"
|
15
|
+
require "#{__dir__}/repos/sla_policies"
|
16
|
+
require "#{__dir__}/repos/ticket_fields"
|
17
|
+
require "#{__dir__}/repos/ticket_forms"
|
18
|
+
require "#{__dir__}/repos/triggers"
|
19
|
+
require "#{__dir__}/repos/user_fields"
|
20
|
+
require "#{__dir__}/repos/views"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Salesforce
|
6
|
+
module Salesforce
|
7
|
+
##
|
8
|
+
# Defines the class Accounts within the module {Readiness::Salesforce}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class Accounts < Readiness::Client
|
13
|
+
##
|
14
|
+
# Updates an Account in Salesforce. This will exit on error
|
15
|
+
#
|
16
|
+
# @author Jason Colyer
|
17
|
+
# @since 1.0.12
|
18
|
+
# @param client [Object] An instance of {Readiness::Salesforce::Client}
|
19
|
+
# @param aid [String] The ID of the Account to update
|
20
|
+
# @param args [Various] This allows for multiple 'key: value' entries when calling the function
|
21
|
+
# @return [Boolean]
|
22
|
+
# @example
|
23
|
+
# config = Readiness::Salesforce::Configuration.new
|
24
|
+
# config.api_version = '58.0'
|
25
|
+
# config.client_id = ENV.fetch('SFDC_CLIENTID')
|
26
|
+
# config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
27
|
+
# config.password = ENV.fetch('SFDC_PASSWORD')
|
28
|
+
# config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
29
|
+
# config.username = ENV.fetch('SFDC_USERNAME')
|
30
|
+
# client = Readiness::Salesforce::Client.new(config)
|
31
|
+
# result = Readiness::Salesforce::Client.update!(client, '0016100000AYvx9', Support_Hold__c: false, Support_Instance__c: 'federal-support')
|
32
|
+
# pp result
|
33
|
+
# # => true
|
34
|
+
# result = Readiness::Salesforce::Client.update!(client, '0016100000AYvx9', Restricted_Account__c: nil)
|
35
|
+
# pp result
|
36
|
+
# # => true
|
37
|
+
def self.update!(client, aid, **args)
|
38
|
+
client.connection.update!('Account', Id: aid, **args)
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Determines if a SFDC Account is US Government enabled.
|
44
|
+
#
|
45
|
+
# @author Jason Colyer
|
46
|
+
# @since 1.0.12
|
47
|
+
# @param client [Object] An instance of {Readiness::Salesforce::Client}
|
48
|
+
# @param aid [String] The ID of the Account to check
|
49
|
+
# @return [Boolean]
|
50
|
+
# @example
|
51
|
+
# config = Readiness::Salesforce::Configuration.new
|
52
|
+
# config.api_version = '58.0'
|
53
|
+
# config.client_id = ENV.fetch('SFDC_CLIENTID')
|
54
|
+
# config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
55
|
+
# config.password = ENV.fetch('SFDC_PASSWORD')
|
56
|
+
# config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
57
|
+
# config.username = ENV.fetch('SFDC_USERNAME')
|
58
|
+
# client = Readiness::Salesforce::Client.new(config)
|
59
|
+
# pp Readiness::Salesforce::Client.us_gover_enabled?(client, '0016100000AYvx9')
|
60
|
+
# # => false
|
61
|
+
def self.us_gov_enabled?(client, aid)
|
62
|
+
query = Queries.new(us_gov_check_query_string(aid))
|
63
|
+
results = Queries.run!(client, query)
|
64
|
+
return false if results.count.zero?
|
65
|
+
return false if results.first.Support_Hold__c
|
66
|
+
return false unless results.first.Restricted_Account__c.nil?
|
67
|
+
return true if results.first.Support_Instance__c == 'federal-support'
|
68
|
+
|
69
|
+
if results.first.Account_Demographics_Territory__c =~ /^PUBSEC/
|
70
|
+
if results.first.Account_Demographics_Territory__c != 'PUBSEC_'
|
71
|
+
return true unless results.first.Account_Demographics_Territory__c =~ /SLED/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Provides the String needed to make a specific type of SOQL query
|
79
|
+
#
|
80
|
+
# @author Jason Colyer
|
81
|
+
# @since 1.0.12
|
82
|
+
# @param aid [String] The ID of the Account to check
|
83
|
+
# @return [String]
|
84
|
+
def self.us_gov_check_query_string(aid)
|
85
|
+
<<~STRING
|
86
|
+
SELECT
|
87
|
+
Restricted_Account__c,
|
88
|
+
Support_Hold__c,
|
89
|
+
Support_Instance__c,
|
90
|
+
Account_Demographics_Territory__c,
|
91
|
+
(
|
92
|
+
SELECT
|
93
|
+
Id,
|
94
|
+
Name,
|
95
|
+
Zuora__ProductName__c,
|
96
|
+
Zuora__EffectiveEndDate__c,
|
97
|
+
Zuora__Quantity__c,
|
98
|
+
Zuora__TotalContractValue__c,
|
99
|
+
Subscription_Status__c
|
100
|
+
FROM Zuora__R00N40000001lGjTEAU__r
|
101
|
+
)
|
102
|
+
FROM Account
|
103
|
+
WHERE
|
104
|
+
Account_ID_18__c = '#{aid}'
|
105
|
+
STRING
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Salesforce
|
6
|
+
module Salesforce
|
7
|
+
##
|
8
|
+
# Defines the class Cases within the module {Readiness::Salesforce}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class Cases < Readiness::Client
|
13
|
+
attr_accessor :AccountId, :Description, :Id, :OwnerId, :Priority, :RecordTypeId, :Status, :Subject, :Zendesk_Support_Ticket_ID__c, :Zendesk_Support_Ticket_Requester_Email__c, :Zendesk_Support_Ticket_URL__c
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Salesforce::Cases} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.12
|
20
|
+
# @param object [Object] An instance of {Readiness::Salesforce::Cases}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# item = Readiness::Salesforce::Cases.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@AccountId = object['AccountId']
|
26
|
+
@Description = object['Description']
|
27
|
+
@Id = object['Id']
|
28
|
+
@OwnerId = object['OwnerId']
|
29
|
+
@Priority = object['Priority']
|
30
|
+
@RecordTypeId = object['RecordTypeId']
|
31
|
+
@Status = object['Status']
|
32
|
+
@Subject = object['Subject']
|
33
|
+
@Zendesk_Support_Ticket_ID__c = object['Zendesk_Support_Ticket_ID__c']
|
34
|
+
@Zendesk_Support_Ticket_Requester_Email__c = object['Zendesk_Support_Ticket_Requester_Email__c']
|
35
|
+
@Zendesk_Support_Ticket_URL__c = object['Zendesk_Support_Ticket_URL__c']
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Creates a Case in Salesforce. This will exit on error
|
40
|
+
#
|
41
|
+
# @author Jason Colyer
|
42
|
+
# @since 1.0.12
|
43
|
+
# @param client [Object] An instance of {Readiness::Salesforce::Client}
|
44
|
+
# @param object [Object] An instance of {Readiness::Salesforce::Cases}
|
45
|
+
# @return [Boolean]
|
46
|
+
# @example
|
47
|
+
# config = Readiness::Salesforce::Configuration.new
|
48
|
+
# config.api_version = '58.0'
|
49
|
+
# config.client_id = ENV.fetch('SFDC_CLIENTID')
|
50
|
+
# config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
51
|
+
# config.password = ENV.fetch('SFDC_PASSWORD')
|
52
|
+
# config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
53
|
+
# config.username = ENV.fetch('SFDC_USERNAME')
|
54
|
+
# client = Readiness::Salesforce::Client.new(config)
|
55
|
+
# item = Readiness::Salesforce::Cases.new
|
56
|
+
# item.AccountId = '001ABC123'
|
57
|
+
# item.Description = 'Test description'
|
58
|
+
# item.Id = '500ABC123'
|
59
|
+
# item.OwnerId = '0054ABC123'
|
60
|
+
# item.Priority = 'Normal'
|
61
|
+
# item.Status = 'Closed'
|
62
|
+
# item.Subject = 'Test subject'
|
63
|
+
# item.Zendesk_Support_Ticket_ID__c = '123456'
|
64
|
+
# item.Zendesk_Support_Ticket_Requester_Email__c = 'alice@example.com'
|
65
|
+
# item.Zendesk_Support_Ticket_URL__c = 'https://gitlab.zendesk.com/agent/tickets/123456'
|
66
|
+
# pp Readiness::Salesforce::Cases.update!(client, item)
|
67
|
+
# # => true
|
68
|
+
# returns case ID as String
|
69
|
+
def self.create!(client, object)
|
70
|
+
client.connection.create!('Case', to_clean_json(object))
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Updates a Case in Salesforce. This will exit on error
|
75
|
+
#
|
76
|
+
# @author Jason Colyer
|
77
|
+
# @since 1.0.12
|
78
|
+
# @param client [Object] An instance of {Readiness::Salesforce::Client}
|
79
|
+
# @param object [Object] An instance of {Readiness::Salesforce::Cases}
|
80
|
+
# @return [Boolean]
|
81
|
+
# @example
|
82
|
+
# config = Readiness::Salesforce::Configuration.new
|
83
|
+
# config.api_version = '58.0'
|
84
|
+
# config.client_id = ENV.fetch('SFDC_CLIENTID')
|
85
|
+
# config.client_secret = ENV.fetch('SFDC_CLIENTSECRET')
|
86
|
+
# config.password = ENV.fetch('SFDC_PASSWORD')
|
87
|
+
# config.security_token = ENV.fetch('SFDC_SECURITYTOKEN')
|
88
|
+
# config.username = ENV.fetch('SFDC_USERNAME')
|
89
|
+
# client = Readiness::Salesforce::Client.new(config)
|
90
|
+
# item = Readiness::Salesforce::Cases.new
|
91
|
+
# item.AccountId = '001ABC123'
|
92
|
+
# item.Description = 'Test description'
|
93
|
+
# item.Id = '500ABC123'
|
94
|
+
# item.OwnerId = '0054ABC123'
|
95
|
+
# item.Priority = 'Normal'
|
96
|
+
# item.RecordTypeId: '012123ABC'
|
97
|
+
# item.Status = 'Closed'
|
98
|
+
# item.Subject = 'Test subject'
|
99
|
+
# item.Zendesk_Support_Ticket_ID__c = '123456'
|
100
|
+
# item.Zendesk_Support_Ticket_Requester_Email__c = 'alice@example.com'
|
101
|
+
# item.Zendesk_Support_Ticket_URL__c = 'https://gitlab.zendesk.com/agent/tickets/123456'
|
102
|
+
# pp Readiness::Salesforce::Cases.update!(client, item)
|
103
|
+
# # => true
|
104
|
+
def self.update!(client, object)
|
105
|
+
client.connection.update!('Case', to_hash(object))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the module Salesforce
|
7
|
+
module Salesforce
|
8
|
+
##
|
9
|
+
# Defines the class Client within the module {Readiness::Salesforce}.
|
10
|
+
#
|
11
|
+
# @author Jason Colyer
|
12
|
+
# @since 1.0.12
|
13
|
+
class Client
|
14
|
+
attr_accessor :connection
|
15
|
+
|
16
|
+
##
|
17
|
+
# Creates a new {Readiness::Salesforce::Client} instance
|
18
|
+
#
|
19
|
+
# @author Jason Colyer
|
20
|
+
# @since 1.0.12
|
21
|
+
# @param config [Object] An instance of {Readiness::Salesforce::Configuration}
|
22
|
+
# @example
|
23
|
+
# require 'support_readiness'
|
24
|
+
# config = Readiness::Salesforce::Configuration.new
|
25
|
+
# config.api_version = '58.0'
|
26
|
+
# config.client_id = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'
|
27
|
+
# config.client_secret = 'XYZ789'
|
28
|
+
# config.password = 'p@ssw0rd!'
|
29
|
+
# config.security_token = 'ABC123'
|
30
|
+
# config.username = 'alice@example.com'
|
31
|
+
# client = Readiness::Salesforce::Client.new(config)
|
32
|
+
def initialize(config = Readiness::Salesforce::Configuration.new)
|
33
|
+
@connection = generate_connection(config)
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Generates a connection to Salesforce
|
38
|
+
#
|
39
|
+
# @author Jason Colyer
|
40
|
+
# @since 1.0.12
|
41
|
+
# @param config [Object] An instance of {Readiness::Salesforce::Configuration}
|
42
|
+
# @example
|
43
|
+
# require 'support_readiness'
|
44
|
+
# config = Readiness::Salesforce::Configuration.new
|
45
|
+
# config.api_version = '58.0'
|
46
|
+
# config.client_id = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'
|
47
|
+
# config.client_secret = 'XYZ789'
|
48
|
+
# config.password = 'p@ssw0rd!'
|
49
|
+
# config.security_token = 'ABC123'
|
50
|
+
# config.username = 'alice@example.com'
|
51
|
+
# connection = Readiness::Salesforce::Client.generate_connection(config)
|
52
|
+
def generate_connection(config)
|
53
|
+
Restforce.new(
|
54
|
+
api_version: config.api_version,
|
55
|
+
client_id: config.client_id,
|
56
|
+
client_secret: config.client_secret,
|
57
|
+
password: config.password,
|
58
|
+
security_token: config.security_token,
|
59
|
+
username: config.username
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|