Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 165 lines (145 sloc) 4.791 kb
6323474 @weppos Update copyright and docblock.
authored
1 #--
2 # Ruby Whois
be24e73 @weppos Base GEM skeleton.
authored
3 #
578b5fc @weppos No longer a simple client! :)
authored
4 # An intelligent pure Ruby WHOIS client and parser.
be24e73 @weppos Base GEM skeleton.
authored
5 #
4e68eec @weppos Update copyright year
authored
6 # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
be24e73 @weppos Base GEM skeleton.
authored
7 #++
8
9
ad3a5b1 @semaperepelitsa Place "core_ext" under "whois" namespace.
semaperepelitsa authored
10 require 'whois/core_ext'
be24e73 @weppos Base GEM skeleton.
authored
11 require 'whois/version'
0f8cc86 @weppos The class starts to take form. Creates basic server class, added one sim...
authored
12 require 'whois/errors'
afb4065 @weppos Super simple and super buggy initial version. It works, but sometimes it...
authored
13 require 'whois/client'
0f8cc86 @weppos The class starts to take form. Creates basic server class, added one sim...
authored
14 require 'whois/server'
e94d872 @weppos Rename Whois::Answer to Whois::Record
authored
15 require 'whois/record'
be24e73 @weppos Base GEM skeleton.
authored
16
17
0f8cc86 @weppos The class starts to take form. Creates basic server class, added one sim...
authored
18 module Whois
be24e73 @weppos Base GEM skeleton.
authored
19
add6330 @weppos Double quotes
authored
20 NAME = "Whois"
21 GEM = "whois"
22 AUTHORS = ["Simone Carletti <weppos@weppos.net>"]
ce867f8 @weppos Initial support for Whois::Response and Whois parsers (references #281).
authored
23
24
4bb9107 @weppos Make sure a warning is issued when #registered? or #available? returns n...
authored
25 class << self
8598aa6 @weppos Move class methods to the top.
authored
26
27 # Queries the WHOIS server for <tt>qstring</tt> and returns
28 # the response from the server.
29 #
30 # @param [String] qstring The string to be sent as query parameter.
e94d872 @weppos Rename Whois::Answer to Whois::Record
authored
31 # @return [Whois::Record] The record containing the response from the WHOIS server.
8598aa6 @weppos Move class methods to the top.
authored
32 #
33 # @example
34 # Whois.query("google.com")
e94d872 @weppos Rename Whois::Answer to Whois::Record
authored
35 # # => #<Whois::Record>
8598aa6 @weppos Move class methods to the top.
authored
36 #
37 # # Equivalent to
38 # Whois::Client.new.query("google.com")
39 #
40 def query(qstring)
41 Client.new.query(qstring)
42 end
43
4bb9107 @weppos Make sure a warning is issued when #registered? or #available? returns n...
authored
44 alias_method :whois, :query
45
46
8598aa6 @weppos Move class methods to the top.
authored
47 # Checks whether the object represented by <tt>qstring</tt> is available.
48 #
49 # Warning: this method is only available if a Whois parser exists
50 # for the top level domain of <tt>qstring</tt>.
51 # If no parser exists for <tt>qstring</tt>, you'll receive a
52 # warning message and the method will return <tt>nil</tt>.
e94d872 @weppos Rename Whois::Answer to Whois::Record
authored
53 # This is a technical limitation. Browse the lib/whois/record/parsers
8598aa6 @weppos Move class methods to the top.
authored
54 # folder to view all available parsers.
55 #
56 # @param [String] qstring The string to be sent as query parameter.
57 # It is intended to be a domain name, otherwise this method
58 # may return unexpected responses.
59 # @return [Boolean]
60 #
61 # @example
62 # Whois.available?("google.com")
63 # # => false
64 #
65 # @example
66 # Whois.available?("google-is-not-available-try-again-later.com")
67 # # => true
68 #
69 def available?(qstring)
70 result = query(qstring).available?
71 if result.nil?
72 warn "This method is not supported for this kind of object.\n" +
73 "Use Whois.query('#{qstring}') instead."
74 end
75 result
4bb9107 @weppos Make sure a warning is issued when #registered? or #available? returns n...
authored
76 end
ce867f8 @weppos Initial support for Whois::Response and Whois parsers (references #281).
authored
77
8598aa6 @weppos Move class methods to the top.
authored
78 # Checks whether the object represented by <tt>qstring</tt> is registered.
79 #
80 # Warning: this method is only available if a Whois parser exists
81 # for the top level domain of <tt>qstring</tt>.
82 # If no parser exists for <tt>qstring</tt>, you'll receive a warning message
83 # and the method will return <tt>nil</tt>.
e94d872 @weppos Rename Whois::Answer to Whois::Record
authored
84 # This is a technical limitation. Browse the lib/whois/record/parsers folder
8598aa6 @weppos Move class methods to the top.
authored
85 # to view all available parsers.
86 #
87 # @param [String] qstring The string to be sent as query parameter.
88 # It is intended to be a domain name, otherwise this method
89 # may return unexpected responses.
90 # @return [Boolean]
91 #
92 # @example
93 # Whois.registered?("google.com")
94 # # => true
95 #
96 # @example
97 # Whois.registered?("google-is-not-available-try-again-later.com")
98 # # => false
99 #
100 def registered?(qstring)
101 result = query(qstring).registered?
102 if result.nil?
103 warn "This method is not supported for this kind of object.\n" +
104 "Use Whois.query('#{qstring}') instead."
105 end
106 result
4bb9107 @weppos Make sure a warning is issued when #registered? or #available? returns n...
authored
107 end
58726ad @weppos Documented main Whois file.
authored
108
623ee51 @weppos Moved Whois#deprecate to main Whois file.
authored
109
8598aa6 @weppos Move class methods to the top.
authored
110 # Echoes a deprecation warning message.
111 #
112 # @param [String] message The message to display.
113 # @return [void]
114 #
115 # @api internal
116 # @private
dcee304 @weppos Introduce deprecation backtrace
authored
117 def deprecate(message = nil, callstack = caller)
8598aa6 @weppos Move class methods to the top.
authored
118 message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
dcee304 @weppos Introduce deprecation backtrace
authored
119 # warn("DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}")
8598aa6 @weppos Move class methods to the top.
authored
120 warn("DEPRECATION WARNING: #{message}")
121 end
122
123 # Appends <em>Please report issue to</em> to the message
e033c5c @weppos Bad char
authored
124 # and raises a new +error+ with the final message.
8598aa6 @weppos Move class methods to the top.
authored
125 #
126 # @param [Exception] error
127 # @param [String] message
128 # @return [void]
129 #
130 # @api internal
131 # @private
132 def bug!(error, message)
133 raise error, message.dup <<
134 " Please report the issue at" <<
135 " http://github.com/weppos/whois/issues"
136 end
623ee51 @weppos Moved Whois#deprecate to main Whois file.
authored
137
dcee304 @weppos Introduce deprecation backtrace
authored
138 private
139
140 def deprecation_caller_message(callstack)
141 file, line, method = extract_callstack(callstack)
142 if file
143 if line && method
144 "(called from #{method} at #{file}:#{line})"
145 else
146 "(called from #{file}:#{line})"
147 end
148 end
149 end
150
151 def extract_callstack(callstack)
152 gem_root = File.expand_path("../../../", __FILE__) + "/"
153 offending_line = callstack.find { |line| !line.start_with?(gem_root) } || callstack.first
154 if offending_line
155 if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
156 md.captures
157 else
158 offending_line
159 end
160 end
161 end
37e931c @weppos Compatibility with the new whois.cira.ca record schema.
authored
162 end
163
dd7fc7c @weppos RDoc/TomDoc updates.
authored
164 end
Something went wrong with that request. Please try again.