Skip to content

Commit

Permalink
whois.nic.hu now correctly raises PropertyNotSupported when a propert…
Browse files Browse the repository at this point in the history
…y is not supported.
  • Loading branch information
weppos committed Mar 13, 2010
1 parent de98a76 commit 1444f8d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

* CHANGED: whois.nic.cc now correctly raises PropertyNotSupported when a property is not supported.

* CHANGED: whois.nic.hu now correctly raises PropertyNotSupported when a property is not supported.


== Release 1.0.5

Expand Down
64 changes: 25 additions & 39 deletions lib/whois/answer/parser/whois.nic.hu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,20 @@ class Parser
class WhoisNicHu < Base
include Ast

# Returns the registry disclaimer that comes with the answer.
property_supported :disclaimer do
node('Disclaimer')
end

# If available, returns the domain name as stored by the registry.

property_supported :domain do
node('Domain')
end

# If available, returns the unique domain ID set by the registry.
property_supported :domain_id do
node('hun-id')
end

# Returns the record status: <tt>:available</tt>, <tt>:in_progress</tt>
# or <tt>:registered</tt>.

property_supported :status do
if node('NotFound')
:available
Expand All @@ -56,30 +53,36 @@ class WhoisNicHu < Base
end
end

# Returns whether this record is available.
property_supported :available? do
@available ||= status == :available
end

# Returns whether this record is registered.
property_supported :registered? do
@registered ||= status == :registered
end

# If available, returns a Time object representing the date
# the record was created, according to the registry answer.

property_supported :created_on do
node('registered') { |raw| Time.parse(raw) }
end

# If available, returns a Time object representing the date
# the record was last updated, according to the registry answer.
property_supported :updated_on do
node('changed') { |raw| Time.parse(raw) }
end

# If available, returns a <tt>Whois::Answer::Contact</tt> record
# containing the registrant details extracted from the registry answer.
property_not_supported :expires_on


property_supported :registrar do
if c = registrar_contact
Answer::Registrar.new(
:id => c[:id],
:name => c[:name],
:organization => c[:organization]
)
end
end

property_supported :registrant do
if registered?
a1 = (node('address') || [])[1].split(/\s/)
Expand All @@ -98,40 +101,14 @@ class WhoisNicHu < Base
end
end

# If available, returns a <tt>Whois::Answer::Contact</tt> record
# containing the admin contact details extracted from the registry answer.
property_supported :admin do
contact('admin-c')
end

# If available, returns a <tt>Whois::Answer::Contact</tt> record
# containing the technical contact details extracted from the registry answer.
property_supported :technical do
contact('tech-c')
end

# If available, returns a <tt>Whois::Answer::Contact</tt> record
# containing the zone contact details extracted from the registry answer.
property_supported :zone_contact do
contact('zone-c')
end

# If available, returns a <tt>Whois::Answer::Contact</tt> record
# containing the registrar contact details extracted from the registry answer.
property_supported :registrar_contact do
contact('registrar')
end

property_supported :registrar do
if rc = registrar_contact
Answer::Registrar.new(
:id => rc[:id],
:name => rc[:name],
:organization => rc[:organization]
)
end
end


# If available, returns an array of name servers entries for this domain
# if any name server is available in the registry answer.
Expand All @@ -140,6 +117,15 @@ class WhoisNicHu < Base
end


def registrar_contact
contact('registrar')
end

def zone_contact
contact('zone-c')
end


protected

def parse
Expand Down
71 changes: 39 additions & 32 deletions test/answer/parser/whois.nic.hu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ def test_updated_on
@klass.new(load_part('/registered.txt')).updated_on
end

def test_expires_on
assert_raise(Whois::PropertyNotSupported) { @klass.new(load_part('/registered.txt')).expires_on }
assert_raise(Whois::PropertyNotSupported) { @klass.new(load_part('/available.txt')).expires_on }
assert_raise(Whois::PropertyNotSupported) { @klass.new(load_part('/in_progress.txt')).expires_on }
end


def test_admin_with_registered
admin = @klass.new(load_part('/registered.txt')).admin
assert_instance_of Whois::Answer::Contact, admin
Expand Down Expand Up @@ -148,6 +155,38 @@ def test_technical_with_unregistered
@klass.new(load_part('/in_progress.txt')).technical
end

def test_registrar_with_registered
registrar = @klass.new(load_part('/registered.txt')).registrar
assert_instance_of Whois::Answer::Registrar, registrar
assert_equal '1960108002', registrar.id
assert_equal '3C Kft. (Registrar)', registrar.name
assert_equal '3C Ltd.', registrar.organization
end

def test_registrar_with_unregistered
assert_equal nil,
@klass.new(load_part('/available.txt')).registrar
assert_equal nil,
@klass.new(load_part('/in_progress.txt')).registrar
end

def test_nameserver
parser = @klass.new(load_part('/registered.txt'))
expected = %w( ns1.google.com ns4.google.com ns3.google.com ns2.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 }

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

def test_zone_contact_with_registered
zone_contact = @klass.new(load_part('/registered.txt')).zone_contact
assert_instance_of Whois::Answer::Contact, zone_contact
Expand Down Expand Up @@ -190,36 +229,4 @@ def test_registrar_contact_with_unregistered
@klass.new(load_part('/in_progress.txt')).registrar_contact
end

def test_registrar_with_registered
registrar = @klass.new(load_part('/registered.txt')).registrar
assert_instance_of Whois::Answer::Registrar, registrar
assert_equal '1960108002', registrar.id
assert_equal '3C Kft. (Registrar)', registrar.name
assert_equal '3C Ltd.', registrar.organization
end

def test_registrar_with_unregistered
assert_equal nil,
@klass.new(load_part('/available.txt')).registrar
assert_equal nil,
@klass.new(load_part('/in_progress.txt')).registrar
end

def test_nameserver
parser = @klass.new(load_part('/registered.txt'))
expected = %w( ns1.google.com ns4.google.com ns3.google.com ns2.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 }

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

end

0 comments on commit 1444f8d

Please sign in to comment.