whois 2.7.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/CHANGELOG.md +143 -0
  2. data/{LICENSE → LICENSE.txt} +1 -1
  3. data/README.md +28 -41
  4. data/bin/ruby-whois +14 -7
  5. data/data/ipv4.json +723 -0
  6. data/data/ipv6.json +100 -0
  7. data/data/tld.json +1302 -0
  8. data/lib/whois.rb +3 -3
  9. data/lib/whois/client.rb +17 -7
  10. data/lib/whois/core_ext.rb +0 -2
  11. data/lib/whois/errors.rb +13 -20
  12. data/lib/whois/record.rb +28 -22
  13. data/lib/whois/record/contact.rb +1 -1
  14. data/lib/whois/record/nameserver.rb +1 -1
  15. data/lib/whois/record/parser.rb +70 -46
  16. data/lib/whois/record/parser/base.rb +58 -59
  17. data/lib/whois/record/parser/base_afilias.rb +2 -7
  18. data/lib/whois/record/parser/base_cocca.rb +8 -5
  19. data/lib/whois/record/parser/base_cocca2.rb +107 -0
  20. data/lib/whois/record/parser/base_shared1.rb +2 -7
  21. data/lib/whois/record/parser/base_shared2.rb +2 -7
  22. data/lib/whois/record/parser/base_whoisd.rb +16 -9
  23. data/lib/whois/record/parser/blank.rb +1 -1
  24. data/lib/whois/record/parser/example.rb +1 -10
  25. data/lib/whois/record/parser/jobswhois.verisign-grs.com.rb +19 -19
  26. data/lib/whois/record/parser/kero.yachay.pe.rb +28 -18
  27. data/lib/whois/record/parser/whois.adamsnames.tc.rb +1 -1
  28. data/lib/whois/record/parser/whois.aeda.net.ae.rb +1 -1
  29. data/lib/whois/record/parser/whois.aero.rb +2 -2
  30. data/lib/whois/record/parser/whois.afilias-grs.info.rb +1 -1
  31. data/lib/whois/record/parser/whois.afilias.info.rb +1 -1
  32. data/lib/whois/record/parser/whois.ai.rb +1 -1
  33. data/lib/whois/record/parser/whois.arnes.si.rb +1 -1
  34. data/lib/whois/record/parser/whois.ati.tn.rb +3 -8
  35. data/lib/whois/record/parser/whois.audns.net.au.rb +4 -9
  36. data/lib/whois/record/parser/whois.ax.rb +66 -0
  37. data/lib/whois/record/parser/whois.biz.rb +1 -1
  38. data/lib/whois/record/parser/whois.cat.rb +1 -1
  39. data/lib/whois/record/parser/whois.cctld.by.rb +5 -8
  40. data/lib/whois/record/parser/whois.cctld.uz.rb +1 -1
  41. data/lib/whois/record/parser/whois.centralnic.com.rb +4 -9
  42. data/lib/whois/record/parser/whois.cira.ca.rb +3 -8
  43. data/lib/whois/record/parser/whois.cmc.iq.rb +7 -4
  44. data/lib/whois/record/parser/whois.cnnic.cn.rb +13 -21
  45. data/lib/whois/record/parser/whois.co.ca.rb +1 -1
  46. data/lib/whois/record/parser/whois.co.pl.rb +1 -6
  47. data/lib/whois/record/parser/whois.co.ug.rb +2 -2
  48. data/lib/whois/record/parser/whois.crsnic.net.rb +14 -15
  49. data/lib/whois/record/parser/whois.denic.de.rb +2 -2
  50. data/lib/whois/record/parser/whois.dk-hostmaster.dk.rb +2 -2
  51. data/lib/whois/record/parser/whois.dns.be.rb +2 -2
  52. data/lib/whois/record/parser/whois.dns.hr.rb +3 -8
  53. data/lib/whois/record/parser/whois.dns.lu.rb +1 -1
  54. data/lib/whois/record/parser/whois.dns.pl.rb +70 -9
  55. data/lib/whois/record/parser/whois.dns.pt.rb +16 -15
  56. data/lib/whois/record/parser/whois.domain-registry.nl.rb +2 -2
  57. data/lib/whois/record/parser/whois.domain.kg.rb +1 -1
  58. data/lib/whois/record/parser/whois.domainregistry.ie.rb +9 -12
  59. data/lib/whois/record/parser/whois.domainregistry.my.rb +1 -1
  60. data/lib/whois/record/parser/whois.domreg.lt.rb +1 -1
  61. data/lib/whois/record/parser/whois.dot.tk.rb +1 -1
  62. data/lib/whois/record/parser/whois.dotmobiregistry.net.rb +1 -1
  63. data/lib/whois/record/parser/whois.dreamhost.com.rb +1 -1
  64. data/lib/whois/record/parser/whois.educause.edu.rb +1 -6
  65. data/lib/whois/record/parser/whois.eenet.ee.rb +1 -1
  66. data/lib/whois/record/parser/whois.enom.com.rb +1 -1
  67. data/lib/whois/record/parser/whois.eu.org.rb +1 -1
  68. data/lib/whois/record/parser/whois.eu.rb +13 -1
  69. data/lib/whois/record/parser/whois.fi.rb +2 -2
  70. data/lib/whois/record/parser/whois.gg.rb +1 -1
  71. data/lib/whois/record/parser/whois.godaddy.com.rb +4 -4
  72. data/lib/whois/record/parser/whois.gov.za.rb +1 -1
  73. data/lib/whois/record/parser/whois.hkirc.hk.rb +1 -1
  74. data/lib/whois/record/parser/whois.iam.net.ma.rb +1 -1
  75. data/lib/whois/record/parser/whois.iana.org.rb +2 -2
  76. data/lib/whois/record/parser/whois.in.ua.rb +1 -1
  77. data/lib/whois/record/parser/whois.isnic.is.rb +1 -1
  78. data/lib/whois/record/parser/whois.isoc.org.il.rb +1 -1
  79. data/lib/whois/record/parser/whois.ja.net.rb +1 -1
  80. data/lib/whois/record/parser/whois.je.rb +1 -1
  81. data/lib/whois/record/parser/whois.jprs.jp.rb +9 -6
  82. data/lib/whois/record/parser/whois.kenic.or.ke.rb +1 -1
  83. data/lib/whois/record/parser/whois.kr.rb +1 -1
  84. data/lib/whois/record/parser/whois.markmonitor.com.rb +1 -1
  85. data/lib/whois/record/parser/whois.meregistry.net.rb +1 -1
  86. data/lib/whois/record/parser/whois.monic.mo.rb +1 -6
  87. data/lib/whois/record/parser/whois.museum.rb +1 -1
  88. data/lib/whois/record/parser/whois.na-nic.com.na.rb +3 -23
  89. data/lib/whois/record/parser/whois.nc.rb +8 -11
  90. data/lib/whois/record/parser/whois.netcom.cm.rb +1 -1
  91. data/lib/whois/record/parser/whois.networksolutions.com.rb +1 -1
  92. data/lib/whois/record/parser/whois.nic-se.se.rb +1 -1
  93. data/lib/whois/record/parser/whois.nic.ac.rb +1 -6
  94. data/lib/whois/record/parser/whois.nic.af.rb +7 -3
  95. data/lib/whois/record/parser/whois.nic.ag.rb +1 -1
  96. data/lib/whois/record/parser/whois.nic.am.rb +1 -1
  97. data/lib/whois/record/parser/whois.nic.as.rb +1 -1
  98. data/lib/whois/record/parser/whois.nic.asia.rb +1 -1
  99. data/lib/whois/record/parser/whois.nic.at.rb +7 -9
  100. data/lib/whois/record/parser/whois.nic.bo.rb +1 -1
  101. data/lib/whois/record/parser/whois.nic.cc.rb +11 -11
  102. data/lib/whois/record/parser/whois.nic.cd.rb +1 -1
  103. data/lib/whois/record/parser/whois.nic.ch.rb +1 -1
  104. data/lib/whois/record/parser/whois.nic.ci.rb +1 -1
  105. data/lib/whois/record/parser/whois.nic.ck.rb +1 -1
  106. data/lib/whois/record/parser/whois.nic.cl.rb +1 -1
  107. data/lib/whois/record/parser/whois.nic.co.rb +1 -1
  108. data/lib/whois/record/parser/whois.nic.coop.rb +1 -1
  109. data/lib/whois/record/parser/whois.nic.cx.rb +7 -3
  110. data/lib/whois/record/parser/whois.nic.cz.rb +8 -3
  111. data/lib/whois/record/parser/whois.nic.dm.rb +3 -8
  112. data/lib/whois/record/parser/whois.nic.dz.rb +1 -1
  113. data/lib/whois/record/parser/whois.nic.ec.rb +1 -1
  114. data/lib/whois/record/parser/whois.nic.fo.rb +2 -2
  115. data/lib/whois/record/parser/whois.nic.fr.rb +1 -1
  116. data/lib/whois/record/parser/whois.nic.gl.rb +5 -1
  117. data/lib/whois/record/parser/whois.nic.gov.rb +11 -12
  118. data/lib/whois/record/parser/whois.nic.gs.rb +7 -23
  119. data/lib/whois/record/parser/whois.nic.hn.rb +28 -0
  120. data/lib/whois/record/parser/whois.nic.ht.rb +7 -3
  121. data/lib/whois/record/parser/whois.nic.hu.rb +2 -2
  122. data/lib/whois/record/parser/whois.nic.im.rb +1 -1
  123. data/lib/whois/record/parser/whois.nic.io.rb +1 -6
  124. data/lib/whois/record/parser/whois.nic.ir.rb +1 -1
  125. data/lib/whois/record/parser/whois.nic.it.rb +2 -7
  126. data/lib/whois/record/parser/whois.nic.ki.rb +7 -3
  127. data/lib/whois/record/parser/whois.nic.kz.rb +9 -12
  128. data/lib/whois/record/parser/whois.nic.la.rb +3 -2
  129. data/lib/whois/record/parser/whois.nic.li.rb +1 -1
  130. data/lib/whois/record/parser/whois.nic.lk.rb +3 -9
  131. data/lib/whois/record/parser/whois.nic.lv.rb +1 -1
  132. data/lib/whois/record/parser/whois.nic.ly.rb +1 -1
  133. data/lib/whois/record/parser/whois.nic.md.rb +1 -6
  134. data/lib/whois/record/parser/whois.nic.mg.rb +1 -1
  135. data/lib/whois/record/parser/whois.nic.ms.rb +7 -3
  136. data/lib/whois/record/parser/whois.nic.mu.rb +7 -3
  137. data/lib/whois/record/parser/whois.nic.mx.rb +1 -1
  138. data/lib/whois/record/parser/whois.nic.name.rb +2 -2
  139. data/lib/whois/record/parser/whois.nic.net.nf.rb +7 -42
  140. data/lib/whois/record/parser/whois.nic.net.ng.rb +3 -3
  141. data/lib/whois/record/parser/whois.nic.net.sa.rb +1 -1
  142. data/lib/whois/record/parser/whois.nic.net.sb.rb +7 -3
  143. data/lib/whois/record/parser/whois.nic.nu.rb +1 -1
  144. data/lib/whois/record/parser/whois.nic.org.uy.rb +1 -1
  145. data/lib/whois/record/parser/whois.nic.pr.rb +32 -14
  146. data/lib/whois/record/parser/whois.nic.priv.at.rb +1 -1
  147. data/lib/whois/record/parser/whois.nic.pw.rb +27 -0
  148. data/lib/whois/record/parser/whois.nic.sh.rb +1 -6
  149. data/lib/whois/record/parser/whois.nic.sl.rb +1 -1
  150. data/lib/whois/record/parser/whois.nic.sm.rb +1 -1
  151. data/lib/whois/record/parser/whois.nic.sn.rb +1 -6
  152. data/lib/whois/record/parser/whois.nic.so.rb +1 -1
  153. data/lib/whois/record/parser/whois.nic.st.rb +1 -1
  154. data/lib/whois/record/parser/whois.nic.tel.rb +5 -54
  155. data/lib/whois/record/parser/whois.nic.tl.rb +7 -3
  156. data/lib/whois/record/parser/whois.nic.tm.rb +1 -6
  157. data/lib/whois/record/parser/whois.nic.tr.rb +1 -1
  158. data/lib/whois/record/parser/whois.nic.travel.rb +5 -50
  159. data/lib/whois/record/parser/whois.nic.tv.rb +11 -12
  160. data/lib/whois/record/parser/whois.nic.uk.rb +18 -20
  161. data/lib/whois/record/parser/whois.nic.us.rb +5 -50
  162. data/lib/whois/record/parser/whois.nic.ve.rb +1 -1
  163. data/lib/whois/record/parser/whois.nic.xxx.rb +1 -1
  164. data/lib/whois/record/parser/whois.norid.no.rb +1 -1
  165. data/lib/whois/record/parser/whois.org.za.rb +1 -6
  166. data/lib/whois/record/parser/whois.pandi.or.id.rb +1 -1
  167. data/lib/whois/record/parser/whois.pir.org.rb +1 -1
  168. data/lib/whois/record/parser/whois.pnina.ps.rb +1 -1
  169. data/lib/whois/record/parser/whois.register.bg.rb +1 -1
  170. data/lib/whois/record/parser/whois.register.com.rb +2 -2
  171. data/lib/whois/record/parser/whois.registro.br.rb +1 -1
  172. data/lib/whois/record/parser/whois.registry.gy.rb +7 -3
  173. data/lib/whois/record/parser/whois.registry.hm.rb +1 -1
  174. data/lib/whois/record/parser/whois.registry.in.rb +1 -1
  175. data/lib/whois/record/parser/whois.registry.net.za.rb +123 -0
  176. data/lib/whois/record/parser/whois.registry.om.rb +2 -2
  177. data/lib/whois/record/parser/whois.registry.qa.rb +1 -1
  178. data/lib/whois/record/parser/whois.registrypro.pro.rb +2 -2
  179. data/lib/whois/record/parser/whois.ripe.net.rb +1 -1
  180. data/lib/whois/record/parser/whois.rnids.rs.rb +3 -8
  181. data/lib/whois/record/parser/whois.rotld.ro.rb +1 -1
  182. data/lib/whois/record/parser/whois.samoanic.ws.rb +1 -1
  183. data/lib/whois/record/parser/whois.sgnic.sg.rb +1 -1
  184. data/lib/whois/record/parser/whois.sk-nic.sk.rb +1 -1
  185. data/lib/whois/record/parser/whois.smallregistry.net.rb +2 -2
  186. data/lib/whois/record/parser/whois.srs.net.nz.rb +1 -1
  187. data/lib/whois/record/parser/whois.sx.rb +50 -32
  188. data/lib/whois/record/parser/whois.tcinet.ru.rb +2 -2
  189. data/lib/whois/record/parser/whois.thnic.co.th.rb +5 -5
  190. data/lib/whois/record/parser/whois.tld.ee.rb +2 -2
  191. data/lib/whois/record/parser/whois.tonic.to.rb +1 -6
  192. data/lib/whois/record/parser/whois.twnic.net.tw.rb +1 -1
  193. data/lib/whois/record/parser/whois.tznic.or.tz.rb +2 -2
  194. data/lib/whois/record/parser/whois.ua.rb +1 -6
  195. data/lib/whois/record/parser/whois.usp.ac.fj.rb +1 -1
  196. data/lib/whois/record/parser/whois.za.net.rb +1 -1
  197. data/lib/whois/record/parser/whois.za.org.rb +1 -1
  198. data/lib/whois/record/parser/whois1.nic.bi.rb +5 -1
  199. data/lib/whois/record/part.rb +1 -1
  200. data/lib/whois/record/registrar.rb +1 -1
  201. data/lib/whois/record/scanners/base.rb +1 -1
  202. data/lib/whois/record/scanners/base_afilias.rb +1 -1
  203. data/lib/whois/record/scanners/base_shared1.rb +1 -1
  204. data/lib/whois/record/scanners/base_shared2.rb +1 -2
  205. data/lib/whois/record/scanners/base_whoisd.rb +4 -4
  206. data/lib/whois/record/scanners/iana.rb +1 -1
  207. data/lib/whois/record/scanners/{ast.rb → nodable.rb} +4 -4
  208. data/lib/whois/record/scanners/verisign.rb +1 -1
  209. data/lib/whois/record/scanners/whois.ati.tn.rb +1 -1
  210. data/lib/whois/record/scanners/whois.audns.net.au.rb +1 -1
  211. data/lib/whois/record/scanners/whois.cctld.by.rb +3 -1
  212. data/lib/whois/record/scanners/whois.centralnic.com.rb +1 -1
  213. data/lib/whois/record/scanners/whois.cira.ca.rb +1 -1
  214. data/lib/whois/record/scanners/whois.cnnic.cn.rb +6 -3
  215. data/lib/whois/record/scanners/whois.denic.de.rb +1 -1
  216. data/lib/whois/record/scanners/whois.dns.hr.rb +1 -1
  217. data/lib/whois/record/scanners/whois.domainregistry.ie.rb +3 -1
  218. data/lib/whois/record/scanners/whois.nc.rb +1 -1
  219. data/lib/whois/record/scanners/whois.nic.dm.rb +1 -1
  220. data/lib/whois/record/scanners/whois.nic.hu.rb +1 -1
  221. data/lib/whois/record/scanners/whois.nic.it.rb +1 -1
  222. data/lib/whois/record/scanners/whois.registry.net.za.rb +103 -0
  223. data/lib/whois/record/scanners/whois.rnids.rs.rb +1 -1
  224. data/lib/whois/record/scanners/whois.smallregistry.net.rb +1 -1
  225. data/lib/whois/record/scanners/whois.sx.rb +14 -46
  226. data/lib/whois/record/super_struct.rb +1 -1
  227. data/lib/whois/server.rb +18 -4
  228. data/lib/whois/server/adapters/afilias.rb +8 -13
  229. data/lib/whois/server/adapters/arpa.rb +1 -1
  230. data/lib/whois/server/adapters/base.rb +24 -44
  231. data/lib/whois/server/adapters/formatted.rb +1 -1
  232. data/lib/whois/server/adapters/none.rb +1 -1
  233. data/lib/whois/server/adapters/not_implemented.rb +1 -1
  234. data/lib/whois/server/adapters/standard.rb +1 -1
  235. data/lib/whois/server/adapters/verisign.rb +11 -19
  236. data/lib/whois/server/adapters/web.rb +2 -5
  237. data/lib/whois/server/socket_handler.rb +66 -0
  238. data/lib/whois/version.rb +3 -3
  239. data/whois.gemspec +11 -11
  240. metadata +24 -29
  241. data/lib/whois/core_ext/date_time/conversions.rb +0 -14
  242. data/lib/whois/definitions/ipv4.rb +0 -240
  243. data/lib/whois/definitions/ipv6.rb +0 -32
  244. data/lib/whois/definitions/tlds.rb +0 -367
  245. data/lib/whois/record/parser/saudinic.net.sa.rb +0 -23
  246. data/lib/whois/record/parser/whois.ausregistry.net.au.rb +0 -23
  247. data/lib/whois/record/parser/whois.centralnic.net.rb +0 -25
  248. data/lib/whois/record/parser/whois.cnnic.net.cn.rb +0 -23
  249. data/lib/whois/record/parser/whois.coza.net.za.rb +0 -76
  250. data/lib/whois/record/parser/whois.ficora.fi.rb +0 -24
  251. data/lib/whois/record/parser/whois.hkdnr.net.hk.rb +0 -23
  252. data/lib/whois/record/parser/whois.net.ua.rb +0 -24
  253. data/lib/whois/record/parser/whois.nic.or.kr.rb +0 -24
  254. data/lib/whois/record/parser/whois.publicinterestregistry.net.rb +0 -23
  255. data/lib/whois/record/parser/whois.ripn.net.rb +0 -23
data/lib/whois.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
- # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
6
+ # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
7
7
  #++
8
8
 
9
9
 
@@ -38,7 +38,7 @@ module Whois
38
38
  # Whois::Client.new.query("google.com")
39
39
  #
40
40
  def query(object)
41
- Client.new.query(object)
41
+ Client.new.lookup(object)
42
42
  end
43
43
 
44
44
  alias_method :whois, :query
@@ -84,7 +84,7 @@ module Whois
84
84
  # This is a technical limitation. Browse the lib/whois/record/parsers folder
85
85
  # to view all available parsers.
86
86
  #
87
- # @param [String] string The string to be sent as query parameter.
87
+ # @param [String] object The string to be sent as query parameter.
88
88
  # It is intended to be a domain name, otherwise this method
89
89
  # may return unexpected responses.
90
90
  # @return [Boolean]
data/lib/whois/client.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
- # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
6
+ # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
7
7
  #++
8
8
 
9
9
 
@@ -31,7 +31,7 @@ module Whois
31
31
  # If <tt>block</tt> is given, yields <tt>self</tt>.
32
32
  #
33
33
  # @param [Hash] settings Hash of settings to customize the client behavior.
34
- # @option settings [Fixnum, nil] :timeout (DEFAULT_TIMEOUT)
34
+ # @option settings [Integer, nil] :timeout (DEFAULT_TIMEOUT)
35
35
  # The timeout for a WHOIS query, expressed in seconds.
36
36
  # @option settings [String] :bind_host (nil)
37
37
  # Providing an IP address or hostname will bind the Socket connection
@@ -39,6 +39,10 @@ module Whois
39
39
  # @option settings [Fixnum] :bind_port (nil)
40
40
  # Providing port number will bind the Socket connection
41
41
  # to the specific local port.
42
+ # @option settings [String, nil] :host (nil)
43
+ # The server host to query. Leave it blank for intelligent detection.
44
+ # @option settings [Boolean, nil] :referral (nil)
45
+ # Set to +false+ to disable queries to referral WHOIS servers.
42
46
  #
43
47
  # @yield [self]
44
48
  #
@@ -69,28 +73,34 @@ module Whois
69
73
  end
70
74
 
71
75
 
72
- # Queries the right WHOIS server for <tt>object</tt>
76
+ # Lookups the right WHOIS server for <tt>object</tt>
73
77
  # and returns the response from the server.
74
78
  #
75
- # @param [#to_s] object The string to be sent as query parameter.
79
+ # @param [#to_s] object The string to be sent as lookup parameter.
76
80
  # @return [Whois::Record] The object containing the WHOIS response.
77
81
  #
78
82
  # @raise [Timeout::Error]
79
83
  #
80
84
  # @example
81
85
  #
82
- # client.query("google.com")
86
+ # client.lookup("google.com")
83
87
  # # => #<Whois::Record>
84
88
  #
85
- def query(object)
89
+ def lookup(object)
86
90
  string = object.to_s.downcase
87
91
  Timeout::timeout(timeout) do
88
92
  @server = Server.guess(string)
89
93
  @server.configure(settings)
90
- @server.query(string)
94
+ @server.lookup(string)
91
95
  end
92
96
  end
93
97
 
98
+ # @deprecated
99
+ def query(*args)
100
+ Whois.deprecate("Client#query is deprecated, use Client#lookup instead.")
101
+ lookup(*args)
102
+ end
103
+
94
104
  end
95
105
 
96
106
  end
@@ -1,9 +1,7 @@
1
1
  if defined?(ActiveSupport::VERSION) && ActiveSupport::VERSION::MAJOR == 3
2
2
  require 'active_support/core_ext/array/wrap'
3
- require 'active_support/core_ext/date_time/conversions'
4
3
  require 'whois/core_ext/class/attribute'
5
4
  else
6
5
  require 'whois/core_ext/array/wrap'
7
- require 'whois/core_ext/date_time/conversions'
8
6
  require 'whois/core_ext/class/attribute'
9
7
  end
data/lib/whois/errors.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
- # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
6
+ # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
7
7
  #++
8
8
 
9
9
 
@@ -18,7 +18,7 @@ module Whois
18
18
  end
19
19
 
20
20
 
21
- # @group Server
21
+ # @!group Server
22
22
 
23
23
  # Generic class for server errors.
24
24
  class ServerError < Error
@@ -53,10 +53,10 @@ module Whois
53
53
  class AllocationUnknown < ServerError
54
54
  end
55
55
 
56
- # @endgroup
56
+ # @!endgroup
57
57
 
58
58
 
59
- # @group Interface
59
+ # @!group Interface
60
60
 
61
61
  # Generic class for interfaces not supported.
62
62
  class InterfaceNotSupported < ServerError
@@ -85,10 +85,10 @@ module Whois
85
85
 
86
86
  end
87
87
 
88
- # @endgroup
88
+ # @!endgroup
89
89
 
90
90
 
91
- # @group Parser
91
+ # @!group Parser
92
92
 
93
93
  # Generic class for parser errors.
94
94
  class ParserError < Error
@@ -100,25 +100,18 @@ module Whois
100
100
  class ParserNotFound < ParserError
101
101
  end
102
102
 
103
- # Raised when the property method has not been overwritten (implemented)
104
- # in a child parser class.
105
- class PropertyNotImplemented < ParserError
103
+ # Raised when you are trying to access an attribute that has not been implemented.
104
+ class AttributeNotImplemented < ParserError
106
105
  end
107
106
 
108
- # Raised when you are trying to access a property that is not supported
109
- # for the current WHOIS record.
110
- class PropertyNotSupported < ParserError
107
+ # Raised when you are trying to access an attribute that is not supported.
108
+ class AttributeNotSupported < ParserError
111
109
  end
112
110
 
113
- # Raised when you are trying to access a property that is not supported
114
- # by any of the parsers available for current WHOIS record.
115
- class PropertyNotAvailable < ParserError
116
- end
117
-
118
- # @endgroup
111
+ # @!endgroup
119
112
 
120
113
 
121
- # @group Response
114
+ # @!group Response
122
115
 
123
116
  # Generic class for response errors.
124
117
  class ResponseError < Error
@@ -137,6 +130,6 @@ module Whois
137
130
  class ResponseIsUnavailable < ResponseError
138
131
  end
139
132
 
140
- # @endgroup
133
+ # @!endgroup
141
134
 
142
135
  end
data/lib/whois/record.rb CHANGED
@@ -3,18 +3,20 @@
3
3
  #
4
4
  # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
- # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
6
+ # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
7
7
  #++
8
8
 
9
9
 
10
- require 'whois/record/parser'
11
- require 'whois/record/parser/base'
10
+ require 'whois/record/part'
12
11
 
13
12
 
14
13
  module Whois
15
14
 
16
15
  class Record
17
16
 
17
+ autoload :Parser, 'whois/record/parser'
18
+
19
+
18
20
  # @return [Whois::Server] The server that originated this record.
19
21
  attr_reader :server
20
22
 
@@ -41,7 +43,7 @@ module Whois
41
43
  # @return [Boolean]
42
44
  #
43
45
  def respond_to?(symbol, include_private = false)
44
- super || Parser::PROPERTIES.include?(symbol) || Parser::METHODS.include?(symbol)
46
+ respond_to_parser_method?(symbol) || super
45
47
  end
46
48
 
47
49
  # Returns a String representation of this record.
@@ -131,20 +133,20 @@ module Whois
131
133
  @parser ||= Parser.new(self)
132
134
  end
133
135
 
134
- # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
135
- # is supported by any available parser for this record.
136
+ # Checks if the <tt>property</tt> passed as symbol
137
+ # is supported in any of the parsers.
136
138
  #
137
139
  # @param [Symbol] property The name of the property to check.
138
140
  # @return [Boolean]
139
141
  #
140
- # @see Whois::Record::Parser#property_supported?
142
+ # @see Whois::Record::Parser#property_any_supported?
141
143
  #
142
- def property_supported?(property)
143
- parser.property_supported?(property)
144
+ def property_any_supported?(property)
145
+ parser.property_any_supported?(property)
144
146
  end
145
147
 
146
148
 
147
- # @group Properties
149
+ # @!group Properties
148
150
 
149
151
  # Returns a Hash containing all supported properties for this record
150
152
  # along with corresponding values.
@@ -157,10 +159,10 @@ module Whois
157
159
  hash
158
160
  end
159
161
 
160
- # @endgroup
162
+ # @!endgroup
161
163
 
162
164
 
163
- # @group Methods
165
+ # @!group Methods
164
166
 
165
167
  # Shortcut for <tt>#registrant_contacts.first</tt>.
166
168
  #
@@ -172,7 +174,7 @@ module Whois
172
174
  # @see Whois::Record#registrant_contacts
173
175
  #
174
176
  def registrant_contact
175
- if property_supported?(:registrant_contacts)
177
+ if property_any_supported?(:registrant_contacts)
176
178
  parser.registrant_contacts.first
177
179
  end
178
180
  end
@@ -187,7 +189,7 @@ module Whois
187
189
  # @see Whois::Record#admin_contacts
188
190
  #
189
191
  def admin_contact
190
- if property_supported?(:admin_contacts)
192
+ if property_any_supported?(:admin_contacts)
191
193
  parser.admin_contacts.first
192
194
  end
193
195
  end
@@ -202,7 +204,7 @@ module Whois
202
204
  # @see Whois::Record#technical_contacts
203
205
  #
204
206
  def technical_contact
205
- if property_supported?(:technical_contacts)
207
+ if property_any_supported(:technical_contacts)
206
208
  parser.technical_contacts.first
207
209
  end
208
210
  end
@@ -217,10 +219,10 @@ module Whois
217
219
  parser.contacts
218
220
  end
219
221
 
220
- # @endgroup
222
+ # @!endgroup
221
223
 
222
224
 
223
- # @group Response
225
+ # @!group Response
224
226
 
225
227
  # Checks whether this {Whois::Record} is different than +other+.
226
228
  #
@@ -256,8 +258,7 @@ module Whois
256
258
  raise(ArgumentError, "Can't compare `#{self.class}' with `#{other.class}'")
257
259
  end
258
260
 
259
- equal?(other) ||
260
- parser.unchanged?(other.parser)
261
+ equal?(other) || parser.unchanged?(other.parser)
261
262
  end
262
263
 
263
264
 
@@ -291,16 +292,16 @@ module Whois
291
292
  parser.response_unavailable?
292
293
  end
293
294
 
294
- # @endgroup
295
+ # @!endgroup
295
296
 
296
297
 
297
- private
298
+ private
298
299
 
299
300
  # @api private
300
301
  def self.define_property_method(method)
301
302
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
302
303
  def #{method}(*args, &block)
303
- if property_supported?(:#{method})
304
+ if property_any_supported?(:#{method})
304
305
  parser.#{method}(*args, &block)
305
306
  end
306
307
  end
@@ -327,6 +328,11 @@ module Whois
327
328
  RUBY
328
329
  end
329
330
 
331
+ def respond_to_parser_method?(symbol)
332
+ name = symbol.to_s =~ /\?$/ ? symbol.to_s[0..-2] : symbol
333
+ Parser::PROPERTIES.include?(name.to_sym) || Parser::METHODS.include?(name.to_sym)
334
+ end
335
+
330
336
  # Delegates all method calls to the internal parser.
331
337
  def method_missing(method, *args, &block)
332
338
  if Parser::PROPERTIES.include?(method)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
- # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
6
+ # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
7
7
  #++
8
8
 
9
9
 
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
- # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
6
+ # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
7
7
  #++
8
8
 
9
9
 
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # An intelligent pure Ruby WHOIS client and parser.
5
5
  #
6
- # Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
6
+ # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
7
7
  #++
8
8
 
9
9
 
@@ -16,21 +16,21 @@ module Whois
16
16
  # The list of properties and methods is available
17
17
  # in the following constants:
18
18
  #
19
- # * {Whois::Record::METHODS}
20
- # * {Whois::Record::PROPERTIES}
19
+ # * {Whois::Record::Parser::METHODS}
20
+ # * {Whois::Record::Parser::PROPERTIES}
21
21
  #
22
22
  class Parser
23
23
 
24
24
  METHODS = [
25
- :changed?, :unchanged?,
26
25
  :contacts,
27
- # :response_throttled?, :response_incomplete?,
26
+ :changed?, :unchanged?,
27
+ # :response_incomplete?, :response_throttled?, :response_unavailable?,
28
+ # :referral_whois, :referral_url,
28
29
  ]
29
30
 
30
31
  PROPERTIES = [
31
32
  :disclaimer,
32
33
  :domain, :domain_id,
33
- :referral_whois, :referral_url,
34
34
  :status, :available?, :registered?,
35
35
  :created_on, :updated_on, :expires_on,
36
36
  :registrar,
@@ -38,6 +38,10 @@ module Whois
38
38
  :nameservers,
39
39
  ]
40
40
 
41
+ PROPERTY_STATE_NOT_IMPLEMENTED = :not_implemented
42
+ PROPERTY_STATE_NOT_SUPPORTED = :not_supported
43
+ PROPERTY_STATE_SUPPORTED = :supported
44
+
41
45
 
42
46
  # Returns the proper parser instance for given <tt>part</tt>.
43
47
  # The parser class is selected according to the
@@ -149,7 +153,7 @@ module Whois
149
153
  #
150
154
  # @return [Boolean]
151
155
  def respond_to?(symbol, include_private = false)
152
- super || PROPERTIES.include?(symbol) || METHODS.include?(symbol)
156
+ respond_to_parser_method?(symbol) || super
153
157
  end
154
158
 
155
159
 
@@ -163,19 +167,28 @@ module Whois
163
167
  @parsers ||= init_parsers
164
168
  end
165
169
 
166
- # Returns <tt>true</tt> if the <tt>property</tt> passed as symbol
167
- # is supported by any available parser.
170
+ # Checks if the <tt>property</tt> passed as symbol
171
+ # is supported in any of the parsers.
168
172
  #
169
173
  # @return [Boolean]
170
174
  #
171
175
  # @see Whois::Record::Parser::Base.property_supported?
172
176
  #
173
- def property_supported?(property)
177
+ def property_any_supported?(property)
174
178
  parsers.any? { |parser| parser.property_supported?(property) }
175
179
  end
176
180
 
181
+ # Checks if the <tt>property</tt> passed as symbol
182
+ # is "not implemented" in any of the parsers.
183
+ #
184
+ # @return [Boolean]
185
+ #
186
+ def property_any_not_implemented?(property)
187
+ parsers.any? { |parser| parser.class.property_state?(property, Whois::Record::Parser::PROPERTY_STATE_NOT_IMPLEMENTED) }
188
+ end
189
+
177
190
 
178
- # @group Methods
191
+ # @!group Methods
179
192
 
180
193
  # Collects and returns all the contacts from all the record parts.
181
194
  #
@@ -188,10 +201,10 @@ module Whois
188
201
  parsers.map(&:contacts).flatten
189
202
  end
190
203
 
191
- # @endgroup
204
+ # @!endgroup
192
205
 
193
206
 
194
- # @group Response
207
+ # @!group Response
195
208
 
196
209
  # Loop through all the record parts to check
197
210
  # if at least one part changed.
@@ -223,6 +236,7 @@ module Whois
223
236
  parsers.size == other.parsers.size && all_in_parallel?(parsers, other.parsers) { |one, two| one.unchanged?(two) }
224
237
  end
225
238
 
239
+
226
240
  # Loop through all the parts to check if at least
227
241
  # one part is an incomplete response.
228
242
  #
@@ -259,51 +273,64 @@ module Whois
259
273
  any_is?(parsers, :response_unavailable?)
260
274
  end
261
275
 
262
- # @endgroup
276
+ # @!endgroup
277
+
263
278
 
279
+ private
264
280
 
265
- private
281
+ # @api private
282
+ def self.define_property_method(method)
283
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
284
+ def #{method}(*args, &block)
285
+ delegate_property_to_parsers(:#{method}, *args, &block)
286
+ end
287
+ RUBY
288
+ end
266
289
 
267
290
  # @api private
268
- def self.define_missing_method(method)
291
+ def self.define_method_method(method)
269
292
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
270
293
  def #{method}(*args, &block)
271
- delegate_to_parsers(:#{method}, *args, &block)
294
+ delegate_method_to_parsers(:#{method}, *args, &block)
272
295
  end
273
296
  RUBY
274
297
  end
275
298
 
299
+ def respond_to_parser_method?(symbol)
300
+ Parser::PROPERTIES.include?(symbol) || Parser::METHODS.include?(symbol)
301
+ end
302
+
276
303
  def method_missing(method, *args, &block)
277
304
  if PROPERTIES.include?(method)
278
- self.class.define_missing_method(method)
305
+ self.class.define_property_method(method)
279
306
  send(method, *args, &block)
280
307
  elsif METHODS.include?(method)
281
- self.class.define_missing_method(method)
308
+ self.class.define_method_method(method)
282
309
  send(method, *args, &block)
283
310
  else
284
311
  super
285
312
  end
286
313
  end
287
314
 
288
- def delegate_to_parsers(method, *args, &block)
289
- # Raise an error without any parser
315
+ def delegate_property_to_parsers(method, *args, &block)
290
316
  if parsers.empty?
291
- raise ParserError, "Unable to select a parser because the record is empty"
292
-
293
- # Select a parser where the property is supported
294
- # and call the method.
295
- elsif parser = select_parser(method, :supported)
317
+ raise ParserError, "Unable to select a parser because the Record is empty"
318
+ elsif (parser = select_parser { |p| p.class.property_state?(method, PROPERTY_STATE_SUPPORTED) })
296
319
  parser.send(method, *args, &block)
297
-
298
- # Select a parser where the property is defined but not supported
299
- # and call the method.
300
- # The call is expected to raise an exception.
301
- elsif parser = select_parser(method, :not_supported)
320
+ elsif (parser = select_parser { |p| p.class.property_state?(method, PROPERTY_STATE_NOT_SUPPORTED) })
302
321
  parser.send(method, *args, &block)
322
+ else
323
+ raise AttributeNotImplemented, "Unable to find a parser for property `#{method}'"
324
+ end
325
+ end
303
326
 
304
- # The property is not supported nor defined.
327
+ def delegate_method_to_parsers(method, *args, &block)
328
+ if parsers.empty?
329
+ raise ParserError, "Unable to select a parser because the Record is empty"
330
+ elsif (parser = select_parser { |p| p.respond_to?(method) })
331
+ parser.send(method, *args, &block)
305
332
  else
306
- raise PropertyNotAvailable, "Unable to find a parser for `#{method}'"
333
+ nil
307
334
  end
308
335
  end
309
336
 
@@ -325,34 +352,31 @@ module Whois
325
352
  # parser.parsers
326
353
  # # => [Whois::Record::Parser::WhoisBarCom, Whois::Record::Parser::WhoisFooCom]
327
354
  #
328
- # @see Whois::Record::Parser#select_parser
329
- #
355
+ # @api private
330
356
  def init_parsers
331
357
  record.parts.reverse.map { |part| self.class.parser_for(part) }
332
358
  end
333
359
 
334
- # Selects the first parser in {#parsers}
335
- # where given property matches <tt>status</tt>.
336
- #
337
- # @param [Symbol] property The property to search for.
338
- # @param [Symbol] status The status value.
360
+ # Selects the first parser in {#parsers} where blocks evaluates to true.
339
361
  #
340
362
  # @return [Whois::Record::Parser::Base]
341
- # The parser which satisfies given requirement.
363
+ # The parser for which the block returns true.
342
364
  # @return [nil]
343
365
  # If the parser wasn't found.
344
366
  #
367
+ # @yield [parser]
368
+ #
345
369
  # @example
346
370
  #
347
- # select_parser(:nameservers)
371
+ # select_parser { |parser| parser.class.property_state?(:nameserver, :any) }
348
372
  # # => #<Whois::Record::Parser::WhoisExampleCom>
349
- #
350
- # select_parser(:nameservers, :supported)
373
+ # select_parser { |parser| parser.class.property_state?(:nameservers, PROPERTY_STATE_SUPPORTED) }
351
374
  # # => nil
352
375
  #
353
- def select_parser(property, status = :any)
376
+ # @api private
377
+ def select_parser(&block)
354
378
  parsers.each do |parser|
355
- return parser if parser.class.property_registered?(property, status)
379
+ return parser if block.call(parser)
356
380
  end
357
381
  nil
358
382
  end