Skip to content

Commit

Permalink
Update whois.tucows.com parser to the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Nov 11, 2013
1 parent 80838c1 commit 9e78e50
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 294 deletions.
12 changes: 4 additions & 8 deletions lib/whois/record/parser/base_icann_compliant.rb
Expand Up @@ -39,15 +39,11 @@ class BaseIcannCompliant < Base


property_supported :status do
status = Array.wrap(node('Domain Status'))
if status.empty?
if available?
:available
else
:registered
end
# status = Array.wrap(node('Domain Status'))
if available?
:available
else
status
:registered
end
end

Expand Down
162 changes: 5 additions & 157 deletions lib/whois/record/parser/whois.tucows.com.rb
Expand Up @@ -7,8 +7,7 @@
#++


require 'whois/record/parser/base'
require 'whois/record/scanners/whois.tucows.com'
require 'whois/record/parser/base_icann_compliant'


module Whois
Expand All @@ -20,161 +19,10 @@ class Parser
# @see Whois::Record::Parser::Example
# The Example parser for the list of all available methods.
#
# @author Simone Carletti
# @author Igor Dolzhikov <bluesriverz@gmail.com>
# @since 3.2.1
#
class WhoisTucowsCom < Base
include Scanners::Scannable

self.scanner = Scanners::WhoisTucowsCom


property_supported :disclaimer do
node("field:disclaimer")
end

property_supported :domain do
if content_for_scanner =~ /Domain name:\s(.+)\n/
$1.strip.downcase
end
end

property_not_supported :domain_id

property_supported :status do
if content_for_scanner =~ /Domain status:\s((.+\n)*)\n/
$1.split("\n").map(&:strip)
end
end

# The server is contacted only in case of a registered domain.
property_supported :available? do
false
end

property_supported :registered? do
!available?
end


property_supported :created_on do
if content_for_scanner =~ /Record created on (.+)\.\n/
Time.parse($1)
end
end

property_supported :updated_on do
if content_for_scanner =~ /Record last updated on (.+)\.\n/
Time.parse($1)
end
end

property_supported :expires_on do
if content_for_scanner =~ /Record expires on (.+)\.\n/
Time.parse($1)
end
end


property_supported :registrar do
Record::Registrar.new(
:name => "TUCOWS",
:organization => "TUCOWS, INC.",
:url => "http://tucowsdomains.com/"
)
end

property_supported :registrant_contacts do
build_contact('Registrant:', Record::Contact::TYPE_REGISTRANT)
end

property_supported :admin_contacts do
build_contact('Administrative Contact:', Record::Contact::TYPE_ADMINISTRATIVE)
end

property_supported :technical_contacts do
build_contact('Technical Contact:', Record::Contact::TYPE_TECHNICAL)
end


property_supported :nameservers do
if content_for_scanner =~ /Domain servers in listed order:\n((?:[^\n]+\n)+)/
$1.split("\n").map do |line|
# NS3.TUCOWS.COM 64.99.97.32
name, ipv4 = line.strip.split(" ")
Record::Nameserver.new(:name => name.downcase, :ipv4 => ipv4)
end
end
end

def response_throttled?
!!(content_for_scanner =~ /Maximum Daily connection limit reached./)
end


private

def build_contact(element, type)
match = content_for_scanner.slice(/#{element}.*\n((.+\n){4,6})(.*\sTech|\n)/, 1)
return unless match

lines = match.split("\n").map(&:strip)

# 0 Tucows.com Co
# 1 96 Mowat Avenue
# 2 Toronto, Ontario M6K3M1
# 3 CA

# 0 Cuesta, Raul rcuesta@rehje.com
# 1 Moliere 450A-101
# 2 Mexico D.F., NA 11560
# 3 MX
# 4 011525552506552

# 0 Bowyer, John john@jabbdesign.com
# 1 8D
# 2 Craven Rd
# 3 Newbury, Berkshire RG14 5NE
# 4 GB
# 5 +44.07967570273 Fax: +44.7967570273

# Does the last line contains the word fax, or has >9 digits
phone, fax = nil
if lines[-1].to_s =~ / [Ff]ax: /
phone, fax = lines.pop.to_s.scan(/^(.+) [Ff]ax: (.+)$/).first
phone = phone.strip
fax = fax.strip
elsif lines[-1].to_s.gsub(/[^\d]+/, '').length > 9
phone = lines.pop
end

# Does the first line end in something that looks like a email address?
name, email, organization = nil
if lines[0].to_s =~ /\S+@\S+$/
name, email = lines[0].scan(/^(.+)\s(\S+@\S+)$/).first
name = name.split(',').map(&:strip).reverse.join(' ') if name
else
organization = lines[0]
end

address = lines[1..-3].join(' ')
city, state, zip = lines[-2].scan(/^(.+), (\w+) (.+)$/).first
Record::Contact.new(
:type => type,
:name => name,
:organization => organization,
:address => address,
:city => city,
:state => state,
:zip => zip,
:country_code => lines[-1],
:email => email,
:phone => phone,
:fax => fax
)
end

class WhoisTucowsCom < BaseIcannCompliant
self.scanner = Scanners::BaseIcannCompliant, {
pattern_available: /^ No match for/
}
end

end
Expand Down

This file was deleted.

This file was deleted.

46 changes: 46 additions & 0 deletions spec/fixtures/responses/whois.tucows.com/status_available.expected
@@ -0,0 +1,46 @@
#domain
%s == nil

#domain_id
%s == nil


#status
%s == :available

#available?
%s == true

#registered?
%s == false


#created_on
%s == nil

#updated_on
%s == nil

#expires_on
%s == nil


#registrar
%s == nil

#registrant_contacts
%s %CLASS{array}
%s == []

#admin_contacts
%s %CLASS{array}
%s == []

#technical_contacts
%s %CLASS{array}
%s == []


#nameservers
%s %CLASS{array}
%s == []
@@ -0,0 +1 @@
No match for U34JEDZCQ.COM
46 changes: 21 additions & 25 deletions spec/fixtures/responses/whois.tucows.com/status_registered.expected
@@ -1,16 +1,12 @@
#disclaimer
%s == "The Data in the Tucows Registrar WHOIS database is provided to you by Tucows\nfor information purposes only, and may be used to assist you in obtaining\ninformation about or related to a domain name's registration record.\n\nTucows makes this information available \"as is,\" and does not guarantee its\naccuracy.\n\nBy submitting a WHOIS query, you agree that you will use this data only for\nlawful purposes and that, under no circumstances will you use this data to:\na) allow, enable, or otherwise support the transmission by e-mail,\ntelephone, or facsimile of mass, unsolicited, commercial advertising or\nsolicitations to entities other than the data recipient's own existing\ncustomers; or (b) enable high volume, automated, electronic processes that\nsend queries or data to the systems of any Registry Operator or\nICANN-Accredited registrar, except as reasonably necessary to register\ndomain names or modify existing registrations.\n\nThe compilation, repackaging, dissemination or other use of this Data is\nexpressly prohibited without the prior written consent of Tucows.\n\nTucows reserves the right to terminate your access to the Tucows WHOIS\ndatabase in its sole discretion, including without limitation, for excessive\nquerying of the WHOIS database or for failure to otherwise abide by this\npolicy.\n\nTucows reserves the right to modify these terms at any time.\n\nBy submitting this query, you agree to abide by these terms.\n\nNOTE: THE WHOIS DATABASE IS A CONTACT DATABASE ONLY. LACK OF A DOMAIN\nRECORD DOES NOT SIGNIFY DOMAIN AVAILABILITY.\n"


#domain
%s == "tucows.com"

#domain_id
%s %ERROR{AttributeNotSupported}
%s == ""


#status
%s == ["clientTransferProhibited", "clientUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited", "serverUpdateProhibited"]
%s == :registered


#available?
Expand All @@ -22,54 +18,54 @@

#created_on
%s %CLASS{time}
%s %TIME{1995-09-07}
%s %TIME{1995-09-07 04:00:00}

#updated_on
%s %CLASS{time}
%s %TIME{2013-08-07}
%s %TIME{2013-08-07 23:52:35}

#expires_on
%s %CLASS{time}
%s %TIME{2014-09-06}
%s %TIME{2014-09-06 04:00:00}


#registrar
%s %CLASS{registrar}
%s.id == nil
%s.name == "TUCOWS"
%s.id == "69"
%s.name == "TUCOWS, INC."
%s.organization == "TUCOWS, INC."
%s.url == "http://tucowsdomains.com/"
%s.url == "http://tucowsdomains.com"

#registrant_contacts
%s %CLASS{array}
%s have(1).item
%s[0] %CLASS{contact}
%s[0].type == Whois::Record::Contact::TYPE_REGISTRANT
%s[0].name == nil
%s[0].name == "DNS Administrator"
%s[0].organization == "Tucows.com Co"
%s[0].address == "96 Mowat Avenue"
%s[0].city == "Toronto"
%s[0].zip == "M6K3M1"
%s[0].state == "Ontario"
%s[0].country_code == "CA"
%s[0].phone == nil
%s[0].fax == nil
%s[0].email == nil
%s[0].phone == "+1.4165350123 ext: 0000"
%s[0].fax == ""
%s[0].email == "dnsadmin@tucows.com"

#admin_contacts
%s %CLASS{array}
%s have(1).item
%s[0] %CLASS{contact}
%s[0].type == Whois::Record::Contact::TYPE_ADMINISTRATIVE
%s[0].name == "DNS Administrator"
%s[0].organization == nil
%s[0].organization == "Tucows ( Delaware ) Inc."
%s[0].address == "96 Mowat Avenue"
%s[0].city == "Toronto"
%s[0].zip == "M6K3M1"
%s[0].state == "Ontario"
%s[0].country_code == "CA"
%s[0].phone == "+1.4165350123x0000"
%s[0].fax == nil
%s[0].phone == "+1.4165350123 ext: 0000"
%s[0].fax == ""
%s[0].email == "dnsadmin@tucows.com"

#technical_contacts
Expand All @@ -78,14 +74,14 @@
%s[0] %CLASS{contact}
%s[0].type == Whois::Record::Contact::TYPE_TECHNICAL
%s[0].name == "DNS Administrator"
%s[0].organization == nil
%s[0].organization == "Tucows ( Delaware ) Inc."
%s[0].address == "96 Mowat Avenue"
%s[0].city == "Toronto"
%s[0].zip == "M6K3M1"
%s[0].state == "Ontario"
%s[0].country_code == "CA"
%s[0].phone == "+1.4165350123x0000"
%s[0].fax == nil
%s[0].phone == "+1.4165350123 ext: 0000"
%s[0].fax == ""
%s[0].email == "dnsadmin@tucows.com"


Expand All @@ -94,10 +90,10 @@
%s %SIZE{3}
%s[0] %CLASS{nameserver}
%s[0].name == "ns3.tucows.com"
%s[0].ipv4 == "64.99.97.32"
%s[0].ipv4 == nil
%s[1] %CLASS{nameserver}
%s[1].name == "ns1.tucows.com"
%s[1].ipv4 == "216.40.47.20"
%s[1].ipv4 == nil
%s[2] %CLASS{nameserver}
%s[2].name == "ns2.tucows.com"
%s[2].ipv4 == "64.98.148.15"
%s[2].ipv4 == nil

0 comments on commit 9e78e50

Please sign in to comment.