class BriteVerify::EmailFetcher

Constants

EMAIL_PATH

Public Class Methods

new(key) click to toggle source
# File lib/brite_verify/email_fetcher.rb, line 9
def initialize(key)
  @key = key
end

Public Instance Methods

fetch_email(address) click to toggle source
# File lib/brite_verify/email_fetcher.rb, line 20
def fetch_email(address)
  uri                   = verification_uri(address)
  http                  = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl          = true
  http.continue_timeout = ENV.fetch("BRITEVERIFY_CONTINUE_TIMEOUT", 60).to_i
  http.open_timeout     = ENV.fetch("BRITEVERIFY_OPEN_TIMEOUT", 60).to_i
  http.read_timeout     = ENV.fetch("BRITEVERIFY_READ_TIMEOUT", 60).to_i
  http.verify_mode      = OpenSSL::SSL::VERIFY_PEER
  request               = Net::HTTP::Get.new(uri.request_uri)
  response              = http.request(request)
  EmailResponse.new(response)
end
fetch_raw_email(address) click to toggle source
# File lib/brite_verify/email_fetcher.rb, line 13
def fetch_raw_email(address)
  email_response = fetch_email(address)
  email_response.raw_email
rescue Timeout::Error
  {}
end
verification_uri(address) click to toggle source
# File lib/brite_verify/email_fetcher.rb, line 33
def verification_uri(address)
  query = URI.encode_www_form(address: address, apikey: @key)
  URI::HTTPS.build({host: HOST, path: EMAIL_PATH, query: query})
end