class Docheck::Application

Constants

TLD

DNS name of the generic top-level domain en.wikipedia.org/wiki/List_of_Internet_top-level_domains

Attributes

available_domains[R]
registered_domains[R]

Public Class Methods

new(base_name) click to toggle source

base_name is sld (Second Level Domain) and converted to lower case.

# File lib/docheck/application.rb, line 13
def initialize(base_name)
  @base_name = base_name.to_s.downcase
  @available_domains = []
  @registered_domains = []
end

Public Instance Methods

fetch() click to toggle source

Check domain name availability and return the result as array.

The first element of array will return all available domains as array.

The last element of array will return all registered domains as array.

# File lib/docheck/application.rb, line 42
def fetch
  attempts = 0
  TLD.each do |tld|
    domain_name = "#{@base_name}.#{tld}"
    begin
      whois_domain = Whois.whois(domain_name)

      if whois_domain.available?
        @available_domains << domain_name
      elsif whois_domain.registered?
        @registered_domains << domain_name
      end
    rescue Timeout::Error
      if attempts <= 3
        attempts += 1
        retry
      else
        attempts = 0
        next
      end
    rescue
      if attempts <= 3
        attempts += 1
        retry
      else
        attempts = 0
        next
      end
    end
  end

  return [@available_domains, @registered_domains]
end
print() click to toggle source

Print the fetch result.