Permalink
Browse files

Renamed `query` method into `request` and wrapped request call into q…

…uery so that the call can be easily mock, tested and extended.

The response can now be intercepted before sending back the value to the called, in this way the response can be parsed or normalized.
  • Loading branch information...
1 parent 6d0b49f commit 9662cd2b3f62f27e2ba9e2f47dadd7d44a7c6402 @weppos committed Jul 22, 2009
@@ -20,7 +20,7 @@ module Adapters
class Afilias < Base
- def query(qstring)
+ def request(qstring)
response = ask_the_socket(qstring, "whois.afilias-grs.info", DEFAULT_WHOIS_PORT)
if response =~ /Domain Name:/ && response =~ /Whois Server:(\S+)/
ask_the_socket(qstring, $1, DEFAULT_WHOIS_PORT)
@@ -20,7 +20,7 @@ module Adapters
class Arpa < Base
- def query(qstring)
+ def request(qstring)
Server.guess(inaddr_to_ip(qstring)).query(qstring)
end
@@ -34,9 +34,13 @@ def initialize(extension, server, options = {})
end
def query(qstring)
+ request(qstring)
+ end
+
+ def request(qstring)
raise NotImplementedError
end
-
+
protected
@@ -20,7 +20,7 @@ module Adapters
class Formatted < Base
- def query(qstring)
+ def request(qstring)
query_the_socket(sprintf(options[:format], qstring), server)
end
@@ -20,7 +20,7 @@ module Adapters
class None < Base
- def query(qstring)
+ def request(qstring)
raise NoInterfaceError, "This TLD has no whois server"
end
@@ -20,7 +20,7 @@ module Adapters
class Pir < Base
- def query(qstring)
+ def request(qstring)
response = ask_the_socket("FULL #{qstring}", "whois.publicinterestregistry.net", DEFAULT_WHOIS_PORT)
if response =~ /Registrant Name:SEE SPONSORING REGISTRAR/ &&
response =~ /Registrant Street1:Whois Server:(\S+)/
@@ -20,7 +20,7 @@ module Adapters
class Standard < Base
- def query(qstring)
+ def request(qstring)
query_the_socket(qstring, server)
end
@@ -20,7 +20,7 @@ module Adapters
class Verisign < Base
- def query(qstring)
+ def request(qstring)
response = ask_the_socket("=#{qstring}", "whois.crsnic.net", DEFAULT_WHOIS_PORT)
if response =~ /Domain Name:/ && response =~ /Whois Server: (\S+)/
ask_the_socket(qstring, $1, DEFAULT_WHOIS_PORT)
@@ -20,7 +20,7 @@ module Adapters
class Web < Base
- def query(qstring)
+ def request(qstring)
raise WebInterfaceError, "This TLD has no whois server, " +
"but you can access the whois database at `#{options[:web]}'"
end

0 comments on commit 9662cd2

Please sign in to comment.