class Whoaz::Whois
Attributes
address[R]
@return [String] The address of the registrant.
available?[R]
@return [Boolean] Availability of the domain.
domain[R]
@return [String] The queried domain name.
email[R]
@return [String] The email of the registrant.
fax[R]
@return [String] The fax of the registrant.
free[R]
@return [Boolean] Availability of the domain.
free?[R]
@return [Boolean] Availability of the domain.
name[R]
@return [String] The name of the registrant.
nameservers[R]
@return [Array] An array of nameservers.
organization[R]
@return [String] The organization of the registrant.
phone[R]
@return [String] The phone of the registrant.
Public Class Methods
new(domain)
click to toggle source
Initializes a new Whois
object.
@param [String] domain The domain name required to query. @return [Whoaz::Whois]
# File lib/whoaz/whois.rb, line 36 def initialize(domain) @domain = domain if raw_domain_info.include?('is not exists') || raw_domain_info.include?('cannot be registered') @free = true else @free = false domain_info = raw_domain_info.split("\n") @nameservers = domain_info[3].sub('Name Servers:', '').strip.split(',') @organization = domain_info[16].sub('Organisation:', '').strip @name = domain_info[17].sub('Name:', '').strip @address = domain_info[19..23].join("\n").strip @phone = domain_info[12].sub('Voice phone:', '').strip @fax = domain_info[13].sub('Fax:', '').strip @email = domain_info[11].sub('Email:', '').strip end end
Public Instance Methods
raw_domain_info()
click to toggle source
Returns raw domain info as responded by WHOIS server.
@return [String]
# File lib/whoaz/whois.rb, line 64 def raw_domain_info @raw_domain_info ||= query end
registered?()
click to toggle source
Checks if the domain name is registered or not.
@return [Boolean]
# File lib/whoaz/whois.rb, line 57 def registered? !free? end
Private Instance Methods
query()
click to toggle source
# File lib/whoaz/whois.rb, line 70 def query post_domain = @domain.split('.', 2) raise InvalidDomain, "Invalid domain name is specified" unless (MAIN_TLD + REGIONAL_TLD).include? post_domain.last url = URI WHOIS_URL req = Net::HTTP::Post.new(url.path, 'Referer' => WHOIS_REFERER) req.set_form_data(lang: 'en', domain: post_domain.first, dom: ".#{post_domain.last}") res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req)} if res.code.to_i == 200 page = Nokogiri::HTML res.body page.at_xpath('//table[4]/tr/td[2]/table[2]/td[1]/pre').text.strip else raise ServerError, "WHOIS server responded with status code #{res.code}" end end