Skip to content

Instantly share code, notes, and snippets.

@karloscodes
Last active February 16, 2017 23:48
Show Gist options
  • Save karloscodes/08a0eb099aeb487596c6de986bd52960 to your computer and use it in GitHub Desktop.
Save karloscodes/08a0eb099aeb487596c6de986bd52960 to your computer and use it in GitHub Desktop.
class Email::Validate
def self.call(email)
new(email, RFC::CheckSyntaxt, SMTP::CheckUserExistance).call
end
attr_reader :email, :rfc_check_syntaxt, :smtp_check_user
def initialize(email, rfc_check_syntaxt, smtp_check_user)
@email = email
@rfc_check_syntaxt = rfc_check_syntaxt
@smtp_check_user = smtp_check_user
end
def call
rfc_check_syntaxt.call(email)
smtp_check_user.call(email)
end
end
# Usage
begin
Email::Validate.call("malformed@emailcom")
puts "Valid email address"
rescue EmailSyntaxtError, SMTP::NonExistentUserError
puts "Invalid email address"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment