Module: SendGrid4r::REST::Alerts
- Includes:
- Request
- Included in:
- API
- Defined in:
- lib/sendgrid4r/rest/alerts.rb
Overview
SendGrid Web API v3 Alerts
Defined Under Namespace
Classes: Alert
Constant Summary
Constants included
from Request
Request::BASE_URL
Class Method Summary
collapse
Instance Method Summary
collapse
-
#delete_alert(alert_id:, &block) ⇒ Object
-
#get_alert(alert_id:, &block) ⇒ Object
-
#get_alerts(&block) ⇒ Object
-
#patch_alert(alert_id:, email_to: nil, frequency: nil, percentage: nil, &block) ⇒ Object
-
#post_alert(type:, email_to:, percentage: nil, frequency: nil, &block) ⇒ Object
Methods included from Request
#create_args, #delete, #execute, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put
Class Method Details
.create_alert(resp) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 31
def self.create_alert(resp)
return resp if resp.nil?
created_at = Time.at(resp['created_at'])
updated_at = Time.at(resp['updated_at'])
Alert.new(
created_at,
resp['email_to'],
resp['frequency'],
resp['id'],
resp['percentage'],
resp['type'],
updated_at
)
end
|
.create_alerts(resp) ⇒ Object
26
27
28
29
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 26
def self.create_alerts(resp)
return resp if resp.nil?
resp.map { |alert| Alerts.create_alert(alert) }
end
|
.url(alert_id = nil) ⇒ Object
20
21
22
23
24
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 20
def self.url(alert_id = nil)
url = "#{BASE_URL}/alerts"
url = "#{url}/#{alert_id}" unless alert_id.nil?
url
end
|
Instance Method Details
#delete_alert(alert_id:, &block) ⇒ Object
65
66
67
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 65
def delete_alert(alert_id:, &block)
delete(@auth, Alerts.url(alert_id), &block)
end
|
#get_alert(alert_id:, &block) ⇒ Object
59
60
61
62
63
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 59
def get_alert(alert_id:, &block)
endpoint = Alerts.url(alert_id)
resp = get(@auth, endpoint, &block)
finish(resp, @raw_resp) { |r| Alerts.create_alert(r) }
end
|
#get_alerts(&block) ⇒ Object
46
47
48
49
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 46
def get_alerts(&block)
resp = get(@auth, Alerts.url, &block)
finish(resp, @raw_resp) { |r| Alerts.create_alerts(r) }
end
|
#patch_alert(alert_id:, email_to: nil, frequency: nil, percentage: nil, &block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 69
def patch_alert(
alert_id:, email_to: nil, frequency: nil, percentage: nil, &block
)
params = {}
params[:email_to] = email_to unless email_to.nil?
params[:frequency] = frequency unless frequency.nil?
params[:percentage] = percentage unless percentage.nil?
endpoint = Alerts.url(alert_id)
resp = patch(@auth, endpoint, params, &block)
finish(resp, @raw_resp) { |r| Alerts.create_alert(r) }
end
|
#post_alert(type:, email_to:, percentage: nil, frequency: nil, &block) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/sendgrid4r/rest/alerts.rb', line 51
def post_alert(type:, email_to:, percentage: nil, frequency: nil, &block)
params = { type: type, email_to: email_to }
params[:percentage] = percentage unless percentage.nil?
params[:frequency] = frequency unless frequency.nil?
resp = post(@auth, Alerts.url, params, &block)
finish(resp, @raw_resp) { |r| Alerts.create_alert(r) }
end
|