Add DomainResource
class to wrap MX lookup/normalize (#32864)
This commit is contained in:
parent
e8b6607ece
commit
62d65504f6
6 changed files with 46 additions and 19 deletions
22
app/lib/domain_resource.rb
Normal file
22
app/lib/domain_resource.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DomainResource
|
||||
attr_reader :domain
|
||||
|
||||
RESOLVE_TIMEOUT = 5
|
||||
|
||||
def initialize(domain)
|
||||
@domain = domain
|
||||
end
|
||||
|
||||
def mx
|
||||
Resolv::DNS.open do |dns|
|
||||
dns.timeouts = RESOLVE_TIMEOUT
|
||||
dns
|
||||
.getresources(domain, Resolv::DNS::Resource::IN::MX)
|
||||
.to_a
|
||||
.map { |mx| mx.exchange.to_s }
|
||||
.compact_blank
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue