Permalink
Browse files

Added ability to check for an unavailable response.

  • Loading branch information...
1 parent 2cc4809 commit c33b0e8ac5299253589e7aca50861dfe4acccde6 @weppos committed Feb 17, 2012
View
@@ -7,6 +7,8 @@
* NEW: Added full whois.dreamhost.com parser.
+* NEW: Added ability to check for an unavailable response with Whois::Record#response_unavailable?.
+
* FIXED: whois.nic.gl parser must support `Delegate' status.
* FIXED: whois.godaddy.com partially changed response format (GH-148).
View
@@ -255,6 +255,16 @@ def unchanged?(other)
end
+ # Checks whether this is an incomplete response.
+ #
+ # @return [Boolean]
+ #
+ # @see Whois::Record::Parser#response_incomplete?
+ #
+ def response_incomplete?
+ parser.response_incomplete?
+ end
+
# Checks whether this is a throttle response.
#
# @return [Boolean]
@@ -265,14 +275,14 @@ def response_throttled?
parser.response_throttled?
end
- # Checks whether this is an incomplete response.
+ # Checks whether this is an unavailable response.
#
# @return [Boolean]
#
- # @see Whois::Record::Parser#response_incomplete?
+ # @see Whois::Record::Parser#response_unavailable?
#
- def response_incomplete?
- parser.response_incomplete?
+ def response_unavailable?
+ parser.response_unavailable?
end
# @endgroup
View
@@ -223,6 +223,18 @@ def unchanged?(other)
parsers.size == other.parsers.size && all_in_parallel?(parsers, other.parsers) { |one, two| one.unchanged?(two) }
end
+ # Loop through all the parts to check if at least
+ # one part is an incomplete response.
+ #
+ # @return [Boolean]
+ #
+ # @see Whois::Record#response_incomplete?
+ # @see Whois::Record::Parser::Base#response_incomplete?
+ #
+ def response_incomplete?
+ any_is?(parsers, :response_incomplete?)
+ end
+
# Loop through all the parts to check if at least
# one part is a throttle response.
#
@@ -236,15 +248,15 @@ def response_throttled?
end
# Loop through all the parts to check if at least
- # one part is an incomplete response.
+ # one part is an unavailable response.
#
# @return [Boolean]
#
- # @see Whois::Record#response_incomplete?
- # @see Whois::Record::Parser::Base#response_incomplete?
+ # @see Whois::Record#response_unavailable?
+ # @see Whois::Record::Parser::Base#response_unavailable?
#
- def response_incomplete?
- any_is?(parsers, :response_incomplete?)
+ def response_unavailable?
+ any_is?(parsers, :response_unavailable?)
end
# @endgroup
@@ -299,30 +299,30 @@ def unchanged?(other)
content_for_scanner == other.content_for_scanner
end
- # Checks whether this is a throttle response.
+ # Checks whether this is an incomplete response.
#
# @return [Boolean]
#
# @abstract This method is just a stub.
# Define it in your parser class.
#
- # @see Whois::Record#response_throttled?
- # @see Whois::Record::Parser#response_throttled?
+ # @see Whois::Record#response_incomplete?
+ # @see Whois::Record::Parser#response_incomplete?
#
- def response_throttled?
+ def response_incomplete?
end
- # Checks whether this is an incomplete response.
+ # Checks whether this is a throttle response.
#
# @return [Boolean]
#
# @abstract This method is just a stub.
# Define it in your parser class.
#
- # @see Whois::Record#response_incomplete?
- # @see Whois::Record::Parser#response_incomplete?
+ # @see Whois::Record#response_throttled?
+ # @see Whois::Record::Parser#response_throttled?
#
- def response_incomplete?
+ def response_throttled?
end
# Checks whether this response contains a message
@@ -336,6 +336,9 @@ def response_incomplete?
# @abstract This method is just a stub.
# Define it in your parser class.
#
+ # @see Whois::Record#response_unavailable?
+ # @see Whois::Record::Parser#response_unavailable?
+ #
def response_unavailable?
end
@@ -158,35 +158,35 @@
end
- describe "#response_throttled?" do
+ describe "#response_incomplete?" do
it "is undefined" do
- klass.new(@part).respond_to?(:response_throttled?).should be_false
+ klass.new(@part).respond_to?(:response_incomplete?).should be_false
end
# it "returns nil" do
# i = klass.new(@part)
- # i.response_throttled?.should be_nil
+ # i.response_incomplete?.should be_nil
# end
#
# it "is false" do
# i = klass.new(@part)
- # i.response_throttled?.should be_false
+ # i.response_incomplete?.should be_false
# end
end
- describe "#response_incomplete?" do
+ describe "#response_throttled?" do
it "is undefined" do
- klass.new(@part).respond_to?(:response_incomplete?).should be_false
+ klass.new(@part).respond_to?(:response_throttled?).should be_false
end
# it "returns nil" do
# i = klass.new(@part)
- # i.response_incomplete?.should be_nil
+ # i.response_throttled?.should be_nil
# end
#
# it "is false" do
# i = klass.new(@part)
- # i.response_incomplete?.should be_false
+ # i.response_throttled?.should be_false
# end
end
@@ -295,6 +295,21 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
end
end
+ describe "#response_incomplete?" do
+ it "returns false when all parts are complete" do
+ i = parsers("defined-false", "defined-false")
+ i.response_incomplete?.should == false
+ end
+
+ it "returns true when at least one part is incomplete" do
+ i = parsers("defined-false", "defined-true")
+ i.response_incomplete?.should == true
+
+ i = parsers("defined-true", "defined-false")
+ i.response_incomplete?.should == true
+ end
+ end
+
describe "#response_throttled?" do
it "returns false when all parts are not throttled" do
i = parsers("defined-false", "defined-false")
@@ -310,47 +325,53 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
end
end
- describe "#response_incomplete?" do
- it "returns false when all parts are complete" do
+ describe "#response_unavailable?" do
+ it "returns false when all parts are available" do
i = parsers("defined-false", "defined-false")
- i.response_incomplete?.should == false
+ i.response_unavailable?.should == false
end
- it "returns true when at least one part is incomplete" do
+ it "returns true when at least one part is unavailable" do
i = parsers("defined-false", "defined-true")
- i.response_incomplete?.should == true
+ i.response_unavailable?.should == true
i = parsers("defined-true", "defined-false")
- i.response_incomplete?.should == true
+ i.response_unavailable?.should == true
end
end
private
- class Whois::Record::Parser::ResponseDefinedTrueTest < Whois::Record::Parser::Base
- def response_throttled?
- true
- end
- def response_incomplete?
- true
- end
+ class Whois::Record::Parser::ResponseDefinedTrueTest < Whois::Record::Parser::Base
+ def response_incomplete?
+ true
end
-
- class Whois::Record::Parser::ResponseDefinedFalseTest < Whois::Record::Parser::Base
- def response_throttled?
- false
- end
- def response_incomplete?
- false
- end
+ def response_throttled?
+ true
end
-
- class Whois::Record::Parser::ResponseUndefinedTest < Whois::Record::Parser::Base
+ def response_unavailable?
+ true
end
+ end
- def parsers(*types)
- klass.new(Whois::Record.new(nil, types.map { |type| Whois::Record::Part.new("", "response-#{type}.test") }))
+ class Whois::Record::Parser::ResponseDefinedFalseTest < Whois::Record::Parser::Base
+ def response_incomplete?
+ false
+ end
+ def response_throttled?
+ false
end
+ def response_unavailable?
+ false
+ end
+ end
+
+ class Whois::Record::Parser::ResponseUndefinedTest < Whois::Record::Parser::Base
+ end
+
+ def parsers(*types)
+ klass.new(Whois::Record.new(nil, types.map { |type| Whois::Record::Part.new("", "response-#{type}.test") }))
+ end
end
View
@@ -305,6 +305,14 @@ class Whois::Record::Parser::WhoisPropertiesTest < Whois::Record::Parser::Base
end
+ describe "#response_incomplete?" do
+ it "delegates to #parser" do
+ i = klass.new(nil, [])
+ i.parser.expects(:response_incomplete?)
+ i.response_incomplete?
+ end
+ end
+
describe "#response_throttled?" do
it "delegates to #parser" do
i = klass.new(nil, [])
@@ -313,11 +321,11 @@ class Whois::Record::Parser::WhoisPropertiesTest < Whois::Record::Parser::Base
end
end
- describe "#response_incomplete?" do
+ describe "#response_unavailable?" do
it "delegates to #parser" do
i = klass.new(nil, [])
- i.parser.expects(:response_incomplete?)
- i.response_incomplete?
+ i.parser.expects(:response_unavailable?)
+ i.response_unavailable?
end
end

0 comments on commit c33b0e8

Please sign in to comment.