Sha256: c7b60e6c5461d4ad0379d0b0e1931dddc115046718282bee4ed5b00b56b3cd4c

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

#--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
# Copyright (c) 2009-2011 Simone Carletti <weppos@weppos.net>
#++


module Whois
  class Server
    module Adapters

      #
      # = Formatted Adapter
      #
      # The {Formatted} adapter is almost equal to the {Standard} adapter.
      # It accepts a +:format+ adapter to format the WHOIS query.
      #
      #   a = Standard.new(:tld, ".it", "whois.nic.it", :format => "HELLO %s")
      #   # performs a query for the string "HELLO example.it"
      #   a.request("example.it")
      #
      # == Options
      #
      # The following options can be supplied to customize the creation
      # of a new instance:
      #
      # * +:port+ - Specifies a port number different than 43
      # * +:format+ - Specifies the format rule to apply to the query string
      #
      # @see Whois::Server::Adapters::Standard
      #
      class Formatted < Base

        # Executes a WHOIS query to the WHOIS interface
        # listening at +host+ and appends the response
        # to the client buffer.
        #
        # The standard port of a WHOIS request is 43.
        # You can customize it by passing a +:port+ option.
        #
        # @param  [String] string
        # @return [void]
        #
        # @raise  [Whois::ServerError] If the :format option is missing.
        #
        def request(string)
          options[:format] || raise(ServerError, "Missing mandatory :format option for adapter `Formatted'")
          response = query_the_socket(sprintf(options[:format], string), host)
          buffer_append response, host
        end

      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
whois-2.2.0 lib/whois/server/adapters/formatted.rb
whois-2.1.0 lib/whois/server/adapters/formatted.rb
whois-2.0.7 lib/whois/server/adapters/formatted.rb
whois-2.0.6 lib/whois/server/adapters/formatted.rb
whois-2.0.5 lib/whois/server/adapters/formatted.rb
whois-2.0.4 lib/whois/server/adapters/formatted.rb
whois-2.0.3 lib/whois/server/adapters/formatted.rb
whois-2.0.2 lib/whois/server/adapters/formatted.rb
whois-2.0.1 lib/whois/server/adapters/formatted.rb
whois-2.0.0 lib/whois/server/adapters/formatted.rb