Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 1e3df67b0c3a6ae7498881c022961a564383f43e 1 parent 3788bc4
@weppos authored
View
2  CHANGELOG.rdoc
@@ -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
20 lib/whois/answer.rb
@@ -134,8 +134,8 @@ 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)
@@ -143,15 +143,25 @@ def #{method}(*args, &block)
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
View
2  lib/whois/answer/parser.rb
@@ -23,7 +23,7 @@ class Answer
class Parser
METHODS = [
- :contacts,
+ :contacts, :throttle?,
# deprecated methods
:registrant, :admin, :technical,
]
View
14 lib/whois/answer/parser/base.rb
@@ -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.
View
5 test/whois/answer/parser/base_test.rb
@@ -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
View
12 test/whois/answer/parser/whois.publicinterestregistry.net_test.rb
@@ -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
View
6 test/whois/answer_test.rb
@@ -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")])
Please sign in to comment.
Something went wrong with that request. Please try again.