Permalink
Browse files

Whois::Answer#throttle? returns true in case of throttle response. Se…

…e whois.publicinternetregistry.com for a real example (closes #1)
  • Loading branch information...
1 parent 3788bc4 commit 1e3df67b0c3a6ae7498881c022961a564383f43e @weppos committed May 31, 2010
View
@@ -2,6 +2,8 @@
== master
+* NEW: Whois::Answer#throttle? returns true in case of throttle response (see whois.publicinternetregistry.com for a real example)
+
* FIXED: With some .tr domains, whois.nic.tr parser returns inconsistent values for nameservers.
* FIXED: Unexpected token error when trying to parse a .hu whois response. The whois.nic.hu has changed response format.
View
@@ -134,24 +134,34 @@ def property_supported?(property)
# Delegates all method calls to the internal parser.
def method_missing(method, *args, &block)
- if (Parser::PROPERTIES + Parser::METHODS).include?(method)
- self.class.class_eval foo = %{
+ if Parser::PROPERTIES.include?(method)
+ self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args, &block)
if property_supported?(:#{method})
parser.#{method}(*args, &block)
else
nil
end
end
- }, __FILE__, __LINE__
+ RUBY
+ send(method, *args, &block)
+
+ elsif Parser::METHODS.include?(method)
+ self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{method}(*args, &block)
+ if parser.respond_to?(:#{method})
+ parser.#{method}(*args, &block)
+ end
+ end
+ RUBY
send(method, *args, &block)
elsif method.to_s =~ /([a-z_]+)\?/ and (Parser::PROPERTIES + Parser::METHODS).include?($1.to_sym)
- self.class.class_eval %{
+ self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{$1}?
!#{$1}.nil?
end
- }, __FILE__, __LINE__
+ RUBY
send($1)
else
@@ -23,7 +23,7 @@ class Answer
class Parser
METHODS = [
- :contacts,
+ :contacts, :throttle?,
# deprecated methods
:registrant, :admin, :technical,
]
@@ -221,7 +221,9 @@ def property_supported?(property)
end
- # Returns an array of all supported contacts.
+ # Gets all supported contacts merged into a single Array.
+ #
+ # Returns an Array of Whois::Aswer::Contact.
def contacts
contacts = []
contacts.concat(registrant_contact.is_a?(Array) ? registrant_contact : [registrant_contact]) if property_supported?(:registrant_contact)
@@ -230,6 +232,16 @@ def contacts
contacts.compact
end
+ # Checks whether this is a throttle response.
+ # The default implementation always returns false.
+ #
+ # This method is intended to be overrridden by child classes.
+ #
+ # Returns false by default.
+ def throttle?
+ false
+ end
+
# @deprecated {#registrant} is deprecated
# and will be removed in a future version.
@@ -63,6 +63,11 @@ def test_contacts_should_return_all_supported_contacts
end
+ def test_throttle_question
+ assert !@klass.new(@part).throttle?
+ end
+
+
def test_self_property_registry
assert_instance_of Hash, @klass.property_registry
end
@@ -9,12 +9,6 @@ def setup
end
- def test_throttle
- parser = @klass.new(load_part('/throttle.txt'))
- assert parser.throttle?
- end
-
-
def test_disclaimer
parser = @klass.new(load_part('/registered.txt'))
expected = <<-EOS.strip
@@ -281,4 +275,10 @@ def test_nameservers
assert_equal expected, parser.instance_eval { @nameservers }
end
+
+ def test_throttle_question
+ parser = @klass.new(load_part('/throttle.txt'))
+ assert parser.throttle?
+ end
+
end
@@ -95,6 +95,12 @@ def test_contacts
assert_equal [], answer.contacts
end
+ def test_throttle_question
+ answer = @klass.new(@server, @parts)
+ answer.parser.expects(:throttle?).returns(true)
+ assert_equal true, answer.throttle?
+ end
+
def test_parser
answer = @klass.new(nil, [Whois::Answer::Part.new("", "whois.nic.it")])

0 comments on commit 1e3df67

Please sign in to comment.