Skip to content

Commit

Permalink
Added simple .ht TLD parser (whois.nic.ht).
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed May 28, 2010
1 parent 046e9af commit 6e2323d
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
Expand Up @@ -5,6 +5,8 @@

* NEW: Added simple .pt TLD parser (whois.dns.pt).

* NEW: Added simple .ht TLD parser (whois.nic.ht).


== Release 1.1.7

Expand Down
2 changes: 1 addition & 1 deletion lib/whois/answer/parser/whois.dns.pt.rb
Expand Up @@ -36,7 +36,7 @@ class WhoisDnsPt < Base

property_supported :status do
@status ||= if content_for_scanner =~ / Status:\s+(.*)\n/
$1.split("-").first
$1
end
end

Expand Down
86 changes: 86 additions & 0 deletions lib/whois/answer/parser/whois.nic.ht.rb
@@ -0,0 +1,86 @@
#
# = Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
#
# Category:: Net
# Package:: Whois
# Author:: Simone Carletti <weppos@weppos.net>
# License:: MIT License
#
#--
#
#++


require 'whois/answer/parser/base'


module Whois
class Answer
class Parser

#
# = whois.nic.ht parser
#
# Parser for the whois.nic.ht server.
#
# NOTE: This parser is just a stub and provides only a few basic methods
# to check for domain availability and get domain status.
# Please consider to contribute implementing missing methods.
# See WhoisNicIt parser for an explanation of all available methods
# and examples.
#
class WhoisNicHt < Base

property_supported :status do
@status ||= if content_for_scanner =~ /Status:\s+(.*)\n/
$1
end
end

property_supported :available? do
@available ||= (status == "Not Registered")
end

property_supported :registered? do
@registered ||= !available?
end


property_supported :created_on do
@created_on ||= if content_for_scanner =~ /Created:\s+(.*)\n/
time = Time.parse($1)
Time.utc(time.year, time.month, time.day)
end
end

property_supported :updated_on do
@updated_on ||= if content_for_scanner =~ /Modified:\s+(.*)\n/
time = Time.parse($1)
Time.utc(time.year, time.month, time.day)
end
end

property_supported :expires_on do
@expires_on ||= if content_for_scanner =~ /Expires:\s+(.*)\n/
time = Time.parse($1)
Time.utc(time.year, time.month, time.day)
end
end


property_supported :nameservers do
@nameservers ||= if content_for_scanner =~ /Name Servers:\n((.+\n)+)\n/
$1.split("\n").map { |value| value.split(" ").first.downcase }
else
[]
end
end

end

end
end
end
98 changes: 98 additions & 0 deletions test/answer/parser/whois.nic.ht_test.rb
@@ -0,0 +1,98 @@
require 'test_helper'
require 'whois/answer/parser/whois.nic.ht'

class AnswerParserWhoisNicHtTest < Whois::Answer::Parser::TestCase

def setup
@klass = Whois::Answer::Parser::WhoisNicHt
@host = "whois.nic.ht"
end


def test_status
parser = @klass.new(load_part('/registered.txt'))
expected = "Active"
assert_equal expected, parser.status
assert_equal expected, parser.instance_eval { @status }

parser = @klass.new(load_part('/available.txt'))
expected = "Not Registered"
assert_equal expected, parser.status
assert_equal expected, parser.instance_eval { @status }
end

def test_available?
parser = @klass.new(load_part('/registered.txt'))
expected = false
assert_equal expected, parser.available?
assert_equal expected, parser.instance_eval { @available }

parser = @klass.new(load_part('/available.txt'))
expected = true
assert_equal expected, parser.available?
assert_equal expected, parser.instance_eval { @available }
end

def test_registered?
parser = @klass.new(load_part('/registered.txt'))
expected = true
assert_equal expected, parser.registered?
assert_equal expected, parser.instance_eval { @registered }

parser = @klass.new(load_part('/available.txt'))
expected = false
assert_equal expected, parser.registered?
assert_equal expected, parser.instance_eval { @registered }
end


def test_created_on
parser = @klass.new(load_part('/registered.txt'))
expected = Time.utc(2004, 6, 18)
assert_equal expected, parser.created_on
assert_equal expected, parser.instance_eval { @created_on }

parser = @klass.new(load_part('/available.txt'))
expected = nil
assert_equal expected, parser.created_on
assert_equal expected, parser.instance_eval { @created_on }
end

def test_updated_on
parser = @klass.new(load_part('/registered.txt'))
expected = Time.utc(2010, 5, 20)
assert_equal expected, parser.updated_on
assert_equal expected, parser.instance_eval { @updated_on }

parser = @klass.new(load_part('/available.txt'))
expected = nil
assert_equal expected, parser.updated_on
assert_equal expected, parser.instance_eval { @updated_on }
end

def test_expires_on
parser = @klass.new(load_part('/registered.txt'))
expected = Time.utc(2011, 6, 18)
assert_equal expected, parser.expires_on
assert_equal expected, parser.instance_eval { @expires_on }

parser = @klass.new(load_part('/available.txt'))
expected = nil
assert_equal expected, parser.expires_on
assert_equal expected, parser.instance_eval { @expires_on }
end


def test_nameservers
parser = @klass.new(load_part('/registered.txt'))
expected = %w( ns1.google.com ns2.google.com ns3.google.com ns4.google.com )
assert_equal expected, parser.nameservers
assert_equal expected, parser.instance_eval { @nameservers }

parser = @klass.new(load_part('/available.txt'))
expected = %w()
assert_equal expected, parser.nameservers
assert_equal expected, parser.instance_eval { @nameservers }
end

end
2 changes: 1 addition & 1 deletion test/list_tld
Expand Up @@ -145,7 +145,7 @@ hk;whois.hkdnr.net.hk;google.hk;u34jedzcq.hk
#Whois::Server.define :tld, ".hm", "whois.registry.hm"
hn;whois.afilias-grs.info;google.hn;u34jedzcq.hn
hr;;;
#Whois::Server.define :tld, ".ht", "whois.nic.ht"
ht;whois.nic.ht;google.ht;u34jedzcq.ht
hu;whois.nic.hu;google.hu;u34jedzcq.hu
id;whois.pandi.or.id;google.co.id;u34jedzcq.co.id
ie;whois.domainregistry.ie;google.ie;u34jedzcq.ie
Expand Down
23 changes: 23 additions & 0 deletions test/testcases/responses/whois.nic.ht/available.txt
@@ -0,0 +1,23 @@
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated. Whois database is provided by Consortium FDS/RDDH as a service to the internet
community on by of Consortium FDS/RDDH. (http://www.nic.ht)

The data is for information purposes only. Consortium FDS/RDDH does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to Consortium FDS/RDDH it's members (or Consortium FDS/RDDH or member computer systems). The
compilation, repackaging, dissemination or other use of this Data is
expressly prohibited.

Domain Information
Query: gu34jedzcq.ht
Status: Not Registered




59 changes: 59 additions & 0 deletions test/testcases/responses/whois.nic.ht/registered.txt
@@ -0,0 +1,59 @@
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated. Whois database is provided by Consortium FDS/RDDH as a service to the internet
community on by of Consortium FDS/RDDH. (http://www.nic.ht)

The data is for information purposes only. Consortium FDS/RDDH does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to Consortium FDS/RDDH it's members (or Consortium FDS/RDDH or member computer systems). The
compilation, repackaging, dissemination or other use of this Data is
expressly prohibited.

Domain Information
Query: google.ht
Created: 18 Jun 2004
Expires: 18 Jun 2011
Modified: 20 May 2010
Status: Active
Registrar: MarkMonitor
Name Servers:
ns1.google.com
ns2.google.com
ns3.google.com
ns4.google.com

Registrant:
Google Inc.
Google Inc.
1600 Amphitheatre Parkway
Mountain View, CA 94043
US
dns-admin@google.com
Voice: +1.6502530000
Fax: +1.6506188571

Administrative Contact:
Google Inc.
Google Inc.
1600 Amphitheatre Parkway
Mountain View, CA 94043
US
dns-admin@google.com
Voice: +1.6502530000
Fax: +1.6506188571

Technical Contact:
Google Inc.
1600 Amphitheatre Parkway
Mountain View, CA 94043
US
dns-admin@google.com
Voice: +1.6502530000
Fax: +1.6506188571


0 comments on commit 6e2323d

Please sign in to comment.