Skip to content

Commit

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

* NEW: Added simple .pe TLD parser (kero.yachay.pe).

* NEW: Added simple .ps TLD parser (whois.pnina.ps).


== Release 1.5.1

Expand Down
6 changes: 3 additions & 3 deletions lib/whois/answer/parser/whois.nic.gs.rb
Expand Up @@ -57,19 +57,19 @@ class WhoisNicGs < Base


property_supported :created_on do
@created_on ||= if content_for_scanner =~ /Created:\s+(.*)\n/
@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/
@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/
@expires_on ||= if content_for_scanner =~ /Expires:\s+(.+?)\n/
Time.parse($1)
end
end
Expand Down
86 changes: 86 additions & 0 deletions lib/whois/answer/parser/whois.pnina.ps.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.pnina.ps parser
#
# Parser for the whois.pnina.ps 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 WhoisPninaPs < 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_not_supported :updated_on

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(&:strip)
else
[]
end
end

end

end
end
end
10 changes: 10 additions & 0 deletions test/fixtures/responses/whois.pnina.ps/available.txt
@@ -0,0 +1,10 @@
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 PNINA as a service to the internet community on behalf of PNINA members. (http://www.pnina.ps/)

The data is for information purposes only. PNINA 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 PNINA and it's registrars (or PNINA or registrars computer systems). The compilation, repackaging, dissemination or other use of this Data is expressly prohibited.

Domain Information
Query: u34jedzcq.ps
Status: Not Registered



20 changes: 20 additions & 0 deletions test/fixtures/responses/whois.pnina.ps/registered.txt
@@ -0,0 +1,20 @@
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 PNINA as a service to the internet community on behalf of PNINA members. (http://www.pnina.ps/)

The data is for information purposes only. PNINA 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 PNINA and it's registrars (or PNINA or registrars computer systems). The compilation, repackaging, dissemination or other use of this Data is expressly prohibited.

Domain Information
Query: google.ps
Status: Active
Created: 19 May 2004
Expires: 19 May 2011
Name Servers:
ns1.google.com
ns2.google.com
ns3.google.com

Registrar Information
Registrar Name: eMarkMonitor




2 changes: 1 addition & 1 deletion test/tlds
Expand Up @@ -228,7 +228,7 @@ pk;;;
pm;whois.nic.fr;nic.pm;u34jedzcq.pm
pn;;;
#Whois::Server.define :tld, ".pr", "whois.nic.pr"
#Whois::Server.define :tld, ".ps", "whois.pnina.ps"
ps;whois.pnina.ps;google.ps;u34jedzcq.ps
pt;whois.dns.pt;google.pt;u34jedzcq.pt
pw;;;
py;;;
Expand Down
91 changes: 91 additions & 0 deletions test/whois/answer/parser/whois.pnina.ps_test.rb
@@ -0,0 +1,91 @@
require 'test_helper'
require 'whois/answer/parser/whois.pnina.ps'

class AnswerParserWhoisPninaPsTest < Whois::Answer::Parser::TestCase

def setup
@klass = Whois::Answer::Parser::WhoisPninaPs
@host = "whois.pnina.ps"
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("2004-05-19")
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
assert_raise(Whois::PropertyNotSupported) { @klass.new(load_part('/registered.txt')).updated_on }
assert_raise(Whois::PropertyNotSupported) { @klass.new(load_part('/available.txt')).updated_on }
end

def test_expires_on
parser = @klass.new(load_part('/registered.txt'))
expected = Time.parse("2011-05-19")
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 )
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 49c90de

Please sign in to comment.