Class: Whois::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/universal_ruby_whois/domain.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, server_tld_key = nil) ⇒ Domain

:nodoc:



27
28
29
# File 'lib/universal_ruby_whois/domain.rb', line 27

def initialize(domain, server_tld_key = nil) #:nodoc:
  @domain, @server_tld_key = domain.to_s.strip.downcase, server_tld_key
end

Instance Attribute Details

#domainObject (readonly)

The domain name, lower case, no spaces.



9
10
11
# File 'lib/universal_ruby_whois/domain.rb', line 9

def domain
  @domain
end

#server_tld_keyObject (readonly)

The TLD server being used for this domain.



12
13
14
# File 'lib/universal_ruby_whois/domain.rb', line 12

def server_tld_key
  @server_tld_key
end

#whois_outputObject (readonly)

The raw whois server output obtained when looking up this domain.



15
16
17
# File 'lib/universal_ruby_whois/domain.rb', line 15

def whois_output
  @whois_output
end

Class Method Details

.find(domain) ⇒ Object

Look up a domain name. If a proper whois server can not be found for this domain name’s extension, it will return nil. Otherwise it returns a Whois::Domain object.

Note: the preferred way to call this method is through the wrapper:

Whois.find(domain)


23
24
25
# File 'lib/universal_ruby_whois/domain.rb', line 23

def self.find(domain)
  ::Whois::Server.find(domain)
end

Instance Method Details

#available?Boolean

Is this domain available? Returns true/false.

Returns:

  • (Boolean)


80
81
82
83
# File 'lib/universal_ruby_whois/domain.rb', line 80

def available?
  return nil unless has_domain_and_server?
  status == :free
end

#creation_dateObject Also known as: created_date

Returns a Time object representing the date this domain name was created.



92
93
94
95
96
97
98
99
# File 'lib/universal_ruby_whois/domain.rb', line 92

def creation_date
  return nil unless has_domain_and_server?
  return @creation_date unless @creation_date.blank?
  if regexes[:creation_date] && (regexes[:creation_date] =~ whois_output)
    @creation_date = (Time.local(*ParseDate.parsedate($2)) rescue nil)
  end
  @creation_date
end

#creation_date_known?Boolean

Do we know the creation date for this domain?

Returns:

  • (Boolean)


105
106
107
# File 'lib/universal_ruby_whois/domain.rb', line 105

def creation_date_known?
  creation_date.kind_of?(Time)
end

#expiration_dateObject

Returns a Time object representing the date this domain name is set to expire.



111
112
113
114
115
116
117
118
# File 'lib/universal_ruby_whois/domain.rb', line 111

def expiration_date
  return nil unless has_domain_and_server?
  return @expiration_date unless @expiration_date.blank?
  if regexes[:expiration_date] && (regexes[:expiration_date] =~ whois_output)
    @expiration_date = (Time.local(*ParseDate.parsedate($2)) rescue nil)
  end
  @expiration_date
end

#expiration_date_known?Boolean

Do we know the expiration date for this domain?

Returns:

  • (Boolean)


121
122
123
# File 'lib/universal_ruby_whois/domain.rb', line 121

def expiration_date_known?
  expiration_date.kind_of?(Time)
end

#has_available_server?Boolean

Does this domain have a server which is available?

Returns:

  • (Boolean)


48
49
50
# File 'lib/universal_ruby_whois/domain.rb', line 48

def has_available_server?
  server && !(server.unavailable? rescue true)
end

#has_domain?Boolean

Does this object have a domain name set?

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/universal_ruby_whois/domain.rb', line 42

def has_domain?
  return false if domain.nil?
  (domain.to_s =~ /\w/) ? true : false
end

#has_domain_and_server?Boolean Also known as: valid?

Does this domain have sufficient info to perform a lookup?

Returns:

  • (Boolean)


53
54
55
# File 'lib/universal_ruby_whois/domain.rb', line 53

def has_domain_and_server?
  has_domain? && has_available_server?
end

#regexesObject

The set of regular expressions that will be used in matching this domain’s whois output.



37
38
39
# File 'lib/universal_ruby_whois/domain.rb', line 37

def regexes
  server.regexes rescue {}
end

#registered?Boolean

Is this domain name registered? Returns true/false.

Returns:

  • (Boolean)


86
87
88
89
# File 'lib/universal_ruby_whois/domain.rb', line 86

def registered?
  return nil unless has_domain_and_server?
  status == :registered
end

#serverObject

Returns the Whois::Server object for this domain name.



32
33
34
# File 'lib/universal_ruby_whois/domain.rb', line 32

def server
  Whois::Server.list[@server_tld_key] rescue nil
end

#statusObject

The domain name’s current registration status: :registered The domain name is registered. :free The domain name is not registered (available). :error There was an error looking up the domain name. :unknown The domain name status could not be determined.



69
70
71
72
73
74
75
76
77
# File 'lib/universal_ruby_whois/domain.rb', line 69

def status
  return :unknown unless has_domain_and_server?
  return @status unless @status.blank?
  [ :registered, :free, :error ].each do |status|
    #return status if Regexp.new(regexes[status].source, 5).match(res)
    return(@status = status) if regexes[status].match_with_inversion(whois_output)
  end
  return @status = :unknown
end

#to_hashObject



128
129
130
131
132
133
134
135
# File 'lib/universal_ruby_whois/domain.rb', line 128

def to_hash
  {
    :status => self.status,
    :creation_date => self.creation_date,
    :expiration_date => self.expiration_date,
    :output => self.whois_output
  }
end

#to_jsonObject



136
137
138
# File 'lib/universal_ruby_whois/domain.rb', line 136

def to_json
  self.to_hash.to_json
end

#to_sObject



125
126
127
# File 'lib/universal_ruby_whois/domain.rb', line 125

def to_s
  domain.to_s rescue nil
end

#to_xmlObject



139
140
141
# File 'lib/universal_ruby_whois/domain.rb', line 139

def to_xml
  self.to_hash.to_xml
end