Class: Whois::Server::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/whois/server/adapters/base.rb

Direct Known Subclasses

Afilias, Arin, Arpa, Formatted, None, NotImplemented, Standard, Verisign, Web

Constant Summary collapse

DEFAULT_WHOIS_PORT =

Default WHOIS request port.

43
DEFAULT_BIND_HOST =

Default bind hostname.

"0.0.0.0"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, allocation, host, options = {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • type (Symbol)

    the type of WHOIS adapter to define. Known values are :tld, :ipv4, :ipv6,

  • allocation (String)

    the allocation, range or hostname, this server is responsible for.

  • host (String, nil)

    the server hostname. Use nil if unknown or not available.

  • options (Hash) (defaults to: {})

    optional adapter properties



55
56
57
58
59
60
# File 'lib/whois/server/adapters/base.rb', line 55

def initialize(type, allocation, host, options = {})
  @type       = type
  @allocation = allocation
  @host       = host
  @options    = options || {}
end

Class Attribute Details

.query_handlerObject



23
24
25
# File 'lib/whois/server/adapters/base.rb', line 23

def query_handler
  @query_handler ||= SocketHandler.new
end

Instance Attribute Details

#allocationString (readonly)

Returns The allocation this server is responsible for.

Returns:

  • (String)

    The allocation this server is responsible for.



38
39
40
# File 'lib/whois/server/adapters/base.rb', line 38

def allocation
  @allocation
end

#bufferArray (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Temporary internal response buffer.

Returns:

  • (Array)


48
49
50
# File 'lib/whois/server/adapters/base.rb', line 48

def buffer
  @buffer
end

#hostString? (readonly)

Returns The server hostname.

Returns:

  • (String, nil)

    The server hostname.



40
41
42
# File 'lib/whois/server/adapters/base.rb', line 40

def host
  @host
end

#optionsHash (readonly)

Returns Optional adapter properties.

Returns:

  • (Hash)

    Optional adapter properties.



42
43
44
# File 'lib/whois/server/adapters/base.rb', line 42

def options
  @options
end

#typeSymbol (readonly)

Returns The type of WHOIS server.

Returns:

  • (Symbol)

    The type of WHOIS server.



36
37
38
# File 'lib/whois/server/adapters/base.rb', line 36

def type
  @type
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Checks self and other for equality.

Parameters:

Returns:

  • (Boolean)

    true if the other is the same object, or other attributes matches this object attributes.



67
68
69
70
71
72
73
74
75
# File 'lib/whois/server/adapters/base.rb', line 67

def ==(other)
  equal?(other) || (
    other.is_a?(self.class) &&
    type == other.type &&
    allocation == other.allocation &&
    host == other.host &&
    options == other.options
  )
end

#configure(settings) ⇒ Hash

Merges given settings into current #options.

Parameters:

  • settings (Hash)

Returns:

  • (Hash)

    the updated options for this object



84
85
86
87
# File 'lib/whois/server/adapters/base.rb', line 84

def configure(settings)
  @host = settings[:host] if settings[:host]
  options.merge!(settings)
end

#lookup(string) ⇒ Whois::Record

Performs a Whois lookup for string using the current server adapter.

Internally, this method calls #request using the Template Method design pattern.

server.lookup("google.com")
# => Whois::Record

Parameters:

  • string (String)

    the string to query

Returns:



99
100
101
102
# File 'lib/whois/server/adapters/base.rb', line 99

def lookup(string)
  parts = buffer_start { request(string) }
  Whois::Record.new(self, parts)
end

#query_handlerObject

Gets the current query handler for this class.

Returns:

  • (Object)

    the query handler

See Also:

  • Whois::Servers::Adapters::Base.query_handler


123
124
125
# File 'lib/whois/server/adapters/base.rb', line 123

def query_handler
  self.class.query_handler
end

#request(string) ⇒ void

This method is abstract.

This method returns an undefined value.

Performs the real WHOIS request.

This method is not implemented in Whois::Server::Adapters::Base class, it is intended to be overwritten in the concrete subclasses. This is the heart of the Template Method design pattern.

Parameters:

  • string (String)

    the string to query

Raises:

  • (NotImplementedError)


114
115
116
# File 'lib/whois/server/adapters/base.rb', line 114

def request(string)
  raise NotImplementedError
end