class Trumail::Lookup

Attributes

email[R]
format[R]
hash[R]
host[R]
response[R]

Public Class Methods

new(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT) click to toggle source
# File lib/trumail/lookup.rb, line 14
def initialize(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT)
  @email = email
  @host = host
  @format = format.to_sym
  @response = nil
  @hash = {}
end
verify(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT) click to toggle source
# File lib/trumail/lookup.rb, line 22
def self.verify(email, host: DEFAULT_HOST, format: DEFAULT_FORMAT)
  klass = new(email, host: host, format: format)
  klass.verify
  klass
end

Public Instance Methods

address() click to toggle source
# File lib/trumail/lookup.rb, line 49
def address
  @hash['address']
end
catch_all?() click to toggle source
# File lib/trumail/lookup.rb, line 53
def catch_all?
  @hash['catchAll']
end
deliverable?() click to toggle source
# File lib/trumail/lookup.rb, line 57
def deliverable?
  @hash['deliverable']
end
disposable?() click to toggle source
# File lib/trumail/lookup.rb, line 61
def disposable?
  @hash['disposable']
end
domain() click to toggle source
# File lib/trumail/lookup.rb, line 65
def domain
  @hash['domain']
end
error?() click to toggle source
# File lib/trumail/lookup.rb, line 41
def error?
  !success?
end
free?() click to toggle source
# File lib/trumail/lookup.rb, line 69
def free?
  @hash['free']
end
full_inbox?() click to toggle source
# File lib/trumail/lookup.rb, line 73
def full_inbox?
  @hash['fullInbox']
end
gravatar?() click to toggle source
# File lib/trumail/lookup.rb, line 77
def gravatar?
  @hash['gravatar']
end
host_exists?() click to toggle source
# File lib/trumail/lookup.rb, line 81
def host_exists?
  @hash['hostExists']
end
md5_hash() click to toggle source
# File lib/trumail/lookup.rb, line 85
def md5_hash
  @hash['md5Hash']
end
role?() click to toggle source
# File lib/trumail/lookup.rb, line 89
def role?
  @hash['role']
end
success?() click to toggle source
# File lib/trumail/lookup.rb, line 45
def success?
  @hash.key?('address')
end
suggestion() click to toggle source
# File lib/trumail/lookup.rb, line 93
def suggestion
  @hash['suggestion']
end
url() click to toggle source
# File lib/trumail/lookup.rb, line 37
def url
  "#{@host}/v2/lookups/#{@format}?email=#{@email}"
end
username() click to toggle source
# File lib/trumail/lookup.rb, line 97
def username
  @hash['username']
end
valid_format?() click to toggle source
# File lib/trumail/lookup.rb, line 101
def valid_format?
  @hash['validFormat']
end
verify() click to toggle source
# File lib/trumail/lookup.rb, line 28
def verify
  return @hash unless @response.nil?

  Typhoeus::Config.user_agent = Agents.random_user_agent(:desktop)
  @response = Typhoeus.get(url, accept_encoding: 'gzip,deflate').response_body

  parse_by_format
end

Private Instance Methods

parse_by_format() click to toggle source
# File lib/trumail/lookup.rb, line 107
def parse_by_format
  return @hash if @response.nil?

  @hash = case @format
          when :json then Trumail::Parser::Json.parse(@response)
          when :xml then Trumail::Parser::Xml.parse(@response)
          end
end