Skip to content

Commit

Permalink
Added simple .ng TLD parser (whois.nic.net.ng).
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Oct 24, 2010
1 parent 9ee497a commit eebaf13
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
Expand Up @@ -6,6 +6,8 @@

* SERVER: Updated the .nf TLD definition.

* SERVER: Updated the .ng TLD definition.

* NEW: Added .md TLD parser (whois.nic.md).

* NEW: Added simple .mg TLD parser (whois.nic.mg).
Expand All @@ -18,6 +20,8 @@

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

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


== Release 1.5.1

Expand Down
90 changes: 90 additions & 0 deletions lib/whois/answer/parser/whois.nic.net.ng.rb
@@ -0,0 +1,90 @@
#
# = 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.net.ng parser
#
# Parser for the whois.nic.net.ng 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 WhoisNicNetNg < Base

property_supported :status do
@status ||= if content_for_scanner =~ /Status:\s+(.+?)\n/
case $1.downcase
when "active" then :registered
when "not registered" then :available
else
Whois.bug!(ParserError, "Unknown status `#{$1}'.")
end
else
Whois.bug!(ParserError, "Unable to parse status.")
end
end

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

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


property_supported :created_on do
@created_on ||= if content_for_scanner =~ /Created:\s+(.+?)\n/
Time.parse($1)
end
end

property_supported :updated_on do
@updated_on ||= if content_for_scanner =~ /Modified:\s+(.+?)\n/
Time.parse($1)
end
end

property_supported :expires_on do
@expires_on ||= if content_for_scanner =~ /Expires:\s+(.+?)\n/
Time.parse($1)
end
end


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

end

end
end
end
2 changes: 1 addition & 1 deletion lib/whois/definitions/tlds.rb
Expand Up @@ -208,7 +208,7 @@
Whois::Server.define :tld, ".nc", nil, {:web=>"http://www.domaine.nc/en/whois.html", :adapter=>Whois::Server::Adapters::Web}
Whois::Server.define :tld, ".ne", nil, {:adapter=>Whois::Server::Adapters::None}
Whois::Server.define :tld, ".nf", "whois.nic.net.nf"
Whois::Server.define :tld, ".ng", "whois.register.net.ng"
Whois::Server.define :tld, ".ng", "whois.nic.net.ng"
Whois::Server.define :tld, ".ni", nil, {:adapter=>Whois::Server::Adapters::Web, :web=>"http://www.nic.ni/"}
Whois::Server.define :tld, ".nl", "whois.domain-registry.nl"
Whois::Server.define :tld, ".no", "whois.norid.no"
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/responses/whois.nic.net.ng/available.txt
@@ -0,0 +1,9 @@
<br/>
<b>TERMS OF USE:</b> 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 NIRA as a service to the internet community. <br/><br/>The data is for information purposes only. NIRA 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 NIRA or NIRA Accredited Registrars and their computer systems. The compilation, repackaging, dissemination or other use of this Data is expressly prohibited.

Domain Information
Query: u34jedzcq.ng
Status: Not Registered



41 changes: 41 additions & 0 deletions test/fixtures/responses/whois.nic.net.ng/registered.txt
@@ -0,0 +1,41 @@
<br/>
<b>TERMS OF USE:</b> 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 NIRA as a service to the internet community. <br/><br/>The data is for information purposes only. NIRA 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 NIRA or NIRA Accredited Registrars and their computer systems. The compilation, repackaging, dissemination or other use of this Data is expressly prohibited.

Domain Information
Query: nic.net.ng
Status: Active
Created: 13 May 2009 15:27 WAT
Modified: 02 Jul 2010 20:06 WAT
Expires: 31 Jul 2020 00:00 WAT
Name Servers:
rns1.nic.net.ng
rns2.nic.net.ng
rns3.nic.net.ng
rns4.nic.net.ng

Registrar Information
Registrar Name: nira
Country: NG




Registrant:
Organisation: Nigeria Internet Registration Association (NIRA)
Address:
9 Kofo Abayomi Street
Victoria Island
Lagos, Lagos, Nigeria P O Box 1088 Yaba
NG
Email Address: ugo@nira.org.ng


Admin Contact:
Organisation: Nigeria Internet Registration Association (NIRA)
Address:
9 Kofo Abayomi Street
Victoria Island
Lagos, Lagos, Nigeria P O Box 1088 Yaba
NG
Email Address: ugo@nira.org.ng

2 changes: 1 addition & 1 deletion test/tlds
Expand Up @@ -209,7 +209,7 @@ na;whois.na-nic.com.na;google.na;u34jedzcq.na
nc;;;
ne;;;
nf;whois.nic.net.nf;google.nf;u34jedzcq.nf
#Whois::Server.define :tld, ".ng", "whois.register.net.ng"
ng;whois.nic.net.ng;google.ng;u34jedzcq.ng
ni;;;
nl;whois.domain-registry.nl;google.nl;u34jedzcq.nl
no;whois.norid.no;google.no;u34jedzcq.no
Expand Down
98 changes: 98 additions & 0 deletions test/whois/answer/parser/whois.nic.net.ng_test.rb
@@ -0,0 +1,98 @@
require 'test_helper'
require 'whois/answer/parser/whois.nic.net.ng'

class AnswerParserWhoisNicNetNgTest < Whois::Answer::Parser::TestCase

def setup
@klass = Whois::Answer::Parser::WhoisNicNetNg
@host = "whois.nic.net.ng"
end


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

parser = @klass.new(load_part('/available.txt'))
expected = :available
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.parse("2009-05-13 15:27 WAT")
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.parse("2010-07-02 20:06 WAT")
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.parse("2020-07-31 00:00 WAT")
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( rns1.nic.net.ng rns2.nic.net.ng rns3.nic.net.ng rns4.nic.net.ng )
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

0 comments on commit eebaf13

Please sign in to comment.