Sha256: 2019b4544d808c468fbabd8c3fce047ab92294c98e4387c4e6b729409c982b59

Contents?: true

Size: 1.43 KB

Versions: 10

Compression:

Stored size: 1.43 KB

Contents

#
# = Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
#
# Category::    Net
# Package::     Whois
# Author::      Simone Carletti <weppos@weppos.net>
# License::     MIT License
#
#--
#
#++


require 'socket'
require 'timeout'


module Whois

  class Client

    # The maximum time to run a whois query expressed in seconds
    DEFAULT_TIMEOUT = 10

    attr_accessor :timeout


    #
    # :call-seq:
    #   new { |client| ... } => client
    #   new(options = {}) { |client| ... } => client
    # 
    # Initializes a new Whois::Client with <tt>options</tt>.
    # 
    # If block is given, yields self.
    # 
    #   client = Whois::Client.new do |c|
    #     c.timeout = nil
    #   end
    #   client.query("google.com")
    #
    def initialize(options = {}, &block)
      self.timeout = options[:timeout] || DEFAULT_TIMEOUT
      yield(self) if block_given?
    end


    class Query # :nodoc
      # IPv6?
      # RPSL?
      # email?
      # NSIC?
      # ASP32?
      # IP?
      # domain?
      # network?
    end


    # Queries the right whois server for <tt>qstring</tt> and returns
    # a <tt>Whois::Answer</tt> instance containing the response from the server.
    #
    #   client.query("google.com")
    #   # => #<Whois::Answer>
    #
    def query(qstring)
      string = qstring.to_s
      Timeout::timeout(timeout) do
        @server = Server.guess(string)
        @server.query(string)
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
whois-1.0.9 lib/whois/client.rb
whois-1.0.8 lib/whois/client.rb
whois-1.0.7 lib/whois/client.rb
whois-1.0.6 lib/whois/client.rb
whois-1.0.5 lib/whois/client.rb
whois-1.0.4 lib/whois/client.rb
whois-1.0.3 lib/whois/client.rb
whois-1.0.2 lib/whois/client.rb
whois-1.0.1 lib/whois/client.rb
whois-1.0.0 lib/whois/client.rb