Sha256: 6755d039d6389e63c2ed2f2c5bc32c02172e87b8789897f1b23a5049107581a3

Contents?: true

Size: 756 Bytes

Versions: 3

Compression:

Stored size: 756 Bytes

Contents

# frozen_string_literal: true

module Ryo
  module Plugin
    class DNS
      TYPES = %w(A AAAA CNAME MX NS SOA TXT).freeze

      attr_reader :domain
      def initialize(domain)
        @domain = domain
      end

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

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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ryo-0.3.2 lib/ryo/plugin/dns.rb
ryo-0.3.1 lib/ryo/plugin/dns.rb
ryo-0.3.0 lib/ryo/plugin/dns.rb