PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/whois/record/parser/whois.nic.uk.rb

http://github.com/weppos/whois
Ruby | 179 lines | 139 code | 18 blank | 22 comment | 10 complexity | 4c1d71bc86e6e2b494c64d6e7025a4e8 MD5 | raw file
Possible License(s): MIT
  1. #--
  2. # Ruby Whois
  3. #
  4. # An intelligent pure Ruby WHOIS client and parser.
  5. #
  6. # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
  7. #++
  8. require 'whois/record/parser/base'
  9. module Whois
  10. class Record
  11. class Parser
  12. # Parser for the whois.nic.uk server.
  13. #
  14. # @note This parser is just a stub and provides only a few basic methods
  15. # to check for domain availability and get domain status.
  16. # Please consider to contribute implementing missing methods.
  17. #
  18. # @see http://www.nominet.org.uk/other/whois/detailedinstruct/
  19. #
  20. class WhoisNicUk < Base
  21. # == Values for Status
  22. #
  23. # @see http://www.nominet.org.uk/registrars/systems/data/regstatus/
  24. # @see http://www.nominet.org.uk/registrants/maintain/renew/status/
  25. #
  26. property_supported :status do
  27. if content_for_scanner =~ /\s+Registration status:\s+(.+?)\n/
  28. case $1.downcase
  29. when "registered until expiry date."
  30. :registered
  31. when "registration request being processed."
  32. :registered
  33. when "renewal request being processed."
  34. :registered
  35. when "no longer required"
  36. :registered
  37. when "no registration status listed."
  38. :reserved
  39. # NEWSTATUS (redemption?)
  40. when "renewal required."
  41. :registered
  42. else
  43. Whois.bug!(ParserError, "Unknown status `#{$1}'.")
  44. end
  45. elsif invalid?
  46. :invalid
  47. else
  48. :available
  49. end
  50. end
  51. property_supported :available? do
  52. !!(content_for_scanner =~ /This domain name has not been registered/)
  53. end
  54. property_supported :registered? do
  55. !available?
  56. end
  57. property_supported :created_on do
  58. if content_for_scanner =~ /\s+Registered on:\s+(.+)\n/
  59. Time.parse($1)
  60. end
  61. end
  62. property_supported :updated_on do
  63. if content_for_scanner =~ /\s+Last updated:\s+(.+)\n/
  64. Time.parse($1)
  65. end
  66. end
  67. property_supported :expires_on do
  68. if content_for_scanner =~ /\s+Expiry date:\s+(.+)\n/
  69. Time.parse($1)
  70. end
  71. end
  72. # @see http://www.nic.uk/other/whois/instruct/
  73. property_supported :registrar do
  74. if content_for_scanner =~ /Registrar:\n((.+\n)+)\n/
  75. content = $1.strip
  76. id = name = org = url = nil
  77. if content =~ /Tag =/
  78. name, id = (content =~ /(.+) \[Tag = (.+)\]/) && [$1.strip, $2.strip]
  79. org, name = name.split(" t/a ")
  80. url = (content =~ /URL: (.+)/) && $1.strip
  81. elsif content =~ /This domain is registered directly with Nominet/
  82. name = "Nominet"
  83. org = "Nominet UK"
  84. url = "http://www.nic.uk/"
  85. end
  86. Record::Registrar.new(
  87. :id => id,
  88. :name => name || org,
  89. :organization => org,
  90. :url => url
  91. )
  92. end
  93. end
  94. property_supported :registrant_contacts do
  95. if content_for_scanner =~ /Registrant's address:\n((.+\n)+)\n/
  96. lines = $1.split("\n").map(&:strip)
  97. address = lines[0..-5]
  98. city = lines[-4]
  99. state = lines[-3]
  100. zip = lines[-2]
  101. country = lines[-1]
  102. Record::Contact.new(
  103. :type => Record::Contact::TYPE_REGISTRANT,
  104. :name => content_for_scanner[/Registrant:\n\s*(.+)\n/, 1],
  105. :address => address.join("\n"),
  106. :city => city,
  107. :state => state,
  108. :zip => zip,
  109. :country => country
  110. )
  111. end
  112. end
  113. property_supported :nameservers do
  114. if content_for_scanner =~ /Name servers:\n((.+\n)+)\n/
  115. $1.split("\n").reject { |value| value =~ /No name servers listed/ }.map do |line|
  116. name, ipv4, ipv6 = line.strip.split(/\s+/)
  117. Record::Nameserver.new(:name => name, :ipv4 => ipv4, :ipv6 => ipv6)
  118. end
  119. end
  120. end
  121. # Checks whether the response has been throttled.
  122. #
  123. # @return [Boolean]
  124. #
  125. # @example
  126. # The WHOIS query quota for 127.0.0.1 has been exceeded
  127. # and will be replenished in 50 seconds.
  128. #
  129. def response_throttled?
  130. !!(content_for_scanner =~ /The WHOIS query quota for .+ has been exceeded/)
  131. end
  132. # NEWPROPERTY
  133. def valid?
  134. cached_properties_fetch(:valid?) do
  135. !invalid?
  136. end
  137. end
  138. # NEWPROPERTY
  139. def invalid?
  140. cached_properties_fetch(:invalid?) do
  141. !!(content_for_scanner =~ /This domain cannot be registered/)
  142. end
  143. end
  144. # NEWPROPERTY
  145. # def suspended?
  146. # end
  147. end
  148. end
  149. end
  150. end