gitlab_support_readiness 1.0.11 → 1.0.13
Sign up to get free protection for your applications and to get access to all the features.
- 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/jobs.rb +189 -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/pipelines.rb +191 -0
- data/lib/support_readiness/gitlab/projects.rb +85 -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 +4 -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 +122 -2
@@ -262,6 +262,180 @@ module Readiness
|
|
262
262
|
handle_request_error(1, 'GitLab', response.status, { action: 'Update submodule in repo', id: "#{project.id}" }) unless response.status == 200
|
263
263
|
Oj.load(response.body)
|
264
264
|
end
|
265
|
+
|
266
|
+
##
|
267
|
+
# Lists a repository's commits.
|
268
|
+
# This method can take a long time to run depending on the parameters used.
|
269
|
+
#
|
270
|
+
# @author Jason Colyer
|
271
|
+
# @since 1.0.12
|
272
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
273
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
274
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
275
|
+
# @return [Array]
|
276
|
+
# @see https://docs.gitlab.com/ee/api/commits.html#list-repository-commits GitLab API > Repositories > List repository commits
|
277
|
+
# @example
|
278
|
+
# require 'support_readiness'
|
279
|
+
# config = Readiness::GitLab::Configuration.new
|
280
|
+
# config.token = 'test123abc'
|
281
|
+
# client = Readiness::GitLab::Client.new(config)
|
282
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
283
|
+
# commits = Readiness::GitLab::Repositories.commits(client, project)
|
284
|
+
# pp commits.first['title']
|
285
|
+
# # => "Replace sanitize with escape once"
|
286
|
+
def self.commits(client, project, filters)
|
287
|
+
array = []
|
288
|
+
page = 0
|
289
|
+
loop do
|
290
|
+
response = client.connection.get "projects/#{project.id}/repository/commits?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
291
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
292
|
+
body = Oj.load(response.body)
|
293
|
+
array += body
|
294
|
+
break if body.count < 100
|
295
|
+
|
296
|
+
page += 1
|
297
|
+
end
|
298
|
+
array
|
299
|
+
end
|
300
|
+
|
301
|
+
##
|
302
|
+
# Lists a repository's tags.
|
303
|
+
# This method can take a long time to run depending on the parameters used.
|
304
|
+
#
|
305
|
+
# @author Jason Colyer
|
306
|
+
# @since 1.0.12
|
307
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
308
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
309
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
310
|
+
# @return [Array]
|
311
|
+
# @see https://docs.gitlab.com/ee/api/tags.html#list-project-repository-tags GitLab API > Tags > List project repository tags
|
312
|
+
# @example
|
313
|
+
# require 'support_readiness'
|
314
|
+
# config = Readiness::GitLab::Configuration.new
|
315
|
+
# config.token = 'test123abc'
|
316
|
+
# client = Readiness::GitLab::Client.new(config)
|
317
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
318
|
+
# tags = Readiness::GitLab::Repositories.tags(client, project)
|
319
|
+
# pp tags.first['commit']['id']
|
320
|
+
# # => "2695effb5807a22ff3d138d593fd856244e155e7"
|
321
|
+
def self.tags(client, project, filters = [])
|
322
|
+
array = []
|
323
|
+
page = 1
|
324
|
+
loop do
|
325
|
+
response = client.connection.get "projects/#{project.id}/repository/tags?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
326
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
327
|
+
body = Oj.load(response.body)
|
328
|
+
array += body
|
329
|
+
break if body.count < 100
|
330
|
+
|
331
|
+
page += 1
|
332
|
+
end
|
333
|
+
array
|
334
|
+
end
|
335
|
+
|
336
|
+
##
|
337
|
+
# Locates a repository tag. This will not exit on error (except Authentication errors)
|
338
|
+
#
|
339
|
+
# @author Jason Colyer
|
340
|
+
# @since 1.0.12
|
341
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
342
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
343
|
+
# @param tag_name [String] The tag to find
|
344
|
+
# @return [Hash]
|
345
|
+
# @see https://docs.gitlab.com/ee/api/tags.html#get-a-single-repository-tag GitLab API > Tags > Get a single project repository tag
|
346
|
+
# @example
|
347
|
+
# require 'support_readiness'
|
348
|
+
# config = Readiness::GitLab::Configuration.new
|
349
|
+
# config.token = 'test123abc'
|
350
|
+
# client = Readiness::GitLab::Client.new(config)
|
351
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
352
|
+
# tag = Readiness::GitLab::Repositories.find_tag(client, project, 'v5.0.0')
|
353
|
+
# pp tag.['target']
|
354
|
+
# # => "60a8ff033665e1207714d6670fcd7b65304ec02f"
|
355
|
+
def self.find_tag(client, project, tag_name)
|
356
|
+
response = client.connection.get "projects/#{project.id}/repository/tags/#{tag_name}"
|
357
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200
|
358
|
+
Oj.load(response.body)
|
359
|
+
end
|
360
|
+
|
361
|
+
##
|
362
|
+
# Locates a repository tag. This will exit on error
|
363
|
+
#
|
364
|
+
# @author Jason Colyer
|
365
|
+
# @since 1.0.12
|
366
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
367
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
368
|
+
# @param tag_name [String] The tag to find
|
369
|
+
# @return [Hash]
|
370
|
+
# @see https://docs.gitlab.com/ee/api/tags.html#get-a-single-repository-tag GitLab API > Tags > Get a single project repository tag
|
371
|
+
# @example
|
372
|
+
# require 'support_readiness'
|
373
|
+
# config = Readiness::GitLab::Configuration.new
|
374
|
+
# config.token = 'test123abc'
|
375
|
+
# client = Readiness::GitLab::Client.new(config)
|
376
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
377
|
+
# tag = Readiness::GitLab::Repositories.find_tag!(client, project, 'v5.0.0')
|
378
|
+
# pp tag.['target']
|
379
|
+
# # => "60a8ff033665e1207714d6670fcd7b65304ec02f"
|
380
|
+
def self.find_tag!(client, project, tag_name)
|
381
|
+
response = client.connection.get("projects/#{project.id}/repository/tags/#{tag_name}")
|
382
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Find tag', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200
|
383
|
+
Oj.load(response.body)
|
384
|
+
end
|
385
|
+
|
386
|
+
##
|
387
|
+
# Creates a repository tag. This will exit on error
|
388
|
+
#
|
389
|
+
# @author Jason Colyer
|
390
|
+
# @since 1.0.12
|
391
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
392
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
393
|
+
# @param tag [Hash] The Hash to use for the tag creation
|
394
|
+
# @return [Hash]
|
395
|
+
# @see https://docs.gitlab.com/ee/api/tags.html#create-a-new-tag GitLab API > Tags > Create a new tag
|
396
|
+
# @example
|
397
|
+
# require 'support_readiness'
|
398
|
+
# config = Readiness::GitLab::Configuration.new
|
399
|
+
# config.token = 'test123abc'
|
400
|
+
# client = Readiness::GitLab::Client.new(config)
|
401
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
402
|
+
# tag = {
|
403
|
+
# tag_name: 'test',
|
404
|
+
# ref: 'main'
|
405
|
+
# }
|
406
|
+
# create = Readiness::GitLab::Repositories.create_tag!(client, project, tag)
|
407
|
+
# pp create['target']
|
408
|
+
# # => "2695effb5807a22ff3d138d593fd856244e155e7"
|
409
|
+
def self.create_tag!(client, project, tag)
|
410
|
+
response = client.connection.post "projects/#{project.id}/repository/tags", tag.to_json
|
411
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Create tag', id: "projects/#{project.id}/repository/tags" }) unless response.status == 200
|
412
|
+
Oj.load(response.body)
|
413
|
+
end
|
414
|
+
|
415
|
+
##
|
416
|
+
# Deletes a repository tag. This will exit on error
|
417
|
+
#
|
418
|
+
# @author Jason Colyer
|
419
|
+
# @since 1.0.12
|
420
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
421
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
422
|
+
# @param tag_name [String] The name of the tag to delete
|
423
|
+
# @return [Boolean]
|
424
|
+
# @see https://docs.gitlab.com/ee/api/tags.html#delete-a-tag GitLab API > Tags > Delete a tag
|
425
|
+
# @example
|
426
|
+
# require 'support_readiness'
|
427
|
+
# config = Readiness::GitLab::Configuration.new
|
428
|
+
# config.token = 'test123abc'
|
429
|
+
# client = Readiness::GitLab::Client.new(config)
|
430
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
431
|
+
# delete = Readiness::GitLab::Repositories.create_tag!(client, project, 'test')
|
432
|
+
# pp delete
|
433
|
+
# # => true
|
434
|
+
def self.delete_tag!(client, project, tag_name)
|
435
|
+
response = client.connection.delete "projects/#{project.id}/repository/tags/#{tag_name}"
|
436
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Delete tag', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200
|
437
|
+
true
|
438
|
+
end
|
265
439
|
end
|
266
440
|
end
|
267
441
|
end
|
@@ -507,6 +507,30 @@ module Readiness
|
|
507
507
|
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
508
508
|
Oj.load(response.body)
|
509
509
|
end
|
510
|
+
|
511
|
+
##
|
512
|
+
# Determines if a user is the only maintainer on projects they are within
|
513
|
+
#
|
514
|
+
# @author Jason Colyer
|
515
|
+
# @since 1.0.3
|
516
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
517
|
+
# @param user [Object] An instance of {Readiness::GitLab::Users}
|
518
|
+
# @return [Boolean]
|
519
|
+
# @example
|
520
|
+
# require 'support_readiness'
|
521
|
+
# config = Readiness::GitLab::Configuration.new
|
522
|
+
# config.token = 'test123abc'
|
523
|
+
# client = Readiness::GitLab::Client.new(config)
|
524
|
+
# user = Readiness::GitLab::Users.find!(client, 5881867)
|
525
|
+
# pp Readiness::GitLab::Users.only_maintainer?(client, user)
|
526
|
+
# # => true
|
527
|
+
def self.only_maintainer?(client, user)
|
528
|
+
Users.projects(client, user).each do |p|
|
529
|
+
members = Projects.all_members(client, p)
|
530
|
+
return true if members = members.select { |m| m['access_level'] >= 40 && m['username'] != user.username }.count.zero?
|
531
|
+
end
|
532
|
+
false
|
533
|
+
end
|
510
534
|
end
|
511
535
|
end
|
512
536
|
end
|
@@ -11,7 +11,11 @@ module Readiness
|
|
11
11
|
require "#{__dir__}/gitlab/configuration"
|
12
12
|
require "#{__dir__}/gitlab/groups"
|
13
13
|
require "#{__dir__}/gitlab/issues"
|
14
|
+
require "#{__dir__}/gitlab/jobs"
|
15
|
+
require "#{__dir__}/gitlab/markdown"
|
16
|
+
require "#{__dir__}/gitlab/merge_requests"
|
14
17
|
require "#{__dir__}/gitlab/namespaces"
|
18
|
+
require "#{__dir__}/gitlab/pipelines"
|
15
19
|
require "#{__dir__}/gitlab/projects"
|
16
20
|
require "#{__dir__}/gitlab/repositories"
|
17
21
|
require "#{__dir__}/gitlab/users"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the module GoogleCalendar
|
7
|
+
module GoogleCalendar
|
8
|
+
##
|
9
|
+
# Defines the class Client within the module {Readiness::GoogleCalendar}.
|
10
|
+
#
|
11
|
+
# @author Jason Colyer
|
12
|
+
# @since 1.0.12
|
13
|
+
class Client
|
14
|
+
attr_accessor :calendar_id, :service
|
15
|
+
|
16
|
+
##
|
17
|
+
# Creates a new {Readiness::GoogleCalendar::Client} instance
|
18
|
+
#
|
19
|
+
# @author Jason Colyer
|
20
|
+
# @since 1.0.12
|
21
|
+
# @param config [Object] An instance of {Readiness::GoogleCalendar::Configuration}
|
22
|
+
# @example
|
23
|
+
# require 'support_readiness'
|
24
|
+
# config = Readiness::GoogleCalendar::Configuration.new
|
25
|
+
# config.calendar_id = 'abc123'
|
26
|
+
# config.filepath = 'data/config.json'
|
27
|
+
# client = Readiness::GoogleCalendar::Client.new(config)
|
28
|
+
# pp client.calendar_id
|
29
|
+
# # => "abc123"
|
30
|
+
def initialize(config = Readiness::GoogleCalendar::Configuration.new)
|
31
|
+
@service = generate_service(config)
|
32
|
+
@calendar_id = config.calendar_id
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Generates a service connection to Google Calendar
|
37
|
+
#
|
38
|
+
# @author Jason Colyer
|
39
|
+
# @since 1.0.12
|
40
|
+
# @param config [Object] An instance of {Readiness::GoogleCalendar::Configuration}
|
41
|
+
# @example
|
42
|
+
# require 'support_readiness'
|
43
|
+
# config = Readiness::GoogleCalendar::Configuration.new
|
44
|
+
# config.calendar_id = 'abc123'
|
45
|
+
# config.filepath = 'data/config.json'
|
46
|
+
# service = Readiness::GoogleCalendar::Client.generate_service(config)
|
47
|
+
def generate_service(config)
|
48
|
+
authorize = Google::Auth::ServiceAccountCredentials.make_creds(
|
49
|
+
json_key_io: File.open(config.filepath),
|
50
|
+
scope: config.scope
|
51
|
+
)
|
52
|
+
authorize.fetch_access_token!
|
53
|
+
service = Google::Apis::CalendarV3::CalendarService.new
|
54
|
+
service.authorization = authorize
|
55
|
+
service
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the module GoogleCalendar
|
7
|
+
module GoogleCalendar
|
8
|
+
##
|
9
|
+
# Defines the class Configuration within the module {Readiness::GoogleCalendar}.
|
10
|
+
#
|
11
|
+
# @author Jason Colyer
|
12
|
+
# @since 1.0.12
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :calendar_id, :filepath, :scope
|
15
|
+
|
16
|
+
##
|
17
|
+
# Creates a new {Readiness::GoogleCalendar::Configuration} instance
|
18
|
+
#
|
19
|
+
# @author Jason Colyer
|
20
|
+
# @since 1.0.12
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# config = Readiness::GoogleCalendar::Configuration.new
|
24
|
+
# config.calendar_id = 'abc123'
|
25
|
+
# config.filepath = 'data/config.json'
|
26
|
+
# pp config
|
27
|
+
# # => #<Readiness::GoogleCalendar::Configuration:0x00007f352fdd1420
|
28
|
+
# @calendar_id="abc123"
|
29
|
+
# @filepath="data/config.json"
|
30
|
+
# @scope="https://www.googleapis.com/auth/calendar">
|
31
|
+
def initialize
|
32
|
+
# /home/jason/dev/gitlab-support-readiness/zendesk-us-government/tickets/round-robin/lib/round_robin
|
33
|
+
@calendar_id = ''
|
34
|
+
@filepath = ''
|
35
|
+
@scope = 'https://www.googleapis.com/auth/calendar'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the module GoogleCalendar
|
7
|
+
module GoogleCalendar
|
8
|
+
##
|
9
|
+
# Defines the class Events within the module {Readiness::GoogleCalendar}.
|
10
|
+
#
|
11
|
+
# @author Jason Colyer
|
12
|
+
# @since 1.0.12
|
13
|
+
class Events < Readiness::Client
|
14
|
+
attr_accessor :attachments, :attendees, :created, :creator, :description, :id, :location, :summary, :updated
|
15
|
+
##
|
16
|
+
# The time to use for the start of the event. When creating an event, you need to pass a Time/DateTime object for this.
|
17
|
+
# @return [Object] a Time or DateTime object
|
18
|
+
# @example
|
19
|
+
# require 'support_readiness'
|
20
|
+
# event = Readiness::GoogleCalendar::Events.new
|
21
|
+
# event.start = Time.parse('2024-12-18 20:45')
|
22
|
+
# @example
|
23
|
+
# require 'support_readiness'
|
24
|
+
# event = Readiness::GoogleCalendar::Events.new
|
25
|
+
# event.start = DateTime.now
|
26
|
+
attr_accessor :start
|
27
|
+
##
|
28
|
+
# The time to use for the end of the event. When creating an event, you need to pass a Time/DateTime object for this.
|
29
|
+
# @return [Object] a Time or DateTime object
|
30
|
+
# @example
|
31
|
+
# require 'support_readiness'
|
32
|
+
# event = Readiness::GoogleCalendar::Events.new
|
33
|
+
# event.end = Time.parse('2024-12-18 20:45')
|
34
|
+
# @example
|
35
|
+
# require 'support_readiness'
|
36
|
+
# event = Readiness::GoogleCalendar::Events.new
|
37
|
+
# event.end = DateTime.now
|
38
|
+
attr_accessor :end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Creates a new {Readiness::GoogleCalendar::Events} instance
|
42
|
+
#
|
43
|
+
# @author Jason Colyer
|
44
|
+
# @since 1.0.12
|
45
|
+
# @param object [Object] An instance of {Readiness::GoogleCalendar::Events}
|
46
|
+
# @example
|
47
|
+
# require 'support_readiness'
|
48
|
+
# Readiness::GoogleCalendar::Events.new
|
49
|
+
def initialize(object = {})
|
50
|
+
@attachments = object['attachments']
|
51
|
+
@attendees = object['attendees']
|
52
|
+
@created = object['created']
|
53
|
+
@creator = object['creator']
|
54
|
+
@description = object['description']
|
55
|
+
@end = object['end']
|
56
|
+
@id = object['id']
|
57
|
+
@location = object['location']
|
58
|
+
@start = object['start']
|
59
|
+
@summary = object['summary']
|
60
|
+
@updated = object['updated']
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Lists all events on a calendar within specified time range
|
65
|
+
#
|
66
|
+
# @author Jason Colyer
|
67
|
+
# @since 1.0.12
|
68
|
+
# @param client [Object] An instance of {Readiness::GoogleCalendar::Client}
|
69
|
+
# @param start_time [Object] A Time or DateTime object
|
70
|
+
# @param end_time [Object] A Time or DateTime object
|
71
|
+
# @param max [Integer] The max number of results per page
|
72
|
+
# @return [Array]
|
73
|
+
# @example
|
74
|
+
# config = Readiness::GoogleCalendar::Configuration.new
|
75
|
+
# config.calendar_id = 'test@example.com'
|
76
|
+
# config.filepath = 'temp.json'
|
77
|
+
# client = Readiness::GoogleCalendar::Client.new(config)
|
78
|
+
# events = Readiness::GoogleCalendar::Events.list(client, DateTime.now, (DateTime.now + 5.hours))
|
79
|
+
# pp events.count
|
80
|
+
# # => 6
|
81
|
+
def self.list(client, start_time, end_time, max = 1000)
|
82
|
+
items = []
|
83
|
+
page_token = nil
|
84
|
+
loop do
|
85
|
+
response = client.service.list_events(
|
86
|
+
client.calendar_id,
|
87
|
+
max_results: max,
|
88
|
+
single_events: true,
|
89
|
+
order_by: 'startTime',
|
90
|
+
page_token: page_token,
|
91
|
+
time_min: start_time.rfc3339,
|
92
|
+
time_max: end_time.rfc3339
|
93
|
+
)
|
94
|
+
items += response.items
|
95
|
+
break if response.next_page_token.nil?
|
96
|
+
|
97
|
+
page_token = response.next_page_token
|
98
|
+
end
|
99
|
+
items
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Creates an event on a calendar
|
104
|
+
#
|
105
|
+
# @author Jason Colyer
|
106
|
+
# @since 1.0.12
|
107
|
+
# @param client [Object] An instance of {Readiness::GoogleCalendar::Client}
|
108
|
+
# @param event [Object] An instance of {Readiness::GoogleCalendar::Events}
|
109
|
+
# @return [Object] An instance of {Google::Apis::CalendarV3::Event}
|
110
|
+
# @example
|
111
|
+
# config = Readiness::GoogleCalendar::Configuration.new
|
112
|
+
# config.calendar_id = 'test@example.com'
|
113
|
+
# config.filepath = 'temp.json'
|
114
|
+
# client = Readiness::GoogleCalendar::Client.new(config)
|
115
|
+
# event = Readiness::GoogleCalendar::Events.new
|
116
|
+
# event.description = 'Test from Jason'
|
117
|
+
# event.end = Time.parse('2024-10-04 11:00')
|
118
|
+
# event.start = DateTime.parse('2024-10-04 10:00')
|
119
|
+
# event.summary = 'Jason Test'
|
120
|
+
# create = Readiness::GoogleCalendar::Events.create!(client, event)
|
121
|
+
# pp create.id
|
122
|
+
# # => "um4es01mlbn6nqh3gn25phtlvk"
|
123
|
+
def self.create!(client, event)
|
124
|
+
google_event = to_google_event(event)
|
125
|
+
client.service.insert_event(client.calendar_id, google_event)
|
126
|
+
end
|
127
|
+
|
128
|
+
##
|
129
|
+
# Deletes an event on a calendar
|
130
|
+
#
|
131
|
+
# @author Jason Colyer
|
132
|
+
# @since 1.0.12
|
133
|
+
# @param client [Object] An instance of {Readiness::GoogleCalendar::Client}
|
134
|
+
# @param event [Object] An instance of {Readiness::GoogleCalendar::Events} or {Google::Apis::CalendarV3::Event}
|
135
|
+
# @return [Boolean]
|
136
|
+
# @example
|
137
|
+
# config = Readiness::GoogleCalendar::Configuration.new
|
138
|
+
# config.calendar_id = 'test@example.com'
|
139
|
+
# config.filepath = 'temp.json'
|
140
|
+
# client = Readiness::GoogleCalendar::Client.new(config)
|
141
|
+
# event = Readiness::GoogleCalendar::Events.new
|
142
|
+
# event.id = 'um4es01mlbn6nqh3gn25phtlvk'
|
143
|
+
# delete = Readiness::GoogleCalendar::Events.delete!(client, event)
|
144
|
+
# pp delete
|
145
|
+
# # => true
|
146
|
+
def self.delete!(client, event)
|
147
|
+
client.service.delete_event(client.calendar_id, event.id)
|
148
|
+
true
|
149
|
+
end
|
150
|
+
|
151
|
+
##
|
152
|
+
# Converts an instance of {Readiness::GoogleCalendar::Events} to {Google::Apis::CalendarV3::Event}
|
153
|
+
#
|
154
|
+
# @author Jason Colyer
|
155
|
+
# @since 1.0.12
|
156
|
+
# @param event [Object] An instance of {Readiness::GoogleCalendar::Events}
|
157
|
+
# @return [Object] An instance of {Google::Apis::CalendarV3::Event}
|
158
|
+
def self.to_google_event(event)
|
159
|
+
Google::Apis::CalendarV3::Event.new(
|
160
|
+
description: event.description,
|
161
|
+
end: Google::Apis::CalendarV3::EventDateTime.new(date_time: event.end.rfc3339),
|
162
|
+
location: event.location,
|
163
|
+
start: Google::Apis::CalendarV3::EventDateTime.new(date_time: event.start.rfc3339),
|
164
|
+
summary: event.summary
|
165
|
+
)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
##
|
6
|
+
# Defines the module GoogleCalendar
|
7
|
+
# @author Jason Colyer
|
8
|
+
# @since 1.0.12
|
9
|
+
module GoogleCalendar
|
10
|
+
require "#{__dir__}/google_calendar/client"
|
11
|
+
require "#{__dir__}/google_calendar/configuration"
|
12
|
+
require "#{__dir__}/google_calendar/events"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Mailgun
|
6
|
+
module Mailgun
|
7
|
+
##
|
8
|
+
# Defines the class Bounces within the module {Readiness::Mailgun}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class Bounces < Readiness::Client
|
13
|
+
attr_accessor :address, :code, :error, :created_at
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Mailgun::Bounces} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.12
|
20
|
+
# @param object [Object] An instance of {Readiness::Mailgun::Bounces}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# Readiness::Mailgun::Bounces.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@address = object['address']
|
26
|
+
@code = object['code']
|
27
|
+
@error = object['error']
|
28
|
+
@created_at = object['created_at']
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Locates a suppression within Mailgun. This will not exit on error (except Authentication errors)
|
33
|
+
#
|
34
|
+
# @author Jason Colyer
|
35
|
+
# @since 1.0.12
|
36
|
+
# @param client [Object] An instance of {Readiness::Mailgun::Client}
|
37
|
+
# @param email [String] The email to look for
|
38
|
+
# @return [Object] An instance of {Readiness::Mailgun::Bounces}
|
39
|
+
# @see https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Bounces/#tag/Bounces/operation/api.(*BounceController).Get-fm-20 Mailgun API > Bounces > View single bounce event
|
40
|
+
# @example
|
41
|
+
# require 'support_readiness'
|
42
|
+
# config = Readiness::Mailgun::Configuration.new
|
43
|
+
# config.domain = 'test.gitlab.com'
|
44
|
+
# config.token = 'abc123'
|
45
|
+
# client = Readiness::Mailgun::Client.new(config)
|
46
|
+
# bounce = Readiness::Mailgun::Bounces.find(client, 'test@example.com')
|
47
|
+
# pp bounce.code
|
48
|
+
# # => "550"
|
49
|
+
def self.find(client, email)
|
50
|
+
response = client.connection.get "#{client.domain}/bounces/#{CGI.escape(email)}"
|
51
|
+
handle_request_error(0, 'Mailgun', response.status, { action: 'get', id: "#{client.domain}/bounces/#{CGI.escape(email)}" }) unless response.status == 200
|
52
|
+
Bounces.new Oj.load(response.body)
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Locates a suppression within Mailgun. This will exit on error
|
57
|
+
#
|
58
|
+
# @author Jason Colyer
|
59
|
+
# @since 1.0.12
|
60
|
+
# @param client [Object] An instance of {Readiness::Mailgun::Client}
|
61
|
+
# @param email [String] The email to look for
|
62
|
+
# @return [Object] An instance of {Readiness::Mailgun::Bounces}
|
63
|
+
# @see https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Bounces/#tag/Bounces/operation/api.(*BounceController).Get-fm-20 Mailgun API > Bounces > View single bounce event
|
64
|
+
# @example
|
65
|
+
# require 'support_readiness'
|
66
|
+
# config = Readiness::Mailgun::Configuration.new
|
67
|
+
# config.domain = 'test.gitlab.com'
|
68
|
+
# config.token = 'abc123'
|
69
|
+
# client = Readiness::Mailgun::Client.new(config)
|
70
|
+
# bounce = Readiness::Mailgun::Bounces.find!(client, 'test@example.com')
|
71
|
+
# pp bounce.code
|
72
|
+
# # => "550"
|
73
|
+
def self.find!(client, email)
|
74
|
+
response = client.connection.get "#{client.domain}/bounces/#{CGI.escape(email)}"
|
75
|
+
handle_request_error(1, 'Mailgun', response.status, { action: 'get', id: "#{client.domain}/bounces/#{CGI.escape(email)}" }) unless response.status == 200
|
76
|
+
Bounces.new Oj.load(response.body)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Deletes a suppression within Mailgun. This will exit on error
|
80
|
+
#
|
81
|
+
# @author Jason Colyer
|
82
|
+
# @since 1.0.12
|
83
|
+
# @param client [Object] An instance of {Readiness::Mailgun::Client}
|
84
|
+
# @param bounce [Object] An instance of {Readiness::Mailgun::Bounces}
|
85
|
+
# @return [Boolean]
|
86
|
+
# @see https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Bounces/#tag/Bounces/operation/api.(*BounceController).Delete-fm-25 Mailgun API > Bounces > Clear a single bounce
|
87
|
+
# @example
|
88
|
+
# require 'support_readiness'
|
89
|
+
# config = Readiness::Mailgun::Configuration.new
|
90
|
+
# config.domain = 'test.gitlab.com'
|
91
|
+
# config.token = 'abc123'
|
92
|
+
# client = Readiness::Mailgun::Client.new(config)
|
93
|
+
# bounce = Readiness::Mailgun::Bounces.find!(client, 'test@example.com')
|
94
|
+
# pp Readiness::Mailgun::Bounces.delete!(client, bounce)
|
95
|
+
# # => true
|
96
|
+
def self.delete!(client, bounce)
|
97
|
+
response = client.connection.delete "#{client.domain}/bounces/#{CGI.escape(bounce.address)}"
|
98
|
+
handle_request_error(1, 'Mailgun', response.status, { action: 'delete', id: "#{client.domain}/bounces/#{CGI.escape(email)}" }) unless response.status == 200
|
99
|
+
true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Mailgun
|
6
|
+
module Mailgun
|
7
|
+
##
|
8
|
+
# Defines the class Client within the module {Readiness::Mailgun}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.12
|
12
|
+
class Client
|
13
|
+
attr_reader :connection, :domain
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::Mailgun::Client} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.12
|
20
|
+
# @param config [Object] An instance of {Readiness::Mailgun::Configuration}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# config = Readiness::Mailgun::Configuration.new
|
24
|
+
# config.token = 'test123abc'
|
25
|
+
# config.domain = 'test.gitlab.com'
|
26
|
+
# client = Readiness::Mailgun::Client.new(config)
|
27
|
+
def initialize(config = Readiness::Mailgun::Configuration.new)
|
28
|
+
@connection = generate_connection(config)
|
29
|
+
@domain = config.domain
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Used to generate the retry options passed to Faraday via faraday-retry
|
34
|
+
#
|
35
|
+
# @author Jason Colyer
|
36
|
+
# @since 1.0.12
|
37
|
+
# @param config [Object] An instance of {Readiness::Mailgun::Configuration}
|
38
|
+
# @return [Hash]
|
39
|
+
def retry_options(config)
|
40
|
+
{
|
41
|
+
max: config.retry_max,
|
42
|
+
interval: config.retry_interval,
|
43
|
+
interval_randomness: config.retry_randomness,
|
44
|
+
backoff_factor: config.retry_backoff,
|
45
|
+
exceptions: config.retry_exceptions
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Used to generate a Faraday connection
|
51
|
+
#
|
52
|
+
# @author Jason Colyer
|
53
|
+
# @since 1.0.0
|
54
|
+
# @param config [Object] An instance of {Readiness::Mailgun::Configuration}
|
55
|
+
# @return [Object]
|
56
|
+
def generate_connection(config)
|
57
|
+
Faraday.new("https://api:#{config.token}@api.mailgun.net/v3") do |c|
|
58
|
+
c.request :retry, retry_options(config)
|
59
|
+
c.adapter Faraday.default_adapter
|
60
|
+
c.headers['Content-Type'] = 'application/json'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|