Whois Record

The Whois::Record class is the most important element of the entire application. It's as simple as powerful and represents the content of the WHOIS response returned by the WHOIS server(s).

Structure

The Whois::Record object is composed by two fundamental attributes:

  1. server: an instance of Whois::Server::Adapters::Base representing the WHOIS server adapter which handled the request
  2. parts: an array of one or more Whois::Record::Part

server Attribute

The server attribute is simple to understand. It returns the server adapter which handled the request.

# Example:  Accessing the Whois::Record#server property

r = Whois.whois("google.com")

r.class
# => Whois::Record
r.server.class
# => Whois::Server::Adapters::Verisign

s = r.server
s.options
# => {}
s.type
# => :tld

parts Attribute

The parts attribute holds all the Whois::Record::Parts which compose the full WHOIS response.

# Example:  Accessing the Whois::Record#parts property

r = Whois.whois("google.com")

r.parts.count
# => 2

r.parts.each do |part|
  puts part.host
end
# => whois.crsnic.net
# => whois.markmonitor.com

String vs Record

The initial version of the Whois library returned the response as a simple String. However, a String is a really simple object and isn't a good candidate for storing a complex and multipart element such as a WHOIS response.

Let me explain why.

You have to know that a WHOIS response might be the result of multiple WHOIS requests. For instance, when the WHOIS interface uses the Thin data model, one WHOIS server stores only the name of the WHOIS server of the registrar of a domain, which in turn has the full details on the data being looked up (such as the .com WHOIS servers, which refer the WHOIS query to the registrar where the domain was registered). In this case, Whois needs to recursively contact all hosts in order to compose the final response.

Instead of merging all the responses altogether into a single String, the Whois::Record object preserve the information about each part of the response as Whois::Record::Part instance so you can easily access them.

# Example:  Accessing a Whois::Record::Part instance

r = Whois.whois("google.com")

r.parts.count
# => 2

p = r.parts.first
p.host
# => whois.crsnic.net
p.response
# => "\nWhois Server Version 2.0\n\nDomain names in the .com and .net domains can now be registered..."

But Whois::Record also acts as a String.

# Example:  Similarities between a String and a Whois::Record instance

r = Whois.whois("google.com")

# the following statement
puts r.to_s
# is equal to
puts r
# which is equal to
puts r.content
# which means
puts r.parts.map(&:response).join("\n")