Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Deprecate Whois::Client#query

  • Loading branch information...
commit 987fc7de1152d6f4667e5cedf4152a6cf44d9823 1 parent bf8d00b
@weppos authored
View
2  CHANGELOG.md
@@ -87,6 +87,8 @@
- CHANGED: Definitions are now stored as JSON.
+- CHANGED: Deprecate Whois::Client#query in favor of Whois::Client#lookup
+
- FIXED: whois.domainregistry.ie should support status `Active - LOCKED`.
- FIXED: whois.nic.uk fails to parse registrars without URL (GH-188).
View
32 README.md
@@ -62,46 +62,46 @@ Check out the following examples:
# Domain WHOIS
w = Whois::Client.new
- w.query("google.com")
+ w.lookup("google.com")
# => #<Whois::Record>
# TLD WHOIS
w = Whois::Client.new
- w.query(".com")
+ w.lookup(".com")
# => #<Whois::Record>
# IPv4 WHOIS
w = Whois::Client.new
- w.query("74.125.67.100")
+ w.lookup("74.125.67.100")
# => #<Whois::Record>
# IPv6 WHOIS
w = Whois::Client.new
- w.query("2001:db8::1428:57ab")
+ w.lookup("2001:db8::1428:57ab")
# => #<Whois::Record>
The query method is stateless. For this reason, you can safely re-use the same client instance for multiple queries.
w = Whois::Client.new
- w.query("google.com")
- w.query(".com")
- w.query("74.125.67.100")
- w.query("2001:db8::1428:57ab")
- w.query("google.it")
+ w.lookup("google.com")
+ w.lookup(".com")
+ w.lookup("74.125.67.100")
+ w.lookup("2001:db8::1428:57ab")
+ w.lookup("google.it")
If you just need a WHOIS response and you don't care about a full control of the WHOIS client, the {Whois} module provides an all-in-one method called {Whois.whois}. This is the simplest way to send a WHOIS request.
- Whois.whois("google.com")
+ Whois.lookup("google.com")
# => #<Whois::Record>
Did I mention you can even use blocks?
Whois::Client.new do |w|
- w.query("google.com")
- w.query(".com")
- w.query("74.125.67.100")
- w.query("2001:db8::1428:57ab")
- w.query("google.it")
+ w.lookup("google.com")
+ w.lookup(".com")
+ w.lookup("74.125.67.100")
+ w.lookup("2001:db8::1428:57ab")
+ w.lookup("google.it")
end
### Consuming the Record
@@ -147,7 +147,7 @@ Off course, you can customize the timeout value setting a different value. If ti
w.timeout = 5
w.timeout # => 5
- w.query("google.com")
+ w.lookup("google.com")
## Acknowledgments
View
2  lib/whois.rb
@@ -38,7 +38,7 @@ class << self
# Whois::Client.new.query("google.com")
#
def query(object)
- Client.new.query(object)
+ Client.new.lookup(object)
end
alias_method :whois, :query
View
14 lib/whois/client.rb
@@ -73,20 +73,20 @@ def initialize(settings = {})
end
- # Queries the right WHOIS server for <tt>object</tt>
+ # Lookups the right WHOIS server for <tt>object</tt>
# and returns the response from the server.
#
- # @param [#to_s] object The string to be sent as query parameter.
+ # @param [#to_s] object The string to be sent as lookup parameter.
# @return [Whois::Record] The object containing the WHOIS response.
#
# @raise [Timeout::Error]
#
# @example
#
- # client.query("google.com")
+ # client.lookup("google.com")
# # => #<Whois::Record>
#
- def query(object)
+ def lookup(object)
string = object.to_s.downcase
Timeout::timeout(timeout) do
@server = Server.guess(string)
@@ -95,6 +95,12 @@ def query(object)
end
end
+ # @deprecated
+ def query(*args)
+ Whois.deprecate("Client#query is deprecated, use Client#lookup instead.")
+ lookup(*args)
+ end
+
end
end
View
6 spec/integration_spec.rb
@@ -35,7 +35,7 @@
returns(response)
client = Whois::Client.new(:bind_host => "192.168.1.1", :bind_port => 3000)
- client.query("example.it")
+ client.lookup("example.it")
end
end
end
@@ -50,7 +50,7 @@
returns(response)
client = Whois::Client.new(:bind_port => 3000)
- client.query("example.it")
+ client.lookup("example.it")
end
end
end
@@ -65,7 +65,7 @@
returns(response)
client = Whois::Client.new(:host => "whois.example.com")
- record = client.query("example.it")
+ record = client.lookup("example.it")
record.parts.size.should == 1
record.parts.first.body.should == response
record.parts.first.host.should == "whois.example.com"
View
20 spec/whois/client_spec.rb
@@ -40,7 +40,7 @@
end
end
- describe "#query" do
+ describe "#lookup" do
it "converts the argument to string" do
query = ["example", ".", "test"]
query.instance_eval do
@@ -53,7 +53,7 @@ def to_s
server.expects(:lookup).with("example.test")
Whois::Server.expects(:guess).with("example.test").returns(server)
- klass.new.query(query)
+ klass.new.lookup(query)
end
it "converts the argument to downcase" do
@@ -61,12 +61,12 @@ def to_s
server.expects(:lookup).with("example.test")
Whois::Server.expects(:guess).with("example.test").returns(server)
- klass.new.query("Example.TEST")
+ klass.new.lookup("Example.TEST")
end
it "detects email" do
expect {
- klass.new.query("weppos@weppos.net")
+ klass.new.lookup("weppos@weppos.net")
}.to raise_error(Whois::ServerNotSupported)
end
@@ -74,7 +74,7 @@ def to_s
Whois::Server.define(:tld, ".nowhois", nil, :adapter => Whois::Server::Adapters::None)
expect {
- klass.new.query("domain.nowhois")
+ klass.new.lookup("domain.nowhois")
}.to raise_error(Whois::NoInterfaceError, /no whois server/)
end
@@ -82,7 +82,7 @@ def to_s
Whois::Server.define(:tld, ".webwhois", nil, :adapter => Whois::Server::Adapters::Web, :url => "http://www.example.com/")
expect {
- klass.new.query("domain.webwhois")
+ klass.new.lookup("domain.webwhois")
}.to raise_error(Whois::WebInterfaceError, /www\.example\.com/)
end
@@ -96,7 +96,7 @@ def lookup(*)
client = klass.new(:timeout => 1)
expect {
- client.query("example.test")
+ client.lookup("example.test")
}.to raise_error(Timeout::Error)
end
@@ -110,7 +110,7 @@ def lookup(*)
client = klass.new(:timeout => 5)
expect {
- client.query("example.test")
+ client.lookup("example.test")
}.to_not raise_error
end
@@ -124,7 +124,7 @@ def lookup(*)
client = klass.new.tap { |c| c.timeout = nil }
expect {
- client.query("example.test")
+ client.lookup("example.test")
}.to_not raise_error
end
@@ -134,7 +134,7 @@ def lookup(*)
need_connectivity do
describe "#query" do
it "sends a query for given domain" do
- record = klass.new.query("weppos.it")
+ record = klass.new.lookup("weppos.it")
assert record.match?(/Domain:\s+weppos\.it/)
assert record.match?(/Created:/)
end
Please sign in to comment.
Something went wrong with that request. Please try again.