whois-parser 0.0.1 → 1.0.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -0
  3. data/CHANGELOG.md +20 -0
  4. data/CONTRIBUTING.md +40 -0
  5. data/LICENSE.txt +17 -18
  6. data/README.md +6 -24
  7. data/lib/whois/parser/contact.rb +56 -0
  8. data/lib/whois/parser/errors.rb +46 -0
  9. data/lib/whois/parser/nameserver.rb +39 -0
  10. data/lib/whois/parser/registrar.rb +25 -0
  11. data/lib/whois/parser/super_struct.rb +53 -0
  12. data/lib/whois/parser/version.rb +3 -2
  13. data/lib/whois/parser.rb +407 -3
  14. data/lib/whois/parser_extensions/whois.rb +78 -0
  15. data/lib/whois/parser_extensions/whois_record.rb +222 -0
  16. data/lib/whois/parser_extensions.rb +9 -0
  17. data/lib/whois/parsers/base.rb +412 -0
  18. data/lib/whois/parsers/base_afilias.rb +139 -0
  19. data/lib/whois/parsers/base_afilias2.rb +140 -0
  20. data/lib/whois/parsers/base_cocca.rb +97 -0
  21. data/lib/whois/parsers/base_cocca2.rb +91 -0
  22. data/lib/whois/parsers/base_icann_compliant.rb +150 -0
  23. data/lib/whois/parsers/base_icb.rb +92 -0
  24. data/lib/whois/parsers/base_iisse.rb +113 -0
  25. data/lib/whois/parsers/base_nic_fr.rb +169 -0
  26. data/lib/whois/parsers/base_shared1.rb +108 -0
  27. data/lib/whois/parsers/base_shared2.rb +127 -0
  28. data/lib/whois/parsers/base_shared3.rb +127 -0
  29. data/lib/whois/parsers/base_verisign.rb +106 -0
  30. data/lib/whois/parsers/base_whoisd.rb +145 -0
  31. data/lib/whois/parsers/blank.rb +35 -0
  32. data/lib/whois/parsers/capetown-whois.registry.net.za.rb +25 -0
  33. data/lib/whois/parsers/ccwhois.ksregistry.net.rb +25 -0
  34. data/lib/whois/parsers/ccwhois.verisign-grs.com.rb +25 -0
  35. data/lib/whois/parsers/durban-whois.registry.net.za.rb +25 -0
  36. data/lib/whois/parsers/example.rb +163 -0
  37. data/lib/whois/parsers/joburg-whois.registry.net.za.rb +25 -0
  38. data/lib/whois/parsers/kero.yachay.pe.rb +86 -0
  39. data/lib/whois/parsers/org-whois.registry.net.za.rb +25 -0
  40. data/lib/whois/parsers/tvwhois.verisign-grs.com.rb +25 -0
  41. data/lib/whois/parsers/whois.1und1.info.rb +28 -0
  42. data/lib/whois/parsers/whois.35.com.rb +23 -0
  43. data/lib/whois/parsers/whois.aeda.net.ae.rb +64 -0
  44. data/lib/whois/parsers/whois.aero.rb +58 -0
  45. data/lib/whois/parsers/whois.afilias-grs.info.rb +21 -0
  46. data/lib/whois/parsers/whois.afilias.net.rb +41 -0
  47. data/lib/whois/parsers/whois.ai.rb +62 -0
  48. data/lib/whois/parsers/whois.amnic.net.rb +79 -0
  49. data/lib/whois/parsers/whois.ascio.com.rb +29 -0
  50. data/lib/whois/parsers/whois.ati.tn.rb +116 -0
  51. data/lib/whois/parsers/whois.audns.net.au.rb +118 -0
  52. data/lib/whois/parsers/whois.ax.rb +64 -0
  53. data/lib/whois/parsers/whois.biz.rb +25 -0
  54. data/lib/whois/parsers/whois.bnnic.bn.rb +75 -0
  55. data/lib/whois/parsers/whois.cat.rb +75 -0
  56. data/lib/whois/parsers/whois.cctld.by.rb +94 -0
  57. data/lib/whois/parsers/whois.cctld.uz.rb +79 -0
  58. data/lib/whois/parsers/whois.centralnic.com.rb +140 -0
  59. data/lib/whois/parsers/whois.cira.ca.rb +192 -0
  60. data/lib/whois/parsers/whois.cmc.iq.rb +25 -0
  61. data/lib/whois/parsers/whois.cnnic.cn.rb +108 -0
  62. data/lib/whois/parsers/whois.co.ca.rb +74 -0
  63. data/lib/whois/parsers/whois.co.pl.rb +82 -0
  64. data/lib/whois/parsers/whois.co.ug.rb +82 -0
  65. data/lib/whois/parsers/whois.comlaude.com.rb +113 -0
  66. data/lib/whois/parsers/whois.corporatedomains.com.rb +28 -0
  67. data/lib/whois/parsers/whois.denic.de.rb +164 -0
  68. data/lib/whois/parsers/whois.dk-hostmaster.dk.rb +88 -0
  69. data/lib/whois/parsers/whois.dns.be.rb +120 -0
  70. data/lib/whois/parsers/whois.dns.hr.rb +97 -0
  71. data/lib/whois/parsers/whois.dns.lu.rb +126 -0
  72. data/lib/whois/parsers/whois.dns.pl.rb +151 -0
  73. data/lib/whois/parsers/whois.dns.pt.rb +77 -0
  74. data/lib/whois/parsers/whois.domain-registry.nl.rb +123 -0
  75. data/lib/whois/parsers/whois.domain.kg.rb +76 -0
  76. data/lib/whois/parsers/whois.domainregistry.ie.rb +121 -0
  77. data/lib/whois/parsers/whois.domreg.lt.rb +68 -0
  78. data/lib/whois/parsers/whois.donuts.co.rb +61 -0
  79. data/lib/whois/parsers/whois.dot.cf.rb +71 -0
  80. data/lib/whois/parsers/whois.dot.tk.rb +70 -0
  81. data/lib/whois/parsers/whois.dotgov.gov.rb +61 -0
  82. data/lib/whois/parsers/whois.dotmobiregistry.net.rb +21 -0
  83. data/lib/whois/parsers/whois.dotpostregistry.net.rb +25 -0
  84. data/lib/whois/parsers/whois.dreamhost.com.rb +23 -0
  85. data/lib/whois/parsers/whois.educause.edu.rb +200 -0
  86. data/lib/whois/parsers/whois.eenet.ee.rb +72 -0
  87. data/lib/whois/parsers/whois.enom.com.rb +34 -0
  88. data/lib/whois/parsers/whois.eu.org.rb +58 -0
  89. data/lib/whois/parsers/whois.eu.rb +130 -0
  90. data/lib/whois/parsers/whois.fi.rb +117 -0
  91. data/lib/whois/parsers/whois.gandi.net.rb +30 -0
  92. data/lib/whois/parsers/whois.gg.rb +31 -0
  93. data/lib/whois/parsers/whois.godaddy.com.rb +112 -0
  94. data/lib/whois/parsers/whois.gov.za.rb +60 -0
  95. data/lib/whois/parsers/whois.hkirc.hk.rb +70 -0
  96. data/lib/whois/parsers/whois.iana.org.rb +102 -0
  97. data/lib/whois/parsers/whois.iis.nu.rb +26 -0
  98. data/lib/whois/parsers/whois.iis.se.rb +26 -0
  99. data/lib/whois/parsers/whois.in.ua.rb +75 -0
  100. data/lib/whois/parsers/whois.inregistry.net.rb +27 -0
  101. data/lib/whois/parsers/whois.isnic.is.rb +70 -0
  102. data/lib/whois/parsers/whois.isoc.org.il.rb +75 -0
  103. data/lib/whois/parsers/whois.ja.net.rb +75 -0
  104. data/lib/whois/parsers/whois.je.rb +25 -0
  105. data/lib/whois/parsers/whois.jprs.jp.rb +103 -0
  106. data/lib/whois/parsers/whois.kenic.or.ke.rb +91 -0
  107. data/lib/whois/parsers/whois.kr.rb +79 -0
  108. data/lib/whois/parsers/whois.markmonitor.com.rb +36 -0
  109. data/lib/whois/parsers/whois.monic.mo.rb +83 -0
  110. data/lib/whois/parsers/whois.museum.rb +79 -0
  111. data/lib/whois/parsers/whois.mynic.my.rb +72 -0
  112. data/lib/whois/parsers/whois.na-nic.com.na.rb +21 -0
  113. data/lib/whois/parsers/whois.nc.rb +122 -0
  114. data/lib/whois/parsers/whois.netcom.cm.rb +26 -0
  115. data/lib/whois/parsers/whois.networksolutions.com.rb +37 -0
  116. data/lib/whois/parsers/whois.nic.ac.rb +25 -0
  117. data/lib/whois/parsers/whois.nic.af.rb +25 -0
  118. data/lib/whois/parsers/whois.nic.ag.rb +21 -0
  119. data/lib/whois/parsers/whois.nic.as.rb +63 -0
  120. data/lib/whois/parsers/whois.nic.asia.rb +107 -0
  121. data/lib/whois/parsers/whois.nic.at.rb +64 -0
  122. data/lib/whois/parsers/whois.nic.bj.rb +126 -0
  123. data/lib/whois/parsers/whois.nic.bo.rb +73 -0
  124. data/lib/whois/parsers/whois.nic.cd.rb +34 -0
  125. data/lib/whois/parsers/whois.nic.ch.rb +109 -0
  126. data/lib/whois/parsers/whois.nic.ci.rb +70 -0
  127. data/lib/whois/parsers/whois.nic.cl.rb +71 -0
  128. data/lib/whois/parsers/whois.nic.co.rb +25 -0
  129. data/lib/whois/parsers/whois.nic.college.rb +25 -0
  130. data/lib/whois/parsers/whois.nic.coop.rb +70 -0
  131. data/lib/whois/parsers/whois.nic.cx.rb +25 -0
  132. data/lib/whois/parsers/whois.nic.cz.rb +42 -0
  133. data/lib/whois/parsers/whois.nic.design.rb +25 -0
  134. data/lib/whois/parsers/whois.nic.dm.rb +25 -0
  135. data/lib/whois/parsers/whois.nic.dz.rb +58 -0
  136. data/lib/whois/parsers/whois.nic.ec.rb +34 -0
  137. data/lib/whois/parsers/whois.nic.es.rb +105 -0
  138. data/lib/whois/parsers/whois.nic.fo.rb +43 -0
  139. data/lib/whois/parsers/whois.nic.fr.rb +25 -0
  140. data/lib/whois/parsers/whois.nic.gd.rb +31 -0
  141. data/lib/whois/parsers/whois.nic.gl.rb +25 -0
  142. data/lib/whois/parsers/whois.nic.gs.rb +31 -0
  143. data/lib/whois/parsers/whois.nic.hn.rb +25 -0
  144. data/lib/whois/parsers/whois.nic.ht.rb +25 -0
  145. data/lib/whois/parsers/whois.nic.hu.rb +78 -0
  146. data/lib/whois/parsers/whois.nic.im.rb +66 -0
  147. data/lib/whois/parsers/whois.nic.io.rb +48 -0
  148. data/lib/whois/parsers/whois.nic.ir.rb +66 -0
  149. data/lib/whois/parsers/whois.nic.it.rb +159 -0
  150. data/lib/whois/parsers/whois.nic.jobs.rb +25 -0
  151. data/lib/whois/parsers/whois.nic.ki.rb +25 -0
  152. data/lib/whois/parsers/whois.nic.kz.rb +67 -0
  153. data/lib/whois/parsers/whois.nic.la.rb +25 -0
  154. data/lib/whois/parsers/whois.nic.li.rb +64 -0
  155. data/lib/whois/parsers/whois.nic.lk.rb +109 -0
  156. data/lib/whois/parsers/whois.nic.lv.rb +65 -0
  157. data/lib/whois/parsers/whois.nic.ly.rb +76 -0
  158. data/lib/whois/parsers/whois.nic.md.rb +94 -0
  159. data/lib/whois/parsers/whois.nic.me.rb +85 -0
  160. data/lib/whois/parsers/whois.nic.mg.rb +31 -0
  161. data/lib/whois/parsers/whois.nic.ms.rb +25 -0
  162. data/lib/whois/parsers/whois.nic.mu.rb +25 -0
  163. data/lib/whois/parsers/whois.nic.mx.rb +79 -0
  164. data/lib/whois/parsers/whois.nic.name.rb +68 -0
  165. data/lib/whois/parsers/whois.nic.net.ng.rb +27 -0
  166. data/lib/whois/parsers/whois.nic.net.sa.rb +70 -0
  167. data/lib/whois/parsers/whois.nic.net.sb.rb +31 -0
  168. data/lib/whois/parsers/whois.nic.nf.rb +25 -0
  169. data/lib/whois/parsers/whois.nic.org.uy.rb +75 -0
  170. data/lib/whois/parsers/whois.nic.pm.rb +25 -0
  171. data/lib/whois/parsers/whois.nic.pr.rb +84 -0
  172. data/lib/whois/parsers/whois.nic.priv.at.rb +62 -0
  173. data/lib/whois/parsers/whois.nic.pw.rb +25 -0
  174. data/lib/whois/parsers/whois.nic.re.rb +25 -0
  175. data/lib/whois/parsers/whois.nic.sh.rb +25 -0
  176. data/lib/whois/parsers/whois.nic.sl.rb +76 -0
  177. data/lib/whois/parsers/whois.nic.sm.rb +76 -0
  178. data/lib/whois/parsers/whois.nic.sn.rb +113 -0
  179. data/lib/whois/parsers/whois.nic.so.rb +70 -0
  180. data/lib/whois/parsers/whois.nic.space.rb +25 -0
  181. data/lib/whois/parsers/whois.nic.st.rb +72 -0
  182. data/lib/whois/parsers/whois.nic.tc.rb +25 -0
  183. data/lib/whois/parsers/whois.nic.tech.rb +25 -0
  184. data/lib/whois/parsers/whois.nic.tel.rb +25 -0
  185. data/lib/whois/parsers/whois.nic.tl.rb +25 -0
  186. data/lib/whois/parsers/whois.nic.tm.rb +31 -0
  187. data/lib/whois/parsers/whois.nic.tr.rb +159 -0
  188. data/lib/whois/parsers/whois.nic.travel.rb +25 -0
  189. data/lib/whois/parsers/whois.nic.uk.rb +177 -0
  190. data/lib/whois/parsers/whois.nic.us.rb +25 -0
  191. data/lib/whois/parsers/whois.nic.ve.rb +87 -0
  192. data/lib/whois/parsers/whois.nic.wf.rb +25 -0
  193. data/lib/whois/parsers/whois.nic.xxx.rb +42 -0
  194. data/lib/whois/parsers/whois.nic.xyz.rb +25 -0
  195. data/lib/whois/parsers/whois.norid.no.rb +61 -0
  196. data/lib/whois/parsers/whois.pairnic.com.rb +28 -0
  197. data/lib/whois/parsers/whois.pandi.or.id.rb +25 -0
  198. data/lib/whois/parsers/whois.pir.org.rb +90 -0
  199. data/lib/whois/parsers/whois.pnina.ps.rb +31 -0
  200. data/lib/whois/parsers/whois.register.bg.rb +83 -0
  201. data/lib/whois/parsers/whois.register.com.rb +30 -0
  202. data/lib/whois/parsers/whois.register.si.rb +73 -0
  203. data/lib/whois/parsers/whois.registre.ma.rb +63 -0
  204. data/lib/whois/parsers/whois.registro.br.rb +73 -0
  205. data/lib/whois/parsers/whois.registry.gy.rb +25 -0
  206. data/lib/whois/parsers/whois.registry.hm.rb +72 -0
  207. data/lib/whois/parsers/whois.registry.net.za.rb +139 -0
  208. data/lib/whois/parsers/whois.registry.om.rb +40 -0
  209. data/lib/whois/parsers/whois.registry.qa.rb +25 -0
  210. data/lib/whois/parsers/whois.ripe.net.rb +68 -0
  211. data/lib/whois/parsers/whois.rnids.rs.rb +134 -0
  212. data/lib/whois/parsers/whois.rotld.ro.rb +65 -0
  213. data/lib/whois/parsers/whois.rrpproxy.net.rb +32 -0
  214. data/lib/whois/parsers/whois.safenames.net.rb +48 -0
  215. data/lib/whois/parsers/whois.schlund.info.rb +34 -0
  216. data/lib/whois/parsers/whois.sgnic.sg.rb +87 -0
  217. data/lib/whois/parsers/whois.sk-nic.sk.rb +101 -0
  218. data/lib/whois/parsers/whois.smallregistry.net.rb +131 -0
  219. data/lib/whois/parsers/whois.srs.net.nz.rb +159 -0
  220. data/lib/whois/parsers/whois.sx.rb +127 -0
  221. data/lib/whois/parsers/whois.tcinet.ru.rb +114 -0
  222. data/lib/whois/parsers/whois.thnic.co.th.rb +79 -0
  223. data/lib/whois/parsers/whois.tld.ee.rb +134 -0
  224. data/lib/whois/parsers/whois.tld.sy.rb +34 -0
  225. data/lib/whois/parsers/whois.tonic.to.rb +86 -0
  226. data/lib/whois/parsers/whois.tucows.com.rb +28 -0
  227. data/lib/whois/parsers/whois.twnic.net.tw.rb +72 -0
  228. data/lib/whois/parsers/whois.tznic.or.tz.rb +25 -0
  229. data/lib/whois/parsers/whois.ua.rb +240 -0
  230. data/lib/whois/parsers/whois.udag.net.rb +28 -0
  231. data/lib/whois/parsers/whois.uniregistry.net.rb +61 -0
  232. data/lib/whois/parsers/whois.usp.ac.fj.rb +72 -0
  233. data/lib/whois/parsers/whois.verisign-grs.com.rb +49 -0
  234. data/lib/whois/parsers/whois.website.ws.rb +74 -0
  235. data/lib/whois/parsers/whois.wildwestdomains.com.rb +37 -0
  236. data/lib/whois/parsers/whois.yoursrs.com.rb +125 -0
  237. data/lib/whois/parsers/whois.za.net.rb +72 -0
  238. data/lib/whois/parsers/whois.za.org.rb +72 -0
  239. data/lib/whois/parsers/whois1.nic.bi.rb +25 -0
  240. data/lib/whois/parsers/za_central_registry.rb +68 -0
  241. data/lib/whois/parsers.rb +4 -0
  242. data/lib/whois/safe_record.rb +169 -0
  243. data/lib/whois/scanners/base.rb +116 -0
  244. data/lib/whois/scanners/base_afilias.rb +51 -0
  245. data/lib/whois/scanners/base_cocca2.rb +43 -0
  246. data/lib/whois/scanners/base_icann_compliant.rb +45 -0
  247. data/lib/whois/scanners/base_iisse.rb +36 -0
  248. data/lib/whois/scanners/base_shared1.rb +31 -0
  249. data/lib/whois/scanners/base_shared2.rb +35 -0
  250. data/lib/whois/scanners/base_shared3.rb +37 -0
  251. data/lib/whois/scanners/base_whoisd.rb +44 -0
  252. data/lib/whois/scanners/iana.rb +89 -0
  253. data/lib/whois/scanners/scannable.rb +65 -0
  254. data/lib/whois/scanners/verisign.rb +100 -0
  255. data/lib/whois/scanners/whois.ati.tn.rb +32 -0
  256. data/lib/whois/scanners/whois.audns.net.au.rb +25 -0
  257. data/lib/whois/scanners/whois.cctld.by.rb +35 -0
  258. data/lib/whois/scanners/whois.centralnic.com.rb +32 -0
  259. data/lib/whois/scanners/whois.cira.ca.rb +72 -0
  260. data/lib/whois/scanners/whois.cnnic.cn.rb +42 -0
  261. data/lib/whois/scanners/whois.denic.de.rb +96 -0
  262. data/lib/whois/scanners/whois.dns.hr.rb +25 -0
  263. data/lib/whois/scanners/whois.domainregistry.ie.rb +46 -0
  264. data/lib/whois/scanners/whois.fi.rb +39 -0
  265. data/lib/whois/scanners/whois.nc.rb +32 -0
  266. data/lib/whois/scanners/whois.nic.cz.rb +22 -0
  267. data/lib/whois/scanners/whois.nic.it.rb +92 -0
  268. data/lib/whois/scanners/whois.pir.org.rb +17 -0
  269. data/lib/whois/scanners/whois.registry.net.za.rb +92 -0
  270. data/lib/whois/scanners/whois.rnids.rs.rb +52 -0
  271. data/lib/whois/scanners/whois.smallregistry.net.rb +50 -0
  272. data/lib/whois/scanners/whois.srs.net.nz.rb +23 -0
  273. data/lib/whois/scanners/whois.sx.rb +37 -0
  274. data/lib/whois/scanners/whois.tld.ee.rb +47 -0
  275. data/lib/whois/scanners/whois.tucows.com.rb +23 -0
  276. data/lib/whois/scanners/whois.yoursrs.com.rb +24 -0
  277. data/lib/whois-parser.rb +10 -0
  278. data/whois-parser.gemspec +37 -19
  279. metadata +318 -20
  280. data/.gitignore +0 -14
  281. data/Gemfile +0 -4
  282. data/Rakefile +0 -2
@@ -0,0 +1,9 @@
1
+ require_relative 'parser_extensions/whois'
2
+ require_relative 'parser_extensions/whois_record'
3
+
4
+ Whois.class_eval do
5
+ include Whois::ParserExtensions::Whois
6
+ end
7
+ Whois::Record.class_eval do
8
+ include Whois::ParserExtensions::WhoisRecord
9
+ end
@@ -0,0 +1,412 @@
1
+ #--
2
+ # Ruby Whois
3
+ #
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
+ #
6
+ # Copyright (c) 2009-2015 Simone Carletti <weppos@weppos.net>
7
+ #++
8
+
9
+
10
+ require 'time'
11
+ require_relative '../parser/contact'
12
+ require_relative '../parser/registrar'
13
+ require_relative '../parser/nameserver'
14
+ require_relative '../scanners/scannable'
15
+
16
+
17
+ module Whois
18
+ class Parsers
19
+
20
+ # Represents the abstract base parser class for all
21
+ # server-specific parser implementations.
22
+ #
23
+ # NOTE. This class is for the most part auto-generated via meta programming.
24
+ # This is the reason why RDoc can't detect and document all available methods.
25
+ #
26
+ # @abstract
27
+ #
28
+ class Base
29
+
30
+ class_attribute :_properties
31
+ self._properties = {}
32
+
33
+ # Returns the status for the +property+ passed as symbol.
34
+ #
35
+ # @param [Symbol] property
36
+ # @return [Symbol, nil]
37
+ #
38
+ # @example Undefined property
39
+ # property_state(:disclaimer)
40
+ # # => nil
41
+ #
42
+ # @example Defined property
43
+ # property_register(:disclaimer, Parser::PROPERTY_STATE_SUPPORTED) {}
44
+ # property_state(:disclaimer)
45
+ # # => :supported
46
+ #
47
+ def self.property_state(property)
48
+ self._properties[property]
49
+ end
50
+
51
+ # Check if the +property+ passed as symbol
52
+ # is registered in the registry for current parser.
53
+ #
54
+ # @param [Symbol] property
55
+ # @param [Symbol] status
56
+ # @return [Boolean]
57
+ #
58
+ # @example Not-registered property
59
+ # property_state?(:disclaimer)
60
+ # # => false
61
+ #
62
+ # @example Registered property
63
+ # property_register(:disclaimer) {}
64
+ # property_state?(:disclaimer)
65
+ # # => true
66
+ #
67
+ def self.property_state?(property, status = :any)
68
+ if status == :any
69
+ self._properties.key?(property)
70
+ else
71
+ self._properties[property] == status
72
+ end
73
+ end
74
+
75
+ # Registers a <tt>property</tt> in the registry.
76
+ #
77
+ # @param [Symbol] property
78
+ # @param [Symbol] status
79
+ #
80
+ # @return [void]
81
+ #
82
+ def self.property_register(property, status)
83
+ self._properties = self._properties.merge({ property => status })
84
+ end
85
+
86
+
87
+ # Registers a <tt>property</tt> as "not implemented"
88
+ # and defines the corresponding private _property_PROPERTY method.
89
+ #
90
+ # A "not implemented" property always raises a <tt>AttributeNotImplemented</tt> error
91
+ # when the property method is called.
92
+ #
93
+ # @param [Symbol] property
94
+ # @return [void]
95
+ #
96
+ # @example Defining a not implemented property
97
+ # # Defines a not implemented property called :disclaimer.
98
+ # property_not_implemented(:disclaimer)
99
+ #
100
+ def self.property_not_implemented(property)
101
+ property_register(property, Parser::PROPERTY_STATE_NOT_IMPLEMENTED)
102
+
103
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
104
+ def _property_#{property}(*args)
105
+ raise AttributeNotImplemented
106
+ end
107
+
108
+ private :_property_#{property}
109
+ RUBY
110
+ end
111
+
112
+ # Registers a <tt>property</tt> as "not supported"
113
+ # and defines the corresponding private _property_PROPERTY method.
114
+ #
115
+ # A "not supported" property always raises a <tt>AttributeNotSupported</tt> error
116
+ # when the property method is called.
117
+ #
118
+ # @param [Symbol] property
119
+ # @return [void]
120
+ #
121
+ # @example Defining an unsupported property
122
+ # # Defines an unsupported property called :disclaimer.
123
+ # property_not_supported(:disclaimer)
124
+ #
125
+ def self.property_not_supported(property)
126
+ property_register(property, Parser::PROPERTY_STATE_NOT_SUPPORTED)
127
+
128
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
129
+ def _property_#{property}(*args)
130
+ raise AttributeNotSupported
131
+ end
132
+
133
+ private :_property_#{property}
134
+ RUBY
135
+ end
136
+
137
+ # Registers a <tt>property</tt> as "supported"
138
+ # and defines the corresponding private _property_PROPERTY method.
139
+ #
140
+ # @param [Symbol] property
141
+ # @return [void]
142
+ #
143
+ # @example Defining a supported property
144
+ # # Defines a supported property called :disclaimer.
145
+ # property_supported(:disclaimer) do
146
+ # ...
147
+ # end
148
+ #
149
+ def self.property_supported(property, &block)
150
+ property_register(property, Parser::PROPERTY_STATE_SUPPORTED)
151
+
152
+ define_method("_property_#{property}", &block)
153
+ private :"_property_#{property}"
154
+ end
155
+
156
+ # Checks if the <tt>property</tt> passed as symbol
157
+ # is supported by the current parser.
158
+ #
159
+ # @param [Symbol] property The name of the property to check.
160
+ # @return [Boolean]
161
+ #
162
+ def property_supported?(property)
163
+ self.class.property_state?(property, Parser::PROPERTY_STATE_SUPPORTED)
164
+ end
165
+
166
+ # Parses a timestamp, returning nil for invalid input
167
+ #
168
+ # @param [String] timestamp The timestamp to parse
169
+ # @return [Nil] if the timestamp can't be parsed
170
+ # @return [Time]
171
+ #
172
+ def self.parse_time(timestamp)
173
+ return unless timestamp.is_a?(String) && !timestamp.empty?
174
+ Time.parse(timestamp).change(usec: 0)
175
+ rescue ArgumentError
176
+ nil
177
+ end
178
+
179
+ # @return [Whois::Record::Part] The part referenced by this parser.
180
+ attr_reader :part
181
+
182
+ # Initializes a new parser with given +part+.
183
+ #
184
+ # @param [Whois::Record::Part] part
185
+ #
186
+ def initialize(part)
187
+ @part = part
188
+ @cached_properties = {}
189
+ end
190
+
191
+
192
+ # This is an internal method primary used as a common access point
193
+ # to get the content to be parsed as a string.
194
+ #
195
+ # The main reason behind this method is because, in the past,
196
+ # the internal representation of the data to be parsed changed
197
+ # several times, and I always had to rewrite all single parsers
198
+ # in order to reflect these changes.
199
+ # Now, as far as the parser access the data via the content method,
200
+ # there's no need to change each single implementation
201
+ # in case the content source changes.
202
+ #
203
+ # That said, the only constraints about this method
204
+ # is to return the data to be parsed as string.
205
+ #
206
+ # @return [String] The part body.
207
+ def content
208
+ part.body
209
+ end
210
+
211
+ # Check if the parser respond to +symbol+
212
+ # and calls the method if defined.
213
+ # The method referenced by the +symbol+
214
+ # is supposed to be a question? method and to return a boolean.
215
+ #
216
+ # @param [Symbol] symbol
217
+ # @return [Boolean]
218
+ #
219
+ # @example
220
+ # is(:response_throttled?)
221
+ # # => true
222
+ #
223
+ # @api private
224
+ def is(symbol)
225
+ respond_to?(symbol) && send(symbol)
226
+ end
227
+
228
+ # @api private
229
+ def validate!
230
+ raise ResponseIsThrottled if is(:response_throttled?)
231
+ raise ResponseIsUnavailable if is(:response_unavailable?)
232
+ end
233
+
234
+
235
+ # @!group Properties
236
+
237
+ Parser::PROPERTIES.each do |property|
238
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
239
+ def #{property}(*args)
240
+ handle_property(:#{property}, *args)
241
+ end
242
+ RUBY
243
+
244
+ property_not_implemented(property)
245
+ end
246
+
247
+ # @!endgroup
248
+
249
+
250
+ # @!group Methods
251
+
252
+ # Collects and returns all the available contacts.
253
+ #
254
+ # @return [Array<Parser::Contact>]
255
+ #
256
+ # @see Whois::Record#contacts
257
+ # @see Whois::Parser#contacts
258
+ #
259
+ def contacts
260
+ [:registrant_contacts, :admin_contacts, :technical_contacts].inject([]) do |contacts, property|
261
+ contacts += send(property) if property_supported?(property)
262
+ contacts
263
+ end
264
+ end
265
+
266
+ # @!endgroup
267
+
268
+
269
+ # @!group Response
270
+
271
+ # Checks whether the content of this part is different than +other+.
272
+ #
273
+ # Comparing a WHOIS response is not as trivial as you may think.
274
+ # WHOIS servers can inject into the WHOIS response strings
275
+ # that changes at every request, such as the timestamp the request
276
+ # was generated or the number of requests left for your current IP.
277
+ #
278
+ # These strings causes a simple equal comparison to fail even if
279
+ # the registry data is the same.
280
+ #
281
+ # This method should provide a bulletproof way to detect
282
+ # whether this record changed compared with +other+.
283
+ #
284
+ # @param [Base] other The other parser instance to compare.
285
+ # @return [Boolean]
286
+ #
287
+ # @see Whois::Record#changed?
288
+ # @see Whois::Parser#changed?
289
+ #
290
+ def changed?(other)
291
+ !unchanged?(other)
292
+ end
293
+
294
+ # The opposite of {#changed?}.
295
+ #
296
+ # @param [Base] other The other parser instance to compare.
297
+ # @return [Boolean]
298
+ #
299
+ # @see Whois::Record#unchanged?
300
+ # @see Whois::Parser#unchanged?
301
+ #
302
+ def unchanged?(other)
303
+ unless other.is_a?(self.class)
304
+ raise(ArgumentError, "Can't compare `#{self.class}' with `#{other.class}'")
305
+ end
306
+
307
+ equal?(other) ||
308
+ content_for_scanner == other.content_for_scanner
309
+ end
310
+
311
+
312
+ # Checks whether this is an incomplete response.
313
+ #
314
+ # @return [Boolean]
315
+ #
316
+ # @abstract This method is just a stub.
317
+ # Define it in your parser class.
318
+ #
319
+ # @see Whois::Record#response_incomplete?
320
+ # @see Whois::Parser#response_incomplete?
321
+ #
322
+ def response_incomplete?
323
+ end
324
+
325
+ # Checks whether this is a throttle response.
326
+ #
327
+ # @return [Boolean]
328
+ #
329
+ # @abstract This method is just a stub.
330
+ # Define it in your parser class.
331
+ #
332
+ # @see Whois::Record#response_throttled?
333
+ # @see Whois::Parser#response_throttled?
334
+ #
335
+ def response_throttled?
336
+ end
337
+
338
+ # Checks whether this response contains a message
339
+ # that can be reconducted to a "WHOIS Server Unavailable" status.
340
+ #
341
+ # Some WHOIS servers returns error messages
342
+ # when they are experiencing failures.
343
+ #
344
+ # @return [Boolean]
345
+ #
346
+ # @abstract This method is just a stub.
347
+ # Define it in your parser class.
348
+ #
349
+ # @see Whois::Record#response_unavailable?
350
+ # @see Whois::Parser#response_unavailable?
351
+ #
352
+ def response_unavailable?
353
+ end
354
+
355
+ # Let them be documented
356
+ undef response_incomplete?
357
+ undef response_throttled?
358
+ undef response_unavailable?
359
+
360
+ # @!endgroup
361
+
362
+
363
+ protected
364
+
365
+ def content_for_scanner
366
+ @content_for_scanner ||= content.to_s.gsub(/\r\n/, "\n")
367
+ end
368
+
369
+ def cached_properties_fetch(key)
370
+ if !@cached_properties.key?(key)
371
+ @cached_properties[key] = yield
372
+ end
373
+ @cached_properties[key]
374
+ end
375
+
376
+
377
+ private
378
+
379
+ def typecast(value, type)
380
+ if Array == type
381
+ Array.wrap(value)
382
+ else
383
+ value
384
+ end
385
+ end
386
+
387
+ def parse_time(timestamp)
388
+ self.class.parse_time(timestamp)
389
+ end
390
+
391
+ def handle_property(property, *args)
392
+ unless property_supported?(property)
393
+ return send(:"_property_#{property}", *args)
394
+ end
395
+
396
+ cached_properties_fetch(property) do
397
+ validate!
398
+ value = send(:"_property_#{property}", *args)
399
+
400
+ case property.to_s
401
+ when /_contacts$/, "nameservers"
402
+ typecast(value, Array)
403
+ else
404
+ value
405
+ end
406
+ end
407
+ end
408
+
409
+ end
410
+
411
+ end
412
+ end
@@ -0,0 +1,139 @@
1
+ #--
2
+ # Ruby Whois
3
+ #
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
+ #
6
+ # Copyright (c) 2009-2015 Simone Carletti <weppos@weppos.net>
7
+ #++
8
+
9
+
10
+ require_relative 'base'
11
+ require 'whois/scanners/base_afilias'
12
+
13
+
14
+ module Whois
15
+ class Parsers
16
+
17
+ # Base parser for Afilias servers.
18
+ #
19
+ # @abstract
20
+ class BaseAfilias < Base
21
+ include Scanners::Scannable
22
+
23
+ self.scanner = Scanners::BaseAfilias
24
+
25
+
26
+ property_supported :disclaimer do
27
+ node("field:disclaimer")
28
+ end
29
+
30
+
31
+ property_supported :domain do
32
+ node("Domain Name", &:downcase)
33
+ end
34
+
35
+ property_supported :domain_id do
36
+ node("Domain ID")
37
+ end
38
+
39
+
40
+ property_supported :status do
41
+ Array.wrap(node("Status"))
42
+ end
43
+
44
+ property_supported :available? do
45
+ !!node("status:available")
46
+ end
47
+
48
+ property_supported :registered? do
49
+ !available?
50
+ end
51
+
52
+
53
+ property_supported :created_on do
54
+ node("Created On") do |value|
55
+ parse_time(value)
56
+ end
57
+ end
58
+
59
+ property_supported :updated_on do
60
+ node("Last Updated On") do |value|
61
+ parse_time(value)
62
+ end
63
+ end
64
+
65
+ property_supported :expires_on do
66
+ node("Expiration Date") do |value|
67
+ parse_time(value)
68
+ end
69
+ end
70
+
71
+
72
+ property_supported :registrar do
73
+ node("Sponsoring Registrar") do |value|
74
+ id, name = decompose_registrar(value) ||
75
+ Whois.bug!(ParserError, "Unknown registrar format `#{value}'")
76
+
77
+ Parser::Registrar.new(
78
+ id: id,
79
+ name: name
80
+ )
81
+ end
82
+ end
83
+
84
+ property_supported :registrant_contacts do
85
+ build_contact("Registrant", Parser::Contact::TYPE_REGISTRANT)
86
+ end
87
+
88
+ property_supported :admin_contacts do
89
+ build_contact("Admin", Parser::Contact::TYPE_ADMINISTRATIVE)
90
+ end
91
+
92
+ property_supported :technical_contacts do
93
+ build_contact("Tech", Parser::Contact::TYPE_TECHNICAL)
94
+ end
95
+
96
+
97
+ property_supported :nameservers do
98
+ Array.wrap(node("Name Server")).reject(&:empty?).map do |name|
99
+ Parser::Nameserver.new(:name => name.downcase)
100
+ end
101
+ end
102
+
103
+
104
+ private
105
+
106
+ def build_contact(element, type)
107
+ node("#{element} ID") do
108
+ address = ["", "1", "2", "3"].
109
+ map { |i| node("#{element} Street#{i}") }.
110
+ delete_if { |i| i.nil? || i.empty? }.
111
+ join("\n")
112
+
113
+ Parser::Contact.new(
114
+ :type => type,
115
+ :id => node("#{element} ID"),
116
+ :name => node("#{element} Name"),
117
+ :organization => node("#{element} Organization"),
118
+ :address => address,
119
+ :city => node("#{element} City"),
120
+ :zip => node("#{element} Postal Code"),
121
+ :state => node("#{element} State/Province"),
122
+ :country_code => node("#{element} Country"),
123
+ :phone => node("#{element} Phone"),
124
+ :fax => node("#{element} FAX") || node("#{element} Fax"),
125
+ :email => node("#{element} Email")
126
+ )
127
+ end
128
+ end
129
+
130
+ def decompose_registrar(value)
131
+ if value =~ /(.+?) \((.+?)\)/
132
+ [$2, $1]
133
+ end
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+ end
@@ -0,0 +1,140 @@
1
+ #--
2
+ # Ruby Whois
3
+ #
4
+ # An intelligent pure Ruby WHOIS client and parser.
5
+ #
6
+ # Copyright (c) 2009-2015 Simone Carletti <weppos@weppos.net>
7
+ #++
8
+
9
+
10
+ require_relative 'base'
11
+ require 'whois/scanners/base_afilias'
12
+
13
+
14
+ module Whois
15
+ class Parsers
16
+
17
+ # Base parser for Afilias servers.
18
+ #
19
+ # @abstract
20
+ class BaseAfilias2 < Base
21
+ include Scanners::Scannable
22
+
23
+ self.scanner = Scanners::BaseAfilias
24
+
25
+
26
+ property_supported :disclaimer do
27
+ node("field:disclaimer")
28
+ end
29
+
30
+
31
+ property_supported :domain do
32
+ node("Domain Name", &:downcase)
33
+ end
34
+
35
+ property_supported :domain_id do
36
+ node("Domain ID")
37
+ end
38
+
39
+
40
+ property_supported :status do
41
+ Array.wrap(node("Domain Status"))
42
+ end
43
+
44
+ property_supported :available? do
45
+ !!node("status:available")
46
+ end
47
+
48
+ property_supported :registered? do
49
+ !available?
50
+ end
51
+
52
+
53
+ property_supported :created_on do
54
+ node("Creation Date") do |value|
55
+ parse_time(value)
56
+ end
57
+ end
58
+
59
+ property_supported :updated_on do
60
+ node("Updated Date") do |value|
61
+ parse_time(value)
62
+ end
63
+ end
64
+
65
+ property_supported :expires_on do
66
+ node("Registry Expiry Date") do |value|
67
+ parse_time(value)
68
+ end
69
+ end
70
+
71
+
72
+ property_supported :registrar do
73
+ node("Sponsoring Registrar") do |value|
74
+ id, name = decompose_registrar(value)
75
+
76
+ Parser::Registrar.new({
77
+ id: id,
78
+ name: name,
79
+ })
80
+ end
81
+ end
82
+
83
+ property_supported :registrant_contacts do
84
+ build_contact("Registrant", Parser::Contact::TYPE_REGISTRANT)
85
+ end
86
+
87
+ property_supported :admin_contacts do
88
+ build_contact("Admin", Parser::Contact::TYPE_ADMINISTRATIVE)
89
+ end
90
+
91
+ property_supported :technical_contacts do
92
+ build_contact("Tech", Parser::Contact::TYPE_TECHNICAL)
93
+ end
94
+
95
+
96
+ property_supported :nameservers do
97
+ Array.wrap(node("Name Server")).reject(&:empty?).map do |name|
98
+ Parser::Nameserver.new(:name => name.downcase)
99
+ end
100
+ end
101
+
102
+
103
+ private
104
+
105
+ def build_contact(element, type)
106
+ node("#{element} ID") do
107
+ address = ["", "1", "2", "3"].
108
+ map { |i| node("#{element} Street#{i}") }.
109
+ delete_if { |i| i.nil? || i.empty? }.
110
+ join("\n")
111
+
112
+ Parser::Contact.new(
113
+ :type => type,
114
+ :id => node("#{element} ID"),
115
+ :name => node("#{element} Name"),
116
+ :organization => node("#{element} Organization"),
117
+ :address => address,
118
+ :city => node("#{element} City"),
119
+ :zip => node("#{element} Postal Code"),
120
+ :state => node("#{element} State/Province"),
121
+ :country_code => node("#{element} Country"),
122
+ :phone => node("#{element} Phone"),
123
+ :fax => node("#{element} FAX") || node("#{element} Fax"),
124
+ :email => node("#{element} Email")
125
+ )
126
+ end
127
+ end
128
+
129
+ def decompose_registrar(value)
130
+ if value =~ /(.+?) \((.+?)\)/
131
+ [$2, $1]
132
+ else
133
+ [nil, value]
134
+ end
135
+ end
136
+
137
+ end
138
+
139
+ end
140
+ end