gitlab_support_readiness 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/support_readiness/calendly/client.rb +64 -0
  3. data/lib/support_readiness/calendly/configuration.rb +45 -0
  4. data/lib/support_readiness/calendly/organization_memberships.rb +67 -0
  5. data/lib/support_readiness/calendly/organizations.rb +123 -0
  6. data/lib/support_readiness/calendly/users.rb +105 -0
  7. data/lib/support_readiness/calendly.rb +16 -0
  8. data/lib/support_readiness/client.rb +88 -1
  9. data/lib/support_readiness/dates.rb +90 -0
  10. data/lib/support_readiness/gitlab/configuration.rb +0 -1
  11. data/lib/support_readiness/gitlab/groups.rb +35 -0
  12. data/lib/support_readiness/gitlab/markdown.rb +37 -0
  13. data/lib/support_readiness/gitlab/merge_requests.rb +127 -0
  14. data/lib/support_readiness/gitlab/namespaces.rb +22 -0
  15. data/lib/support_readiness/gitlab/projects.rb +36 -1
  16. data/lib/support_readiness/gitlab/repositories.rb +174 -0
  17. data/lib/support_readiness/gitlab/users.rb +24 -0
  18. data/lib/support_readiness/gitlab.rb +2 -0
  19. data/lib/support_readiness/google_calendar/client.rb +59 -0
  20. data/lib/support_readiness/google_calendar/configuration.rb +39 -0
  21. data/lib/support_readiness/google_calendar/events.rb +169 -0
  22. data/lib/support_readiness/google_calendar.rb +14 -0
  23. data/lib/support_readiness/mailgun/bounces.rb +103 -0
  24. data/lib/support_readiness/mailgun/client.rb +65 -0
  25. data/lib/support_readiness/mailgun/configuration.rb +46 -0
  26. data/lib/support_readiness/mailgun/emails.rb +95 -0
  27. data/lib/support_readiness/mailgun.rb +15 -0
  28. data/lib/support_readiness/pagerduty/escalation_policies.rb +1 -1
  29. data/lib/support_readiness/pagerduty/schedules.rb +27 -3
  30. data/lib/support_readiness/pagerduty/services.rb +1 -1
  31. data/lib/support_readiness/pagerduty/users.rb +197 -0
  32. data/lib/support_readiness/pagerduty.rb +1 -0
  33. data/lib/support_readiness/repos/articles.rb +335 -0
  34. data/lib/support_readiness/repos/automations.rb +247 -0
  35. data/lib/support_readiness/repos/groups.rb +188 -0
  36. data/lib/support_readiness/repos/macros.rb +224 -0
  37. data/lib/support_readiness/repos/organization_fields.rb +193 -0
  38. data/lib/support_readiness/repos/sla_policies.rb +192 -0
  39. data/lib/support_readiness/repos/ticket_fields.rb +200 -0
  40. data/lib/support_readiness/repos/ticket_forms.rb +200 -0
  41. data/lib/support_readiness/repos/triggers.rb +255 -0
  42. data/lib/support_readiness/repos/user_fields.rb +201 -0
  43. data/lib/support_readiness/repos/views.rb +362 -0
  44. data/lib/support_readiness/repos.rb +22 -0
  45. data/lib/support_readiness/salesforce/accounts.rb +109 -0
  46. data/lib/support_readiness/salesforce/cases.rb +109 -0
  47. data/lib/support_readiness/salesforce/client.rb +64 -0
  48. data/lib/support_readiness/salesforce/configuration.rb +49 -0
  49. data/lib/support_readiness/salesforce/queries.rb +62 -0
  50. data/lib/support_readiness/salesforce.rb +16 -0
  51. data/lib/support_readiness/slack/client.rb +63 -0
  52. data/lib/support_readiness/slack/configuration.rb +43 -0
  53. data/lib/support_readiness/slack/messages.rb +37 -0
  54. data/lib/support_readiness/slack.rb +14 -0
  55. data/lib/support_readiness/zendesk/app_job_statuses.rb +140 -0
  56. data/lib/support_readiness/zendesk/apps.rb +209 -0
  57. data/lib/support_readiness/zendesk/automations.rb +1 -2
  58. data/lib/support_readiness/zendesk/macros.rb +1 -3
  59. data/lib/support_readiness/zendesk/organization_fields.rb +1 -1
  60. data/lib/support_readiness/zendesk/theme_job_statuses.rb +136 -0
  61. data/lib/support_readiness/zendesk/themes.rb +303 -0
  62. data/lib/support_readiness/zendesk/ticket_field_options.rb +110 -0
  63. data/lib/support_readiness/zendesk/ticket_fields.rb +85 -16
  64. data/lib/support_readiness/zendesk/ticket_forms.rb +65 -2
  65. data/lib/support_readiness/zendesk/tickets.rb +77 -0
  66. data/lib/support_readiness/zendesk/triggers.rb +1 -2
  67. data/lib/support_readiness/zendesk/user_field_options.rb +110 -0
  68. data/lib/support_readiness/zendesk/user_fields.rb +257 -0
  69. data/lib/support_readiness/zendesk/views.rb +49 -2
  70. data/lib/support_readiness/zendesk.rb +7 -0
  71. data/lib/support_readiness.rb +16 -0
  72. metadata +120 -2
@@ -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
@@ -0,0 +1,46 @@
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 Configuration within the module {Readiness::Mailgun}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.12
12
+ class Configuration
13
+ attr_accessor :domain, :token, :retry_options, :retry_max, :retry_interval, :retry_randomness, :retry_backoff, :retry_exceptions
14
+
15
+ ##
16
+ # Creates a new {Readiness::Mailgun::Configuration} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.12
20
+ # @example
21
+ # require 'support_readiness'
22
+ # config = Readiness::Mailgun::Configuration.new
23
+ # config.token = 'test123abc'
24
+ # config.domain = 'test.gitlab.com'
25
+ # pp config
26
+ # # => #<Readiness::Mailgun::Configuration:0x00007f352fdd1420
27
+ # @domain="test.gitlab.com"
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
+ def initialize
36
+ @domain = ''
37
+ @token = ''
38
+ @retry_max = 5
39
+ @retry_interval = 1
40
+ @retry_randomness = 0.5
41
+ @retry_backoff = 2
42
+ @retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,95 @@
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 Emails within the module {Readiness::Mailgun}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.12
12
+ class Emails < Readiness::Client
13
+ attr_accessor :bcc, :cc, :from, :html, :subject, :reply_to, :text, :to
14
+
15
+ ##
16
+ # Creates a new {Readiness::Mailgun::Emails} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.12
20
+ # @param object [Object] An instance of {Readiness::Mailgun::Emails}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # Readiness::Mailgun::Emails.new
24
+ def initialize(object = {})
25
+ @bcc = object['bcc']
26
+ @cc = object['cc']
27
+ @from = object['from']
28
+ @html = object['html']
29
+ @subject = object['subject']
30
+ @reply_to = object['reply_to']
31
+ @text = object['text']
32
+ @to = object['to']
33
+ end
34
+
35
+ ##
36
+ # Sends an email using Mailgun. This will exit on error or if the email values used are invalid
37
+ #
38
+ # @author Jason Colyer
39
+ # @since 1.0.12
40
+ # @param client [Object] An instance of {Readiness::Mailgun::Client}
41
+ # @param email [Object] An instance of {Readiness::Mailgun::Emails}
42
+ # @return [Boolean]
43
+ # @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
44
+ # @example
45
+ # require 'support_readiness'
46
+ # config = Readiness::Mailgun::Configuration.new
47
+ # config.domain = 'test.gitlab.com'
48
+ # config.token = 'abc123'
49
+ # client = Readiness::Mailgun::Client.new(config)
50
+ # email = Readiness::Mailgun::Emails.new
51
+ # email.from = 'techsupport@gitlab.com'
52
+ # email.to = 'jcolyer@gitlab.com'
53
+ # email.subject = 'Test from Jason'
54
+ # email.html = '<p>This is a test</p>'
55
+ # email.text = 'This is a test'
56
+ # pp Readiness::Mailgun::Emails.send!(client, email)
57
+ # # => true
58
+ def self.send!(client, email)
59
+ handle_request_error(1, 'Mailgun', 400, { action: 'Send email', id: email }) unless valid_email?(email)
60
+ response = client.connection.post "#{client.domain}/messages", to_clean_json(email)
61
+ handle_request_error(1, 'Mailgun', response.status, { action: 'Send email', id: email }) unless response.status == 200
62
+ true
63
+ end
64
+
65
+ ##
66
+ # Determines if all required values are present for an email to be sent.
67
+ #
68
+ # @author Jason Colyer
69
+ # @since 1.0.12
70
+ # @param email [Object] An instance of {Readiness::Mailgun::Emails}
71
+ # @return [Boolean]
72
+ # @example
73
+ # require 'support_readiness'
74
+ # email = Readiness::Mailgun::Emails.new
75
+ # email.from = 'techsupport@gitlab.com'
76
+ # email.to = 'jcolyer@gitlab.com'
77
+ # email.subject = 'Test from Jason'
78
+ # email.html = '<p>This is a test</p>'
79
+ # email.text = 'This is a test'
80
+ # pp Readiness::Mailgun::Emails.valid_email?(email)
81
+ # # => true
82
+ # email.subject = nil
83
+ # pp Readiness::Mailgun::Emails.valid_email?(email)
84
+ # # => false
85
+ def self.valid_email?(email)
86
+ return false if email.from.nil?
87
+ return false if email.to.nil?
88
+ return false if email.subject.nil?
89
+ return false if email.html.nil? && email.text.nil?
90
+
91
+ true
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ ##
6
+ # Defines the module Mailgun
7
+ # @author Jason Colyer
8
+ # @since 1.0.12
9
+ module Mailgun
10
+ require "#{__dir__}/mailgun/client"
11
+ require "#{__dir__}/mailgun/configuration"
12
+ require "#{__dir__}/mailgun/bounces"
13
+ require "#{__dir__}/mailgun/emails"
14
+ end
15
+ end
@@ -66,7 +66,7 @@ module Readiness
66
66
  array += body['escalation_policies'].map { |e| EscalationPolicies.new(e) }
67
67
  break unless body['more']
68
68
 
69
- offset += 1
69
+ offset += 100
70
70
  end
71
71
  array
72
72
  end
@@ -10,7 +10,6 @@ module Readiness
10
10
  # @author Jason Colyer
11
11
  # @since 1.0.0
12
12
  # @todo Create a schedule
13
- # @todo Update a scehdule
14
13
  # @todo List audit records for a schedule
15
14
  # @todo List users on call
16
15
  # @todo Preview a schedule
@@ -69,9 +68,9 @@ module Readiness
69
68
  array += body['schedules'].map { |e| Schedules.new(e) }
70
69
  break unless body['more']
71
70
 
72
- offset += 1
71
+ offset += 100
73
72
  end
74
- array
73
+ array.uniq
75
74
  end
76
75
 
77
76
  ##
@@ -218,6 +217,31 @@ module Readiness
218
217
  handle_request_error(1, 'Pagerduty', response.status, { action: 'Delete an override', id: schedule.id }) unless [200, 204].include?(response.status)
219
218
  true
220
219
  end
220
+
221
+ ##
222
+ # Updates a schedule within Pagerduty. This will exit on error
223
+ #
224
+ # @author Jason Colyer
225
+ # @since 1.0.12
226
+ # @param client [Object] An instance of {Readiness::Pagerduty::Client}
227
+ # @param schedule [Object] A {Readiness::Pagerduty::Schedules} instance
228
+ # @return [Object] A {Readiness::Pagerduty::Schedules} instance
229
+ # @see https://developer.pagerduty.com/api-reference/7aff39ee95bfc-update-a-schedule Pagerduty API > Schedules > Update a schedule
230
+ # @example
231
+ # require 'support_readiness'
232
+ # config = Readiness::Pagerduty::Configuration.new
233
+ # config.token = 'test123abc'
234
+ # client = Readiness::Pagerduty::Client.new(config)
235
+ # schedule = Readiness::Pagerduty::Schedules.find(client, 'PI7DH85')
236
+ # schedule.name = 'Updated name'
237
+ # update = Readiness::Pagerduty::Schedules.update!(client, schedule)
238
+ # pp update.name
239
+ # # => "Updated name"
240
+ def self.update!(client, schedule)
241
+ response = client.connection.put "schedules/#{schedule.id}", to_clean_json_with_key(schedule, 'schedule')
242
+ handle_request_error(1, 'Pagerduty', response.status, { action: 'Update schedule', id: schedule.id, message: Oj.load(response.body)}) unless response.status == 200
243
+ Schedules.new(Oj.load(response.body)['schedule'])
244
+ end
221
245
  end
222
246
  end
223
247
  end
@@ -75,7 +75,7 @@ module Readiness
75
75
  array += body['services'].map { |e| Services.new(e) }
76
76
  break unless body['more']
77
77
 
78
- offset += 1
78
+ offset += 100
79
79
  end
80
80
  array
81
81
  end