-
-
Save Khovanov/f9762e9ab2957b0060a640b74f010044 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