lib/messenger/email.rb in messenger-0.2.0 vs lib/messenger/email.rb in messenger-0.3.0

- old
+ new

@@ -1,38 +1,34 @@ require 'mail' -module Messenger +class Messenger::Email - class Email + def self.valid_url?(url) + !!url.match(/^(mailto:)?[^@]+@.*$/) + end - def self.valid_url?(url) - !!url.match(/^(mailto:)?[^@]+@.*$/) + # URL format: + # mailto:email@example.com + # + # Options: + # :email_from => Who the email is from + # :email_subject => The subject of the email + def self.deliver(url, message, options={}) + raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) + mail = Mail.new do + from options[:email_from] + to url.sub(/mailto:/, '') + subject options[:email_subject] + body message end + mail.deliver! + Messenger::Result.new(true, nil) + rescue Errno::ECONNREFUSED, Errno::EAFNOSUPPORT => e + Messenger::Result.new(false, e) + end - # URL format: - # mailto:email@example.com - # - # Options: - # :email_from => Who the email is from - # :email_subject => The subject of the email - def self.send(url, message, options={}) - raise URLError, "The URL provided is invalid" unless valid_url?(url) - mail = Mail.new do - from options[:email_from] - to url.sub(/mailto:/, '') - subject options[:email_subject] - body message - end - mail.deliver! - Result.new(true, nil) - rescue Errno::ECONNREFUSED, Errno::EAFNOSUPPORT => e - Result.new(false, e) - end - - def self.obfuscate(url) - raise URLError, "The URL provided is invalid" unless valid_url?(url) - url - end - + def self.obfuscate(url) + raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) + url end end