Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 145 lines (130 sloc) 3.663 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
#
# = Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
#
# Category:: Net
# Package:: Whois
# Author:: Simone Carletti <weppos@weppos.net>
# License:: MIT License
#
#--
#
#++


require 'core_ext'
require 'whois/version'
require 'whois/errors'
require 'whois/client'
require 'whois/server'
require 'whois/answer'


module Whois

  NAME = "Whois"
  GEM = "whois"
  AUTHORS = ["Simone Carletti <weppos@weppos.net>"]


  # Queries the right WHOIS server for <tt>qstring</tt> and returns
  # the response from the server.
  #
  # ==== Parameters
  #
  # qstring:: The String to be sent as query parameter.
  #
  # ==== Returns
  #
  # Whois::Answer:: The answer containing the response from the WHOIS server.
  #
  # ==== Examples
  #
  # Whois.query("google.com")
  # # => #<Whois::Answer>
  #
  # This is equivalent to
  #
  # Whois::Client.new.query("google.com")
  # # => #<Whois::Answer>
  #
  def self.query(qstring)
    Client.new.query(qstring)
  end

  # Checks whether the object represented by <tt>qstring</tt> is available.
  #
  # Warning: this method is only available if a Whois parser exists
  # for the top level domain of <tt>qstring</tt>.
  # If no parser exists for <tt>qstring</tt>, you'll receive a
  # warning message and the method will return <tt>nil</tt>.
  # This is a technical limitation. Browse the lib/whois/answer/parsers
  # folder to view all available parsers.
  #
  # ==== Parameters
  #
  # qstring:: The String to be sent as query parameter.
  # It is intended to be a domain name, otherwise this method
  # may return unexpected responses.
  #
  # ==== Returns
  #
  # Boolean
  #
  # ==== Examples
  #
  # Whois.available?("google.com")
  # # => false
  #
  # Whois.available?("google-is-not-available-try-again-later.com")
  # # => true
  #
  def self.available?(qstring)
    query(qstring).available?
  rescue ParserNotFound => e
    warn "This method is not supported for this kind of object.\n" +
          "Use Whois.query('#{qstring}') instead."
    nil
  end

  # Checks whether the object represented by <tt>qstring</tt> is registered.
  #
  # Warning: this method is only available if a Whois parser exists
  # for the top level domain of <tt>qstring</tt>.
  # If no parser exists for <tt>qstring</tt>, you'll receive a warning message
  # and the method will return <tt>nil</tt>.
  # This is a technical limitation. Browse the lib/whois/answer/parsers folder
  # to view all available parsers.
  #
  # ==== Parameters
  #
  # qstring:: The String to be sent as query parameter.
  # It is intended to be a domain name, otherwise this method
  # may return unexpected responses.
  #
  # ==== Returns
  #
  # Boolean
  #
  # ==== Examples
  #
  # Whois.registered?("google.com")
  # # => true
  #
  # Whois.registered?("google-is-not-available-try-again-later.com")
  # # => false
  #
  def self.registered?(qstring)
    query(qstring).registered?
  rescue ParserNotFound => e
    warn "This method is not supported for this kind of object.\n" +
          "Use Whois.query('#{qstring}') instead."
    nil
  end


  # See <tt>Whois#query</tt>.
  def self.whois(qstring)
    query(qstring)
  end


  def self.deprecate(message = nil) # :nodoc:
    message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
    warn("DEPRECATION WARNING: #{message}")
  end

  def self.bug!(error, message) # :nodoc:
    raise error, message.dup <<
      " Please report the issue at" <<
      " http://github.com/weppos/whois/issues"
  end

end
Something went wrong with that request. Please try again.