Skip to content
Browse files

Extract responses based on whoisd into a common base parser.

  • Loading branch information...
1 parent b4aa8fb commit 78cb1dbf33b06df9c890b847be94d1be3c8f3b87 @weppos committed Jul 3, 2012
View
2 lib/whois/record/parser/NOTES.txt
@@ -77,9 +77,7 @@ whois.nic.wf (CNAME whois.nic.fr)
whois.nic.tf (CNAME whois.nic.fr)
whois.nic.yt (CNAME whois.nic.fr)
-whois.nic.cz
whois.tld.ee
-whois.tznic.or.tz
whois.pandi.or.id
whois.nic.ir
ripe.net
View
79 lib/whois/record/parser/base_whoisd.rb
@@ -0,0 +1,79 @@
+#--
+# Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
+#++
+
+
+require 'whois/record/parser/base'
+
+
+module Whois
+ class Record
+ class Parser
+
+ # Base parser for Whoisd servers.
+ #
+ # @abstract
+ #
+ # @since RELEASE
+ class BaseWhoisd < Base
+
+ property_supported :status do
+ if content_for_scanner =~ /status:\s+(.+)\n/
+ case $1.downcase
+ when "paid and in zone"
+ :registered
+ when "update prohibited"
+ :registered
+ when "expired"
+ :expired
+ else
+ Whois.bug!(ParserError, "Unknown status `#{$1}'.")
+ end
+ else
+ :available
+ end
+ end
+
+ property_supported :available? do
+ !!(content_for_scanner =~ /^%ERROR:101: no entries found/)
+ end
+
+ property_supported :registered? do
+ !available?
+ end
+
+
+ property_supported :created_on do
+ if content_for_scanner =~ /registered:\s+(.+?)\n/
+ Time.parse($1)
+ end
+ end
+
+ property_supported :updated_on do
+ if content_for_scanner =~ /changed:\s+(.+?)\n/
+ Time.parse($1)
+ end
+ end
+
+ property_supported :expires_on do
+ if content_for_scanner =~ /expire:\s+(.+?)\n/
+ Time.parse($1)
+ end
+ end
+
+
+ property_supported :nameservers do
+ content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |name|
+ Record::Nameserver.new(:name => name.strip)
+ end
+ end
+
+ end
+
+ end
+ end
+end
View
62 lib/whois/record/parser/whois.nic.cz.rb
@@ -7,69 +7,23 @@
#++
-require 'whois/record/parser/base'
+require 'whois/record/parser/base_whoisd'
module Whois
class Record
class Parser
- #
- # = whois.nic.cz parser
- #
# Parser for the whois.nic.cz 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.
+ # @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 Whois::Record::Parser::Example
+ # The Example parser for the list of all available methods.
#
- class WhoisNicCz < Base
-
- property_supported :status do
- if content_for_scanner =~ /status:\s+(.+)\n/
- case $1.downcase
- when "paid and in zone", "update prohibited"
- :registered
- # NEWSTATUS
- when "expired"
- :expired
- else
- Whois.bug!(ParserError, "Unknown status `#{$1}'.")
- end
- else
- :available
- end
- end
-
- property_supported :available? do
- !!(content_for_scanner =~ /^%ERROR:101: no entries found/)
- end
-
- property_supported :registered? do
- !available?
- end
-
-
- property_supported :created_on do
- if content_for_scanner =~ /registered:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
- property_supported :updated_on do
- if content_for_scanner =~ /changed:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
- property_supported :expires_on do
- if content_for_scanner =~ /expire:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
+ class WhoisNicCz < BaseWhoisd
property_supported :nameservers do
content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |line|
View
54 lib/whois/record/parser/whois.nic.fo.rb
@@ -7,7 +7,7 @@
#++
-require 'whois/record/parser/base'
+require 'whois/record/parser/base_whoisd'
module Whois
@@ -24,57 +24,7 @@ class Parser
# The Example parser for the list of all available methods.
#
# @since RELEASE
- class WhoisNicFo < Base
-
- property_supported :status do
- if content_for_scanner =~ /status:\s+(.+)\n/
- case $1.downcase
- when "paid and in zone"
- :registered
- when "expired"
- :expired
- else
- Whois.bug!(ParserError, "Unknown status `#{$1}'.")
- end
- else
- :available
- end
- end
-
- property_supported :available? do
- !!(content_for_scanner =~ /^%ERROR:101: no entries found/)
- end
-
- property_supported :registered? do
- !available?
- end
-
-
- property_supported :created_on do
- if content_for_scanner =~ /registered:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
- property_supported :updated_on do
- if content_for_scanner =~ /changed:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
- property_supported :expires_on do
- if content_for_scanner =~ /expire:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
-
- property_supported :nameservers do
- content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |name|
- Record::Nameserver.new(:name => name.strip)
- end
- end
-
+ class WhoisNicFo < BaseWhoisd
end
end
View
69 lib/whois/record/parser/whois.tznic.or.tz.rb
@@ -7,76 +7,23 @@
#++
-require 'whois/record/parser/base'
+require 'whois/record/parser/base_whoisd'
module Whois
class Record
class Parser
- #
- # = whois.tznic.or.tz parser
- #
# Parser for the whois.tznic.or.tz 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.
+ # @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 Whois::Record::Parser::Example
+ # The Example parser for the list of all available methods.
#
- class WhoisTznicOrTz < Base
-
- property_supported :status do
- if content_for_scanner =~ /status:\s+(.+)\n/
- case $1.downcase
- when "paid and in zone"
- :registered
- # NEWSTATUS (redemption?)
- when "expired"
- :expired
- else
- Whois.bug!(ParserError, "Unknown status `#{$1}'.")
- end
- else
- :available
- end
- end
-
- property_supported :available? do
- !!(content_for_scanner =~ /^%ERROR:101: no entries found/)
- end
-
- property_supported :registered? do
- !available?
- end
-
-
- property_supported :created_on do
- if content_for_scanner =~ /registered:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
- property_supported :updated_on do
- if content_for_scanner =~ /changed:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
- property_supported :expires_on do
- if content_for_scanner =~ /expire:\s+(.+?)\n/
- Time.parse($1)
- end
- end
-
-
- property_supported :nameservers do
- content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |name|
- Record::Nameserver.new(:name => name.strip)
- end
- end
-
+ class WhoisTznicOrTz < BaseWhoisd
end
end

0 comments on commit 78cb1db

Please sign in to comment.
Something went wrong with that request. Please try again.