Class: MonoVM::Whois::WhoisHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/monovm/whois/whois_handler.rb

Overview

A single-domain handler that wraps one lookup in an object.

Exists so that code written against camelCase WHOIS APIs reads the same way here — the camelCase method names are aliased at the bottom.

handler = MonoVM::Whois::WhoisHandler.whois("monovm.com")
handler.available?     # => false
handler.whois_message  # => the raw registry response
handler.record.expires_on

One deliberate difference from boolean-style WHOIS APIs: there, an isAvailable() returns false both for a registered domain and for a lookup that failed, and a permissive detector reports a rate-limited or unreachable server as available. Here #available? is true only when availability was positively established, and #unknown? exists to say "we could not find out". Code that branches on available? alone is safe; code that treats !available? as "registered" should ask #registered? instead.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, client: nil, **options) ⇒ WhoisHandler

Returns a new instance of WhoisHandler.



36
37
38
39
40
# File 'lib/monovm/whois/whois_handler.rb', line 36

def initialize(domain, client: nil, **options)
  @domain = domain
  @client = client || build_client(options)
  @result = @client.lookup(domain)
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



25
26
27
# File 'lib/monovm/whois/whois_handler.rb', line 25

def domain
  @domain
end

#resultObject (readonly)

Returns the value of attribute result.



25
26
27
# File 'lib/monovm/whois/whois_handler.rb', line 25

def result
  @result
end

Class Method Details

.whois(domain, **options) ⇒ WhoisHandler

Parameters:

  • domain (String)
  • options (Hash)

    anything Configuration accepts

Returns:



31
32
33
# File 'lib/monovm/whois/whois_handler.rb', line 31

def whois(domain, **options)
  new(domain, **options)
end

Instance Method Details

#availability_detailsHash Also known as: getAvailabilityDetails

Which rule decided, what it matched, and what every other rule said — the actual decision path rather than a fixed set of boolean flags.

Returns:

  • (Hash)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/monovm/whois/whois_handler.rb', line 99

def availability_details
  {
    domain: result.name,
    tld: result.tld,
    sld: result.sld,
    status: result.status,
    decided_by: result.verdict&.rule,
    reason: result.reason,
    evidence: result.verdict&.evidence,
    trace: result.verdict&.trace || [],
    endpoint: result.response&.endpoint&.to_s,
    response_length: result.response&.body&.length || 0,
    response_preview: preview
  }
end

#available?Boolean Also known as: isAvailable

True only when the response positively established that the name is free.

Returns:

  • (Boolean)


53
54
55
# File 'lib/monovm/whois/whois_handler.rb', line 53

def available?
  result.available?
end

#inspectObject



119
120
121
# File 'lib/monovm/whois/whois_handler.rb', line 119

def inspect
  "#<#{self.class.name} #{result.name.inspect} #{status}>"
end

#premium?Boolean Also known as: isPremium

True when the registry flagged the name as premium or reserved: unregistered, but not obtainable at standard price.

Returns:

  • (Boolean)


65
66
67
# File 'lib/monovm/whois/whois_handler.rb', line 65

def premium?
  result.premium?
end

#recordParser::Record?

Returns:



86
87
88
# File 'lib/monovm/whois/whois_handler.rb', line 86

def record
  result.record
end

#registered?Boolean

True when the name exists. Distinct from !available?, which is also true when the lookup failed.

Returns:

  • (Boolean)


59
60
61
# File 'lib/monovm/whois/whois_handler.rb', line 59

def registered?
  result.registered?
end

#sldString Also known as: getSld

Returns the second-level label, or "" when none was resolved.

Returns:

  • (String)

    the second-level label, or "" when none was resolved



48
49
50
# File 'lib/monovm/whois/whois_handler.rb', line 48

def sld
  result.sld.to_s
end

#statusSymbol

Returns :available, :registered, :premium, :unknown or :invalid.

Returns:

  • (Symbol)

    :available, :registered, :premium, :unknown or :invalid



91
92
93
# File 'lib/monovm/whois/whois_handler.rb', line 91

def status
  result.status
end

#tldString Also known as: getTld

Returns the TLD, with its leading dot, or "" when none was resolved.

Returns:

  • (String)

    the TLD, with its leading dot, or "" when none was resolved



43
44
45
# File 'lib/monovm/whois/whois_handler.rb', line 43

def tld
  result.tld.to_s
end

#to_hObject



115
116
117
# File 'lib/monovm/whois/whois_handler.rb', line 115

def to_h
  result.to_h
end

#unknown?Boolean

True when no verdict could be reached — a refusal, a timeout, an unreadable response. Ask again later; do not treat as free.

Returns:

  • (Boolean)


71
72
73
# File 'lib/monovm/whois/whois_handler.rb', line 71

def unknown?
  result.unknown?
end

#valid?Boolean Also known as: isValid

True when the domain was well-formed and its TLD is one we can look up.

Returns:

  • (Boolean)


76
77
78
# File 'lib/monovm/whois/whois_handler.rb', line 76

def valid?
  !result.invalid?
end

#whois_messageObject Also known as: getWhoisMessage

The raw registry response, or the explanatory message when none was obtained.



81
82
83
# File 'lib/monovm/whois/whois_handler.rb', line 81

def whois_message
  result.whois_message
end