Module: EmailVeracity::Resolver

Defined in:
lib/email_veracity/resolver.rb

Constant Summary collapse

RECORD_NAMES_TO_RESOLVE_MAP =
{
      :a => {
:method => 'address',
:type => AddressServer,
:constant => Resolv::DNS::Resource::IN::A },
      :mx => {
:method => 'exchange',
:type => ExchangeServer,
:constant => Resolv::DNS::Resource::IN::MX } }

Class Method Summary collapse

Class Method Details

.get_resources_for(domain_name, record = :a) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/email_veracity/resolver.rb', line 28

def get_resources_for(domain_name, record = :a)
  Resolv::DNS.open do |server|
    record_map = RECORD_NAMES_TO_RESOLVE_MAP[record]
    resources = server.getresources(domain_name, record_map[:constant])
    resources_to_servers(resources, record_map[:method])
  end
end

.get_servers_for(domain_name, record = :a) ⇒ Object



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

def get_servers_for(domain_name, record = :a)
  Timeout::timeout(Config[:timeout]) do
    get_resources_for(domain_name, record).map do |server_name|
      type = RECORD_NAMES_TO_RESOLVE_MAP[record.to_sym][:type]
      type.new(server_name)
    end
  end
 rescue Timeout::Error
  raise DomainResourcesTimeoutError,
    "Timed out while try to resolve #{domain_name}"
end

.resources_to_servers(resources, resolve_method) ⇒ Object



36
37
38
39
40
# File 'lib/email_veracity/resolver.rb', line 36

def resources_to_servers(resources, resolve_method)
  resources.inject([]) do |array, resource|
    array << resource.method(resolve_method).call.to_s.strip
  end.reject { |i| Utils.blank?(i) }
end