Last active
February 16, 2017 23:48
-
-
Save karloscodes/08a0eb099aeb487596c6de986bd52960 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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