Class: Rearview::Alerts::EmailAlert

Inherits:
Base
  • Object
show all
Defined in:
lib/rearview/alerts/email_alert.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

key_to_params, valid_scheme?

Methods included from Logger

#logger

Class Method Details

.key?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/rearview/alerts/email_alert.rb', line 29

def self.key?(key)
  p = key_to_params(key)
  valid_scheme?(p["scheme"]) && valid_email?(p["email"])
end

.params(key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rearview/alerts/email_alert.rb', line 17

def self.params(key)
  uri = URI(key)
  if uri.scheme.present?
    {
      "scheme" => uri.scheme,
      "email" => uri.opaque,
    }
  end
rescue
  {}
end

.schemeObject



38
39
40
# File 'lib/rearview/alerts/email_alert.rb', line 38

def self.scheme
  "mailto"
end

.valid_email?(email) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rearview/alerts/email_alert.rb', line 34

def self.valid_email?(email)
  EmailValidator.getInstance.isValid(email)
end

Instance Method Details

#alert(job, result) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/rearview/alerts/email_alert.rb', line 7

def alert(job, result)
  job.alert_keys.each do |key|
    params = EmailAlert.params(key)
    if EmailAlert.key?(params)
      logger.info "#{self} send alert for #{job.inspect} and key #{key} with params #{params}"
      AlertMailer.alert_email(params["email"], job, result).deliver
    end
  end
end