class PairingShuffler::Mailer

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/pairing_shuffler.rb, line 72
def initialize(config)
  @config = config
end

Public Instance Methods

notify(emails) click to toggle source
# File lib/pairing_shuffler.rb, line 85
    def notify(emails)
      subject = "PairingShuffler winners"
      url = config[:short] || "https://docs.google.com/spreadsheet/ccc?key=#{config[:doc]}"
      # FYI: if the first line is a url the email is blank in gmail
      body = <<-MAIL.gsub(/^ {8}/, "")
        Hello #{emails.map{|e|e.sub(/@.*/,"")}.join(" & ")}!

        You both singed up for PairingShuffler at #{url}
        so let's pair!

        What time would work for you ?

        Ideas:
         - Talk out loud & explain: what are you thinking / what are you going to do
         - Ping pong with tests: A writes tests, B writes implementation
         - Invite others to sign up for pairing

        Greetings,
        PairingShuffler
      MAIL
      send_email(emails, :subject => subject, :body => body)
    end
session() { |self| ... } click to toggle source

Google returns 535-5.7.1 on to frequent auth -> only do it once

# File lib/pairing_shuffler.rb, line 77
def session
  @session = true
  yield self
ensure
  @session = false
  stop_smtp
end

Private Instance Methods

send_email(tos, options={}) click to toggle source
# File lib/pairing_shuffler.rb, line 110
    def send_email(tos, options={})
      tos.each do |to|
        message = <<-MESSAGE.gsub(/^ {10}/, "")
          From: PairingShuffler <#{config.fetch(:username)}>
          To: #{to}
          Reply-To: #{(tos - [to]).join(", ")}
          Subject: #{options.fetch(:subject)}

          #{options.fetch(:body)}
        MESSAGE
        smtp.send_message message, config.fetch(:username), to
      end
    end
smtp() click to toggle source
# File lib/pairing_shuffler.rb, line 124
def smtp
  raise unless @session
  @smtp ||= begin
    smtp = Net::SMTP.new "smtp.gmail.com", 587
    smtp.enable_starttls
    smtp.start("gmail.com", config.fetch(:username), config.fetch(:password), :login)
    smtp
  end
end
stop_smtp() click to toggle source
# File lib/pairing_shuffler.rb, line 134
def stop_smtp
  @smtp.finish if @smtp && @smtp.started?
end