whois 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (262) hide show
  1. data/CHANGELOG.rdoc +161 -21
  2. data/LICENSE.rdoc +1 -1
  3. data/Manifest +184 -13
  4. data/README.rdoc +24 -31
  5. data/Rakefile +7 -7
  6. data/bin/ruby-whois +9 -3
  7. data/data/ip_del_list +2 -0
  8. data/data/make_servers_charset.pl +21 -0
  9. data/data/make_tld_serv.pl +8 -7
  10. data/data/servers_charset_list +37 -0
  11. data/data/tld_serv_list +32 -30
  12. data/lib/whois.rb +0 -1
  13. data/lib/whois/answer.rb +24 -13
  14. data/lib/whois/answer/parser.rb +27 -16
  15. data/lib/whois/answer/parser/NOTES.txt +3 -0
  16. data/lib/whois/answer/parser/base.rb +140 -101
  17. data/lib/whois/answer/parser/jobswhois.verisign-grs.com.rb +99 -0
  18. data/lib/whois/answer/parser/whois.adamsnames.tc.rb +64 -0
  19. data/lib/whois/answer/parser/whois.aeda.net.ae.rb +65 -0
  20. data/lib/whois/answer/parser/whois.aero.rb +6 -6
  21. data/lib/whois/answer/parser/whois.afilias-grs.info.rb +6 -6
  22. data/lib/whois/answer/parser/whois.afilias.info.rb +12 -12
  23. data/lib/whois/answer/parser/whois.biz.rb +72 -0
  24. data/lib/whois/answer/parser/whois.cat.rb +74 -0
  25. data/lib/whois/answer/parser/whois.cira.ca.rb +77 -0
  26. data/lib/whois/answer/parser/whois.crsnic.net.rb +16 -13
  27. data/lib/whois/answer/parser/whois.denic.de.rb +14 -18
  28. data/lib/whois/answer/parser/whois.dk-hostmaster.dk.rb +75 -0
  29. data/lib/whois/answer/parser/whois.domain-registry.nl.rb +72 -0
  30. data/lib/whois/answer/parser/whois.domainregistry.ie.rb +7 -13
  31. data/lib/whois/answer/parser/whois.dotmobiregistry.net.rb +72 -0
  32. data/lib/whois/answer/parser/whois.educause.edu.rb +8 -8
  33. data/lib/whois/answer/parser/whois.eu.org.rb +8 -17
  34. data/lib/whois/answer/parser/whois.eu.rb +64 -0
  35. data/lib/whois/answer/parser/whois.iana.org.rb +6 -9
  36. data/lib/whois/answer/parser/whois.isnic.is.rb +72 -0
  37. data/lib/whois/answer/parser/whois.meregistry.net.rb +72 -0
  38. data/lib/whois/answer/parser/whois.museum.rb +76 -0
  39. data/lib/whois/answer/parser/whois.nic-se.se.rb +77 -0
  40. data/lib/whois/answer/parser/whois.nic.ac.rb +92 -0
  41. data/lib/whois/answer/parser/whois.nic.asia.rb +12 -12
  42. data/lib/whois/answer/parser/whois.nic.cc.rb +99 -0
  43. data/lib/whois/answer/parser/whois.nic.cd.rb +68 -0
  44. data/lib/whois/answer/parser/whois.nic.ch.rb +64 -0
  45. data/lib/whois/answer/parser/whois.nic.coop.rb +74 -0
  46. data/lib/whois/answer/parser/whois.nic.fr.rb +8 -11
  47. data/lib/whois/answer/parser/whois.nic.gl.rb +77 -0
  48. data/lib/whois/answer/parser/whois.nic.gov.rb +8 -17
  49. data/lib/whois/answer/parser/whois.nic.hu.rb +21 -19
  50. data/lib/whois/answer/parser/whois.nic.im.rb +68 -0
  51. data/lib/whois/answer/parser/whois.nic.io.rb +64 -0
  52. data/lib/whois/answer/parser/whois.nic.it.rb +16 -16
  53. data/lib/whois/answer/parser/whois.nic.ly.rb +76 -0
  54. data/lib/whois/answer/parser/whois.nic.mu.rb +77 -0
  55. data/lib/whois/answer/parser/whois.nic.name.rb +8 -17
  56. data/lib/whois/answer/parser/whois.nic.nu.rb +84 -0
  57. data/lib/whois/answer/parser/whois.nic.tel.rb +76 -0
  58. data/lib/whois/answer/parser/whois.nic.tl.rb +76 -0
  59. data/lib/whois/answer/parser/whois.nic.travel.rb +72 -0
  60. data/lib/whois/answer/parser/whois.nic.tv.rb +16 -13
  61. data/lib/whois/answer/parser/whois.nic.uk.rb +82 -0
  62. data/lib/whois/answer/parser/whois.nic.us.rb +72 -0
  63. data/lib/whois/answer/parser/whois.norid.no.rb +72 -0
  64. data/lib/whois/answer/parser/whois.publicinterestregistry.net.rb +16 -16
  65. data/lib/whois/answer/parser/whois.register.bg.rb +74 -0
  66. data/lib/whois/answer/parser/whois.registro.br.rb +64 -0
  67. data/lib/whois/answer/parser/whois.registrypro.pro.rb +77 -0
  68. data/lib/whois/answer/parser/whois.ripe.net.rb +64 -0
  69. data/lib/whois/answer/parser/whois.ripn.net.rb +72 -0
  70. data/lib/whois/answer/parser/whois.rotld.ro.rb +64 -0
  71. data/lib/whois/answer/parser/whois.samoanic.ws.rb +76 -0
  72. data/lib/whois/answer/parser/whois.za.net.rb +8 -11
  73. data/lib/whois/answer/parser/whois.za.org.rb +7 -10
  74. data/lib/whois/answer/super_struct.rb +1 -1
  75. data/lib/whois/client.rb +4 -4
  76. data/lib/whois/definitions/NOTES.txt +12 -0
  77. data/lib/whois/definitions/ipv4.rb +2 -0
  78. data/lib/whois/definitions/tlds.rb +27 -27
  79. data/lib/whois/errors.rb +11 -1
  80. data/lib/whois/server.rb +1 -0
  81. data/lib/whois/server/adapters/web.rb +1 -2
  82. data/lib/whois/version.rb +4 -4
  83. data/test/answer/parser/base_test.rb +16 -29
  84. data/test/answer/parser/jobswhois.verisign-grs.com_test.rb +122 -0
  85. data/test/answer/parser/whois.adamsnames.tc_test.rb +122 -0
  86. data/test/answer/parser/whois.aeda.net.ae_test.rb +63 -0
  87. data/test/answer/parser/whois.afilias-grs.info_test.rb +274 -13
  88. data/test/answer/parser/whois.afilias.info_test.rb +1 -1
  89. data/test/answer/parser/whois.biz_test.rb +51 -0
  90. data/test/answer/parser/whois.cat_test.rb +51 -0
  91. data/test/answer/parser/whois.cira.ca_test.rb +51 -0
  92. data/test/answer/parser/whois.crsnic.net_test.rb +8 -3
  93. data/test/answer/parser/whois.denic.de_test.rb +11 -18
  94. data/test/answer/parser/whois.dk-hostmaster.dk_test.rb +57 -0
  95. data/test/answer/parser/whois.domain-registry.nl_test.rb +49 -0
  96. data/test/answer/parser/whois.domainregistry.ie_test.rb +7 -11
  97. data/test/answer/parser/whois.dotmobiregistry.net_test.rb +51 -0
  98. data/test/answer/parser/whois.educause.edu_test.rb +3 -3
  99. data/test/answer/parser/whois.eu.org_test.rb +6 -12
  100. data/test/answer/parser/whois.eu_test.rb +45 -0
  101. data/test/answer/parser/whois.iana.org_test.rb +2 -4
  102. data/test/answer/parser/whois.isnic.is_test.rb +49 -0
  103. data/test/answer/parser/whois.meregistry.net_test.rb +51 -0
  104. data/test/answer/parser/whois.museum_test.rb +51 -0
  105. data/test/answer/parser/whois.nic-se.se_test.rb +58 -0
  106. data/test/answer/parser/whois.nic.ac_test.rb +126 -0
  107. data/test/answer/parser/whois.nic.asia_test.rb +1 -1
  108. data/test/answer/parser/whois.nic.cc_test.rb +122 -0
  109. data/test/answer/parser/whois.nic.cd_test.rb +49 -0
  110. data/test/answer/parser/whois.nic.ch_test.rb +45 -0
  111. data/test/answer/parser/whois.nic.coop_test.rb +51 -0
  112. data/test/answer/parser/whois.nic.fr_test.rb +178 -13
  113. data/test/answer/parser/whois.nic.gl_test.rb +51 -0
  114. data/test/answer/parser/whois.nic.gov_test.rb +6 -12
  115. data/test/answer/parser/whois.nic.hu_test.rb +9 -7
  116. data/test/answer/parser/whois.nic.im_test.rb +47 -0
  117. data/test/answer/parser/whois.nic.io_test.rb +45 -0
  118. data/test/answer/parser/whois.nic.it_test.rb +6 -3
  119. data/test/answer/parser/whois.nic.ly_test.rb +51 -0
  120. data/test/answer/parser/whois.nic.mu_test.rb +97 -0
  121. data/test/answer/parser/whois.nic.name_test.rb +6 -12
  122. data/test/answer/parser/whois.nic.nu_test.rb +59 -0
  123. data/test/answer/parser/whois.nic.tel_test.rb +51 -0
  124. data/test/answer/parser/whois.nic.tl_test.rb +51 -0
  125. data/test/answer/parser/whois.nic.travel_test.rb +51 -0
  126. data/test/answer/parser/whois.nic.tv_test.rb +9 -5
  127. data/test/answer/parser/whois.nic.uk_test.rb +63 -0
  128. data/test/answer/parser/whois.nic.us_test.rb +51 -0
  129. data/test/answer/parser/whois.norid.no_test.rb +49 -0
  130. data/test/answer/parser/whois.register.bg_test.rb +49 -0
  131. data/test/answer/parser/whois.registro.br_test.rb +45 -0
  132. data/test/answer/parser/whois.registrypro.pro_test.rb +84 -0
  133. data/test/answer/parser/whois.ripe.net_test.rb +203 -0
  134. data/test/answer/parser/whois.ripn.net_test.rb +94 -0
  135. data/test/answer/parser/whois.rotld.ro_test.rb +45 -0
  136. data/test/answer/parser/whois.samoanic.ws_test.rb +51 -0
  137. data/test/answer/parser/whois.za.net_test.rb +2 -4
  138. data/test/answer/parser/whois.za.org_test.rb +2 -4
  139. data/test/answer/parser_test.rb +71 -48
  140. data/test/answer_test.rb +57 -21
  141. data/test/client_test.rb +5 -2
  142. data/test/errors_test.rb +23 -0
  143. data/test/list_tld +74 -76
  144. data/test/testcases/responses/jobswhois.verisign-grs.com/available.txt +44 -0
  145. data/test/testcases/responses/jobswhois.verisign-grs.com/registered.txt +54 -0
  146. data/test/testcases/responses/super_struct_test.rb +3 -4
  147. data/test/testcases/responses/whois.adamsnames.tc/gd/available.txt +2 -0
  148. data/test/testcases/responses/whois.adamsnames.tc/gd/registered.txt +26 -0
  149. data/test/testcases/responses/whois.adamsnames.tc/tc/available.txt +2 -0
  150. data/test/testcases/responses/whois.adamsnames.tc/tc/registered.txt +28 -0
  151. data/test/testcases/responses/whois.adamsnames.tc/vg/available.txt +2 -0
  152. data/test/testcases/responses/whois.adamsnames.tc/vg/registered.txt +28 -0
  153. data/test/testcases/responses/whois.aeda.net.ae/available.txt +1 -0
  154. data/test/testcases/responses/whois.aeda.net.ae/registered.txt +15 -0
  155. data/test/testcases/responses/whois.biz/available.txt +25 -0
  156. data/test/testcases/responses/whois.biz/registered.txt +89 -0
  157. data/test/testcases/responses/whois.cat/available.txt +18 -0
  158. data/test/testcases/responses/whois.cat/registered.txt +83 -0
  159. data/test/testcases/responses/whois.cira.ca/available.txt +9 -0
  160. data/test/testcases/responses/whois.cira.ca/registered.txt +47 -0
  161. data/test/testcases/responses/whois.dk-hostmaster.dk/available.txt +15 -0
  162. data/test/testcases/responses/whois.dk-hostmaster.dk/registered.txt +47 -0
  163. data/test/testcases/responses/whois.domain-registry.nl/available.txt +21 -0
  164. data/test/testcases/responses/whois.domain-registry.nl/registered.txt +67 -0
  165. data/test/testcases/responses/whois.dotmobiregistry.net/available.txt +25 -0
  166. data/test/testcases/responses/whois.dotmobiregistry.net/registered.txt +81 -0
  167. data/test/testcases/responses/whois.eu/available.txt +47 -0
  168. data/test/testcases/responses/whois.eu/registered.txt +63 -0
  169. data/test/testcases/responses/whois.isnic.is/available.txt +7 -0
  170. data/test/testcases/responses/whois.isnic.is/registered.txt +57 -0
  171. data/test/testcases/responses/{whois.afilias-grs.info → whois.meregistry.net}/available.txt +0 -0
  172. data/test/testcases/responses/whois.meregistry.net/registered.txt +94 -0
  173. data/test/testcases/responses/whois.museum/available.txt +18 -0
  174. data/test/testcases/responses/whois.museum/registered.txt +92 -0
  175. data/test/testcases/responses/whois.nic-se.se/available.txt +21 -0
  176. data/test/testcases/responses/whois.nic-se.se/registered.txt +37 -0
  177. data/test/testcases/responses/whois.nic.ac/available.txt +2 -0
  178. data/test/testcases/responses/whois.nic.ac/registered.txt +2 -0
  179. data/test/testcases/responses/whois.nic.cc/available.txt +44 -0
  180. data/test/testcases/responses/whois.nic.cc/registered.txt +58 -0
  181. data/test/testcases/responses/whois.nic.cd/available.txt +1 -0
  182. data/test/testcases/responses/whois.nic.cd/registered.txt +85 -0
  183. data/test/testcases/responses/whois.nic.ch/available.txt +2 -0
  184. data/test/testcases/responses/whois.nic.ch/registered.txt +28 -0
  185. data/test/testcases/responses/whois.nic.coop/available.txt +33 -0
  186. data/test/testcases/responses/whois.nic.coop/registered.txt +123 -0
  187. data/test/testcases/responses/whois.nic.fr/{available.txt → fr/available.txt} +0 -0
  188. data/test/testcases/responses/whois.nic.fr/{registered.txt → fr/registered.txt} +0 -0
  189. data/test/testcases/responses/whois.nic.fr/pm/available.txt +19 -0
  190. data/test/testcases/responses/whois.nic.fr/pm/registered.txt +88 -0
  191. data/test/testcases/responses/whois.nic.fr/re/available.txt +19 -0
  192. data/test/testcases/responses/whois.nic.fr/re/registered.txt +83 -0
  193. data/test/testcases/responses/whois.nic.fr/wf/available.txt +19 -0
  194. data/test/testcases/responses/whois.nic.fr/wf/registered.txt +88 -0
  195. data/test/testcases/responses/whois.nic.fr/yt/available.txt +19 -0
  196. data/test/testcases/responses/whois.nic.fr/yt/registered.txt +88 -0
  197. data/test/testcases/responses/whois.nic.gl/available.txt +23 -0
  198. data/test/testcases/responses/whois.nic.gl/registered.txt +40 -0
  199. data/test/testcases/responses/whois.nic.hu/available.txt +5 -5
  200. data/test/testcases/responses/whois.nic.hu/in_progress.txt +5 -5
  201. data/test/testcases/responses/whois.nic.hu/registered.txt +6 -6
  202. data/test/testcases/responses/whois.nic.im/available.txt +2 -0
  203. data/test/testcases/responses/whois.nic.im/registered.txt +45 -0
  204. data/test/testcases/responses/whois.nic.io/available.txt +2 -0
  205. data/test/testcases/responses/whois.nic.io/registered.txt +2 -0
  206. data/test/testcases/responses/whois.nic.ly/available.txt +1 -0
  207. data/test/testcases/responses/whois.nic.ly/registered.txt +65 -0
  208. data/test/testcases/responses/whois.nic.mu/ki/available.txt +20 -0
  209. data/test/testcases/responses/whois.nic.mu/ki/registered.txt +30 -0
  210. data/test/testcases/responses/whois.nic.mu/mu/available.txt +9 -0
  211. data/test/testcases/responses/whois.nic.mu/mu/registered.txt +22 -0
  212. data/test/testcases/responses/whois.nic.nu/available.txt +19 -0
  213. data/test/testcases/responses/whois.nic.nu/registered.txt +35 -0
  214. data/test/testcases/responses/whois.nic.tel/available.txt +59 -0
  215. data/test/testcases/responses/whois.nic.tel/registered.txt +111 -0
  216. data/test/testcases/responses/whois.nic.tl/available.txt +21 -0
  217. data/test/testcases/responses/whois.nic.tl/registered.txt +29 -0
  218. data/test/testcases/responses/whois.nic.travel/available.txt +25 -0
  219. data/test/testcases/responses/whois.nic.travel/registered.txt +75 -0
  220. data/test/testcases/responses/whois.nic.uk/available.txt +20 -0
  221. data/test/testcases/responses/whois.nic.uk/invalid.txt +22 -0
  222. data/test/testcases/responses/whois.nic.uk/registered.txt +50 -0
  223. data/test/testcases/responses/whois.nic.us/available.txt +29 -0
  224. data/test/testcases/responses/whois.nic.us/registered.txt +99 -0
  225. data/test/testcases/responses/whois.norid.no/available.txt +5 -0
  226. data/test/testcases/responses/whois.norid.no/registered.txt +34 -0
  227. data/test/testcases/responses/whois.register.bg/available.txt +1 -0
  228. data/test/testcases/responses/whois.register.bg/registered.txt +44 -0
  229. data/test/testcases/responses/whois.registro.br/available.txt +22 -0
  230. data/test/testcases/responses/whois.registro.br/registered.txt +23 -0
  231. data/test/testcases/responses/whois.registrypro.pro/available.txt +20 -0
  232. data/test/testcases/responses/whois.registrypro.pro/registered.txt +62 -0
  233. data/test/testcases/responses/whois.ripe.net/fo/available.txt +11 -0
  234. data/test/testcases/responses/whois.ripe.net/fo/registered.txt +45 -0
  235. data/test/testcases/responses/whois.ripe.net/gm/available.txt +11 -0
  236. data/test/testcases/responses/whois.ripe.net/gm/registered.txt +37 -0
  237. data/test/testcases/responses/whois.ripe.net/mc/available.txt +11 -0
  238. data/test/testcases/responses/whois.ripe.net/mc/registered.txt +36 -0
  239. data/test/testcases/responses/whois.ripe.net/sm/available.txt +11 -0
  240. data/test/testcases/responses/whois.ripe.net/sm/registered.txt +60 -0
  241. data/test/testcases/responses/whois.ripe.net/va/available.txt +11 -0
  242. data/test/testcases/responses/whois.ripe.net/va/registered.txt +48 -0
  243. data/test/testcases/responses/whois.ripn.net/ru/available.txt +9 -0
  244. data/test/testcases/responses/whois.ripn.net/ru/registered.txt +24 -0
  245. data/test/testcases/responses/whois.ripn.net/su/available.txt +9 -0
  246. data/test/testcases/responses/whois.ripn.net/su/registered.txt +20 -0
  247. data/test/testcases/responses/whois.rotld.ro/available.txt +16 -0
  248. data/test/testcases/responses/whois.rotld.ro/registered.txt +27 -0
  249. data/test/testcases/responses/whois.samoanic.ws/available.txt +12 -0
  250. data/test/testcases/responses/whois.samoanic.ws/registered.txt +34 -0
  251. data/whois.gemspec +19 -19
  252. metadata +274 -31
  253. data/lib/whois/answer/parser/README.rdoc +0 -21
  254. data/lib/whois/definitions/ipv4.txt +0 -214
  255. data/lib/whois/definitions/ipv6.txt +0 -32
  256. data/lib/whois/definitions/tld.notes.txt +0 -1
  257. data/lib/whois/definitions/tlds.txt +0 -354
  258. data/lib/whois/whois.rb +0 -185
  259. data/test/testcases/responses/whois.afilias-grs.info/registered.txt +0 -122
  260. data/test/testcases/responses/whois.nic.fr/MULTIPLE.txt +0 -4
  261. data/test/whois_test.rb +0 -32
  262. data/utils/tlds.txt +0 -318
@@ -19,7 +19,6 @@ require 'whois/errors'
19
19
  require 'whois/client'
20
20
  require 'whois/server'
21
21
  require 'whois/answer'
22
- require 'whois/whois'
23
22
 
24
23
 
25
24
  module Whois
@@ -113,11 +113,9 @@ module Whois
113
113
  # Returns a Hash containing all supported properties for this Answer
114
114
  # along with corresponding values.
115
115
  def properties
116
- list = Parser.properties.inject([]) do |l,a|
117
- l.concat([a, send(a)]) if property_supported?(a)
118
- l
119
- end
120
- Hash[*list]
116
+ hash = {}
117
+ Parser.properties.each { |property| hash[property] = send(property) }
118
+ hash
121
119
  end
122
120
 
123
121
  # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
@@ -127,23 +125,36 @@ module Whois
127
125
  parser.property_supported?(property)
128
126
  end
129
127
 
130
- def supported?(*args)
131
- ::Whois.deprecate "supported? is deprecated. Use property_supported? instead."
132
- property_supported?(*args)
133
- end
134
-
135
128
 
136
129
  protected
137
-
130
+
138
131
  # Delegates all method calls to the internal parser.
139
132
  def method_missing(method, *args, &block)
140
133
  if Parser.properties.include?(method)
141
- parser.send(method, *args, &block)
134
+ self.class.class_eval foo = %{
135
+ def #{method}(*args, &block)
136
+ if property_supported?(:#{method})
137
+ parser.#{method}(*args, &block)
138
+ else
139
+ nil
140
+ end
141
+ end
142
+ }, __FILE__, __LINE__
143
+ send(method, *args, &block)
144
+
145
+ elsif method.to_s =~ /([a-z_]+)\?/ and Parser.properties.include?($1.to_sym)
146
+ self.class.class_eval %{
147
+ def #{$1}?
148
+ !#{$1}.nil?
149
+ end
150
+ }, __FILE__, __LINE__
151
+ send($1)
152
+
142
153
  else
143
154
  super
144
155
  end
145
156
  end
146
-
157
+
147
158
  end
148
159
 
149
160
  end
@@ -59,29 +59,40 @@ module Whois
59
59
  def property_supported?(property)
60
60
  parsers.any? { |parser| parser.property_supported?(property) }
61
61
  end
62
-
63
- def supported?(*args)
64
- ::Whois.deprecate "supported? is deprecated. Use property_supported? instead."
65
- property_supported?(*args)
66
- end
67
62
 
68
63
 
69
- protected
64
+ private
70
65
 
71
66
  def method_missing(method, *args, &block)
72
67
  if Parser.properties.include?(method)
73
- if parsers.empty?
74
- raise ParserError, "Unable to select a parser because the answer is empty"
75
- elsif parser = select_parser(method)
76
- parser.send(method, *args, &block)
77
- else
78
- raise PropertyNotSupported, "Unable to find a parser for `#{method}'"
79
- end
68
+ delegate_to_parsers(method, *args, &block)
80
69
  else
81
70
  super
82
71
  end
83
72
  end
84
73
 
74
+ def delegate_to_parsers(method, *args, &block)
75
+ # Raise an error without any parser
76
+ if parsers.empty?
77
+ raise ParserError, "Unable to select a parser because the answer is empty"
78
+
79
+ # Select a parser where the property is supported
80
+ # and call the method.
81
+ elsif parser = select_parser(method, :supported)
82
+ parser.send(method, *args, &block)
83
+
84
+ # Select a parser where the property is defined
85
+ # (but not supported) and call the method.
86
+ # The call is expected to raise an exception.
87
+ elsif parser = select_parser(method)
88
+ parser.send(method, *args, &block)
89
+
90
+ # The property is not supported nor defined.
91
+ else
92
+ raise PropertyNotAvailable, "Unable to find a parser for `#{method}'"
93
+ end
94
+ end
95
+
85
96
  # Loops through all answer parts, for each parts tries to guess
86
97
  # the appropriate Whois::Answer::Parser::<parser> if it exists
87
98
  # and returns the final array of server-specific parsers.
@@ -98,9 +109,9 @@ module Whois
98
109
  answer.parts.reverse.map { |part| self.class.parser_for(part) }
99
110
  end
100
111
 
101
- def select_parser(method)
112
+ def select_parser(property, status = :any)
102
113
  parsers.each do |parser|
103
- return parser if parser.method_registered?(method)
114
+ return parser if parser.class.property_registered?(property, status)
104
115
  end
105
116
  nil
106
117
  end
@@ -150,7 +161,7 @@ module Whois
150
161
  #
151
162
  def self.host_to_parser(host)
152
163
  host.to_s.
153
- gsub(/\./, '_').
164
+ gsub(/[.-]/, '_').
154
165
  gsub(/(?:^|_)(.)/) { $1.upcase }
155
166
  end
156
167
 
@@ -0,0 +1,3 @@
1
+ .us == .biz == .travel
2
+ .mobi == .info (afilias)
3
+ (afilias)
@@ -37,146 +37,185 @@ module Whois
37
37
  #
38
38
  class Base
39
39
 
40
- attr_reader :part
40
+ @@property_registry = {}
41
41
 
42
-
43
- def initialize(part)
44
- @part = part
45
- end
46
-
47
- ::Whois::Answer::Parser.properties.each do |method|
48
- define_method(method) do
49
- raise PropertyNotImplemented, "You should overwrite this method."
42
+ #
43
+ # :call-seq:
44
+ # property_registry => hash
45
+ # property_registry(ParserClass) => hash
46
+ #
47
+ # Returns the <tt>@@property_registry</tt> if <tt>klass</tt> is nil,
48
+ # otherwise returns the value in <tt>@@property_registry</tt> for given <tt>klass</tt>.
49
+ # <tt>klass</tt> is expected to be a class name.
50
+ #
51
+ # Returned value is always a hash. If <tt>@@property_registry[klass]</tt>
52
+ # doesn't exist, this method automatically initializes it to an empty Hash.
53
+ #
54
+ def self.property_registry(klass = nil)
55
+ if klass.nil?
56
+ @@property_registry
57
+ else
58
+ @@property_registry[klass] ||= {}
50
59
  end
51
60
  end
52
61
 
53
- # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
54
- # is supported by current parser.
62
+ # Returns the status for <tt>property</tt> passed as symbol.
55
63
  #
56
- # parser.property_supported? :disclaimer
57
- # # => false
64
+ # property_status(:disclaimer)
65
+ # # => nil
58
66
  #
59
- # parser.register_method(:disclaimer) {}
60
- # parser.property_supported? :disclaimer
61
- # # => true
67
+ # register_property(:discaimer, :supported) {}
68
+ # property_status(:disclaimer)
69
+ # # => :supported
62
70
  #
63
- # This method is different than <tt>respond_to?</tt>.
64
- # While <tt>respond_to?</tt> always returns true for any registrable property,
65
- # including those not effectively implemented,
66
- # this method only returns <tt>true</tt> if the parser implements <tt>property</tt>.
67
- # Also, <tt>property_supported?</tt> returns <tt>false</tt> if <tt>property</tt> exists as a method
68
- # but it's not a property method.
71
+ def self.property_status(property)
72
+ property = property.to_s.to_sym
73
+ property_registry(self)[property]
74
+ end
75
+
76
+ # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
77
+ # is registered in the <tt>property_registry</tt> for current parser.
69
78
  #
70
- # parser.respond_to?(:disclaimer)
71
- # # => true
72
- # parser.property_supported?(:disclaimer)
79
+ # property_registered?(:disclaimer)
73
80
  # # => false
74
81
  #
75
- # parser.register_method(:disclaimer) {}
76
- # parser.respond_to?(:disclaimer)
77
- # # => true
78
- # parser.property_supported?(:disclaimer)
82
+ # register_property(:discaimer) {}
83
+ # property_registered?(:disclaimer)
79
84
  # # => true
80
85
  #
81
- # parser.respond_to?(:contact)
82
- # # => true
83
- # parser.property_supported?(:contact)
84
- # # => false
85
- #
86
- def property_supported?(property)
87
- method_registered?(property.to_s.to_sym)
88
- end
89
-
90
- def supported?(*args)
91
- ::Whois.deprecate "supported? is deprecated. Use property_supported? instead."
92
- property_supported?(*args)
86
+ def self.property_registered?(property, status = :any)
87
+ property = property.to_s.to_sym
88
+ if status == :any
89
+ property_registry(self).key?(property)
90
+ else
91
+ property_registry(self)[property] == status
92
+ end
93
93
  end
94
94
 
95
-
96
- # This is an internal method primaly used as a common access point
97
- # to get the content to be parsed as a string.
98
95
  #
99
- # The main reason behind this method is because I changed the internal
100
- # representation of the data to be parsed more than once
101
- # and I always had to rewrite all single parsers in order to reflect these changes.
102
- # Now, as far as the parser access the data via the content method,
103
- # there's no need to change each single implementation in case the content source changes.
96
+ # :call-seq:
97
+ # register_property(:property, :status) { }
98
+ # register_property(:property, :status) { |parameter| ... }
99
+ # register_property(:property, :status) { |parameter, ...| ... }
104
100
  #
105
- # That said, the only constraints about this method is to return the data to be parsed as string.
101
+ # This method creates a new method called <tt>property</tt>
102
+ # with the content of <tt>block</tt> and registers
103
+ # the <tt>property</tt> in the <tt>property_registry</tt>
104
+ # with given <tt>status</tt>.
106
105
  #
107
- def content
108
- part.response
106
+ # register_property(:disclaimer, :supported) do
107
+ # ...
108
+ # end
109
+ #
110
+ # # def disclaimer
111
+ # # ...
112
+ # # end
113
+ #
114
+ # property_registered?(:disclaimer)
115
+ # # => true
116
+ #
117
+ #
118
+ # register_property(:changed?, :implemented) do |other|
119
+ # ...
120
+ # end
121
+ #
122
+ # # def changed?(other)
123
+ # # ...
124
+ # # end
125
+ #
126
+ def self.register_property(property, status, &block)
127
+ property = property.to_s.to_sym
128
+ property_registry(self).merge!({ property => status })
129
+ define_method(property, &block)
109
130
  end
110
131
 
111
132
 
112
- @@method_registry = {}
113
-
114
- #
115
- # :call-seq:
116
- # method_registry => hash
117
- # method_registry(:key) => array
133
+ # Registers a <tt>property</tt> as <tt>:not_implemented</tt>
134
+ # and defines a method which will raise a <tt>PropertyNotImplemented</tt> error.
118
135
  #
119
- # Returns the <tt>@@method_registry</tt> if <tt>key</tt> is nil,
120
- # otherwise returns the value in <tt>@@method_registry</tt> for given <tt>key</tt>.
136
+ # # Defines a not implemented property called :disclaimer.
137
+ # property_not_implemented(:disclaimer) do
138
+ # ...
139
+ # end
121
140
  #
122
- # <tt>@@method_registry</tt> is always a Hash while <tt>@@method_registry[:key]</tt>
123
- # is always an array. If <tt>@@method_registry[:key]</tt> doesn't exist, this method
124
- # automatically initializes it to an empty array.
141
+ # # def disclaimer
142
+ # # raise PropertyNotImplemented, "You should overwrite this method."
143
+ # # end
125
144
  #
126
- def self.method_registry(key = nil)
127
- if key.nil?
128
- @@method_registry
129
- else
130
- @@method_registry[key] ||= []
145
+ def self.property_not_implemented(property)
146
+ register_property(property, :not_implemented) do
147
+ raise PropertyNotSupported
131
148
  end
132
149
  end
133
150
 
134
- # Returns true if <tt>method</tt> is registered for current class.
151
+ # Registers a <tt>property</tt> as <tt>:not_supported</tt>
152
+ # and defines a method which will raise a <tt>PropertyNotSupported</tt> error.
135
153
  #
136
- # method_registered?(:disclaimer)
137
- # # => false
154
+ # # Defines an unsupported property called :disclaimer.
155
+ # property_not_supported(:disclaimer) do
156
+ # ...
157
+ # end
138
158
  #
139
- # register_method(:discaimer) {}
140
- # method_registered?(:disclaimer)
141
- # # => true
159
+ # # def disclaimer
160
+ # # raise PropertyNotSupported
161
+ # # end
142
162
  #
143
- def self.method_registered?(method)
144
- method_registry(self).include?(method)
163
+ def self.property_not_supported(property)
164
+ register_property(property, :not_supported) do
165
+ raise PropertyNotSupported
166
+ end
145
167
  end
146
-
147
- #
148
- # :call-seq:
149
- # register_method(:method) { }
150
- # register_method(:method) { |parameter| ... }
151
- # register_method(:method) { |parameter, ...| ... }
152
- #
153
- # Creates <tt>method</tt> with the content of <tt>block</tt>
154
- # and automatically registers <tt>method</tt> for current class.
155
- #
156
- # register_method(:discaimer) do
157
- # ...
158
- # end
168
+
169
+ # Registers a <tt>property</tt> as <tt>:supported</tt>
170
+ # and defines a method with the content of the block.
159
171
  #
160
- # register_method(:changed?) do |other|
172
+ # # Defines a supported property called :disclaimer.
173
+ # property_supported(:disclaimer) do
161
174
  # ...
162
175
  # end
163
176
  #
164
- # method_registered?(:disclaimer)
165
- # # => true
177
+ # # def disclaimer
178
+ # # ...
179
+ # # end
166
180
  #
167
- def self.register_method(method, &block)
168
- method_registry(self) << method
169
- define_method(method, &block)
181
+ def self.property_supported(property, &block)
182
+ register_property(property, :supported, &block)
170
183
  end
171
184
 
172
- # Instance-level version of <tt>Base.method_registered?</tt>.
173
- def method_registered?(method)
174
- self.class.method_registered?(method)
185
+
186
+
187
+ def initialize(part)
188
+ @part = part
175
189
  end
176
190
 
177
- # Instance-level version of <tt>Base.register_method</tt>.
178
- def register_method(method, &block)
179
- self.class.register_method(method, &block)
191
+ ::Whois::Answer::Parser.properties.each do |property|
192
+ property_not_implemented(property)
193
+ end
194
+
195
+ def part
196
+ @part
197
+ end
198
+
199
+ # This is an internal method primaly used as a common access point
200
+ # to get the content to be parsed as a string.
201
+ #
202
+ # The main reason behind this method is because I changed the internal
203
+ # representation of the data to be parsed more than once
204
+ # and I always had to rewrite all single parsers in order to reflect these changes.
205
+ # Now, as far as the parser access the data via the content method,
206
+ # there's no need to change each single implementation in case the content source changes.
207
+ #
208
+ # That said, the only constraints about this method is to return the data to be parsed as string.
209
+ #
210
+ def content
211
+ part.response
212
+ end
213
+
214
+
215
+ # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
216
+ # is supported by the current parser.
217
+ def property_supported?(property)
218
+ self.class.property_registered?(property, :supported)
180
219
  end
181
220
 
182
221
  end
@@ -0,0 +1,99 @@
1
+ #
2
+ # = Ruby Whois
3
+ #
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
+ #
6
+ #
7
+ # Category:: Net
8
+ # Package:: Whois
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ #
14
+ #++
15
+
16
+
17
+ require 'whois/answer/parser/base'
18
+ require 'whois/answer/parser/scanners/verisign'
19
+
20
+
21
+ module Whois
22
+ class Answer
23
+ class Parser
24
+
25
+ #
26
+ # = jobswhois.verisign-grs.com parser
27
+ #
28
+ # Parser for the jobswhois.verisign-grs.com server.
29
+ #
30
+ class JobswhoisVerisignGrsCom < Base
31
+ include Ast
32
+
33
+ property_supported :disclaimer do
34
+ node("Disclaimer")
35
+ end
36
+
37
+
38
+ property_supported :domain do
39
+ node("Domain Name") { |raw| raw.downcase }
40
+ end
41
+
42
+ property_supported :domain_id do
43
+ nil
44
+ end
45
+
46
+
47
+ property_supported :referral_whois do
48
+ node("Whois Server")
49
+ end
50
+
51
+ property_supported :referral_url do
52
+ node("Referral URL")
53
+ end
54
+
55
+
56
+ property_supported :status do
57
+ node("Status")
58
+ end
59
+
60
+ property_supported :available? do
61
+ node("Registrar").nil?
62
+ end
63
+
64
+ property_supported :registered? do
65
+ !available?
66
+ end
67
+
68
+
69
+ property_supported :created_on do
70
+ node("Creation Date") { |raw| Time.parse(raw) }
71
+ end
72
+
73
+ property_supported :updated_on do
74
+ node("Updated Date") { |raw| Time.parse(raw) }
75
+ end
76
+
77
+ property_supported :expires_on do
78
+ node("Expiration Date") { |raw| Time.parse(raw) }
79
+ end
80
+
81
+
82
+ property_supported :registrar do
83
+ # Return nil because when the response contains more than one registrar section
84
+ # the response can be messy. See, for instance, the Verisign response for google.com.
85
+ nil
86
+ end
87
+
88
+
89
+ protected
90
+
91
+ def parse
92
+ Scanners::VerisignScanner.new(content.to_s).parse
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+ end
99
+ end