Class: Ryo::Plugin::DNS

Inherits:
Object
  • Object
show all
Defined in:
lib/ryo/plugin/dns.rb

Constant Summary collapse

TYPES =
%w(A AAAA CNAME MX NS SOA TXT).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ DNS

Returns a new instance of DNS.



9
10
11
# File 'lib/ryo/plugin/dns.rb', line 9

def initialize(domain)
  @domain = domain
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



8
9
10
# File 'lib/ryo/plugin/dns.rb', line 8

def domain
  @domain
end

Class Method Details

.discover(domain) ⇒ Object



36
37
38
# File 'lib/ryo/plugin/dns.rb', line 36

def self.discover(domain)
  new(domain).discover
end

Instance Method Details

#dig(type) ⇒ Object



22
23
24
25
26
# File 'lib/ryo/plugin/dns.rb', line 22

def dig(type)
  params = { name: domain, type: type }
  body = fetch_body(params)
  JSON.parse(body)
end

#discoverObject



28
29
30
31
32
33
34
# File 'lib/ryo/plugin/dns.rb', line 28

def discover
  h = {}
  TYPES.each do |type|
    h[type] = dig(type)
  end
  h
end

#endpointObject



13
14
15
# File 'lib/ryo/plugin/dns.rb', line 13

def endpoint
  "https://dns.google.com/resolve"
end

#fetch_body(params) ⇒ Object



17
18
19
20
# File 'lib/ryo/plugin/dns.rb', line 17

def fetch_body(params)
  res = Client.http.get(endpoint, params: params)
  res.body.to_s
end