module SendGrid4r::REST::Alerts

SendGrid Web API v3 Alerts

Constants

Alert

Public Class Methods

create_alert(resp) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 30
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) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 25
def self.create_alerts(resp)
  return resp if resp.nil?
  resp.map { |alert| Alerts.create_alert(alert) }
end
url(alert_id = nil) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 19
def self.url(alert_id = nil)
  url = "#{BASE_URL}/alerts"
  url = "#{url}/#{alert_id}" unless alert_id.nil?
  url
end

Public Instance Methods

delete_alert(alert_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 64
def delete_alert(alert_id:, &block)
  delete(@auth, Alerts.url(alert_id), &block)
end
get_alert(alert_id:, &block) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 58
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) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 45
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 ) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 68
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) click to toggle source
# File lib/sendgrid4r/rest/alerts.rb, line 50
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