Class: Whois::Domain
- Inherits:
-
Object
- Object
- Whois::Domain
- Defined in:
- lib/universal_ruby_whois/domain.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
The domain name, lower case, no spaces.
-
#server_tld_key ⇒ Object
readonly
The TLD server being used for this domain.
-
#whois_output ⇒ Object
readonly
The raw whois server output obtained when looking up this domain.
Class Method Summary collapse
-
.find(domain) ⇒ Object
Look up a domain name.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Is this domain available? Returns true/false.
-
#creation_date ⇒ Object
(also: #created_date)
Returns a Time object representing the date this domain name was created.
-
#creation_date_known? ⇒ Boolean
Do we know the creation date for this domain?.
-
#expiration_date ⇒ Object
Returns a Time object representing the date this domain name is set to expire.
-
#expiration_date_known? ⇒ Boolean
Do we know the expiration date for this domain?.
-
#has_available_server? ⇒ Boolean
Does this domain have a server which is available?.
-
#has_domain? ⇒ Boolean
Does this object have a domain name set?.
-
#has_domain_and_server? ⇒ Boolean
(also: #valid?)
Does this domain have sufficient info to perform a lookup?.
-
#initialize(domain, server_tld_key = nil) ⇒ Domain
constructor
:nodoc:.
-
#regexes ⇒ Object
The set of regular expressions that will be used in matching this domain’s whois output.
-
#registered? ⇒ Boolean
Is this domain name registered? Returns true/false.
-
#server ⇒ Object
Returns the Whois::Server object for this domain name.
-
#status ⇒ Object
The domain name’s current registration status:
:registered
The domain name is registered. - #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
- #to_xml ⇒ Object
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
#domain ⇒ Object (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_key ⇒ Object (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_output ⇒ Object (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
Instance Method Details
#available? ⇒ Boolean
Is this domain available? Returns true/false.
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_date ⇒ Object 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?
105 106 107 |
# File 'lib/universal_ruby_whois/domain.rb', line 105 def creation_date_known? creation_date.kind_of?(Time) end |
#expiration_date ⇒ Object
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?
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?
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?
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?
53 54 55 |
# File 'lib/universal_ruby_whois/domain.rb', line 53 def has_domain_and_server? has_domain? && has_available_server? end |
#regexes ⇒ Object
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.
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 |
#server ⇒ Object
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 |
#status ⇒ Object
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_hash ⇒ Object
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_json ⇒ Object
136 137 138 |
# File 'lib/universal_ruby_whois/domain.rb', line 136 def to_json self.to_hash.to_json end |
#to_s ⇒ Object
125 126 127 |
# File 'lib/universal_ruby_whois/domain.rb', line 125 def to_s domain.to_s rescue nil end |
#to_xml ⇒ Object
139 140 141 |
# File 'lib/universal_ruby_whois/domain.rb', line 139 def to_xml self.to_hash.to_xml end |