Class: Gemometer::Notifiers::Smtp

Inherits:
Object
  • Object
show all
Defined in:
lib/gemometer/notifiers/smtp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Smtp

Returns a new instance of Smtp.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gemometer/notifiers/smtp.rb', line 8

def initialize(opts)
  @gems     = opts[:gems]
  @to       = opts[:to]
  @sender   = ENV['SMTP_SENDER']
  @server   = ENV['SMTP_SERVER']
  @port     = ENV['SMTP_PORT'] || SMTP.default_port
  @domain   = ENV['SMTP_DOMAIN']
  @username = ENV['SMTP_USERNAME']
  @password = ENV['SMTP_PASSWORD']
  @scheme   = ENV['SMTP_AUTH_SCHEME'] || :plain # :plain, :login, or :cram_md5
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def domain
  @domain
end

#gemsObject (readonly)

Returns the value of attribute gems.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def gems
  @gems
end

#passwordObject (readonly)

Returns the value of attribute password.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def port
  @port
end

#schemeObject (readonly)

Returns the value of attribute scheme.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def scheme
  @scheme
end

#senderObject (readonly)

Returns the value of attribute sender.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def sender
  @sender
end

#serverObject (readonly)

Returns the value of attribute server.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def server
  @server
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def to
  @to
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/gemometer/notifiers/smtp.rb', line 6

def username
  @username
end

Instance Method Details

#bodyObject



45
46
47
48
49
# File 'lib/gemometer/notifiers/smtp.rb', line 45

def body
  msg = '<p>Outdated gems:</p><ul>'
  gems.each { |g| msg += "<li>#{ruby_gems_link(g.name)} #{g.message_line}</li>" }
  msg += '</ul>'
end

#headerObject



31
32
33
34
35
36
37
38
39
# File 'lib/gemometer/notifiers/smtp.rb', line 31

def header
%{
From: Gemometer <#{sender}>
To: #{to.join(",")}
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Subject: Some gems are Outdated
}
end

#messageObject



27
28
29
# File 'lib/gemometer/notifiers/smtp.rb', line 27

def message
  header + body
end

#notifyObject



20
21
22
23
24
25
# File 'lib/gemometer/notifiers/smtp.rb', line 20

def notify

  Net::SMTP.start(server, port, domain, username, password, scheme) do |smtp|
    smtp.send_message(message, sender, to)
  end
end