Sha256: f973d6380a98c29a7d720421c04b66b7132dcefa189848510227f5d7e2598e00

Contents?: true

Size: 1.41 KB

Versions: 14

Compression:

Stored size: 1.41 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 '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

14 entries across 14 versions & 1 rubygems

Version Path
whois-1.2.1 lib/whois/client.rb
whois-1.2.0 lib/whois/client.rb
whois-1.1.8 lib/whois/client.rb
whois-1.1.7 lib/whois/client.rb
whois-1.1.6 lib/whois/client.rb
whois-1.1.5 lib/whois/client.rb
whois-1.1.4 lib/whois/client.rb
whois-1.1.3 lib/whois/client.rb
whois-1.1.2 lib/whois/client.rb
whois-1.1.1 lib/whois/client.rb
whois-1.1.0 lib/whois/client.rb
whois-1.0.12 lib/whois/client.rb
whois-1.0.11 lib/whois/client.rb
whois-1.0.10 lib/whois/client.rb