Class: EmailVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/email_verifier.rb

Constant Summary collapse

API_HOST =
'https://bpi.briteverify.com'
API_PATH =
'emails.json'

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ EmailVerifier

Returns a new instance of EmailVerifier.



9
10
11
12
# File 'lib/email_verifier.rb', line 9

def initialize(api_key)
  @rest = Rest::Client.new(:gem => :typhoeus)
  @api_key = api_key
end

Instance Method Details

#verify(email) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/email_verifier.rb', line 14

def verify(email)
  rest_response = @rest.get("#{API_HOST}/#{API_PATH}", params: {:apikey => @api_key, :address => email})
  if rest_response.code != 200
    raise RuntimeError, "Brite Verify, email verification service is not working. Return code #{rest_response.code}"
  end

  result = JSON.parse(rest_response.body)
  result.update({verified_on: Time.now.strftime('%Y-%m-%d')})
  result['status'].to_sym
end