1
0

domain_resource.rb 392 B

12345678910111213141516171819202122
  1. # frozen_string_literal: true
  2. class DomainResource
  3. attr_reader :domain
  4. RESOLVE_TIMEOUT = 5
  5. def initialize(domain)
  6. @domain = domain
  7. end
  8. def mx
  9. Resolv::DNS.open do |dns|
  10. dns.timeouts = RESOLVE_TIMEOUT
  11. dns
  12. .getresources(domain, Resolv::DNS::Resource::IN::MX)
  13. .to_a
  14. .map { |mx| mx.exchange.to_s }
  15. .compact_blank
  16. end
  17. end
  18. end