Class: MonoVM::Whois::WhoisHandler
- Inherits:
-
Object
- Object
- MonoVM::Whois::WhoisHandler
- 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. # => 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
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#availability_details ⇒ Hash
(also: #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.
-
#available? ⇒ Boolean
(also: #isAvailable)
True only when the response positively established that the name is free.
-
#initialize(domain, client: nil, **options) ⇒ WhoisHandler
constructor
A new instance of WhoisHandler.
- #inspect ⇒ Object
-
#premium? ⇒ Boolean
(also: #isPremium)
True when the registry flagged the name as premium or reserved: unregistered, but not obtainable at standard price.
- #record ⇒ Parser::Record?
-
#registered? ⇒ Boolean
True when the name exists.
-
#sld ⇒ String
(also: #getSld)
The second-level label, or "" when none was resolved.
-
#status ⇒ Symbol
:available, :registered, :premium, :unknown or :invalid.
-
#tld ⇒ String
(also: #getTld)
The TLD, with its leading dot, or "" when none was resolved.
- #to_h ⇒ Object
-
#unknown? ⇒ Boolean
True when no verdict could be reached — a refusal, a timeout, an unreadable response.
-
#valid? ⇒ Boolean
(also: #isValid)
True when the domain was well-formed and its TLD is one we can look up.
-
#whois_message ⇒ Object
(also: #getWhoisMessage)
The raw registry response, or the explanatory message when none was obtained.
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, **) @domain = domain @client = client || build_client() @result = @client.lookup(domain) end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
25 26 27 |
# File 'lib/monovm/whois/whois_handler.rb', line 25 def domain @domain end |
#result ⇒ Object (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
31 32 33 |
# File 'lib/monovm/whois/whois_handler.rb', line 31 def whois(domain, **) new(domain, **) end |
Instance Method Details
#availability_details ⇒ Hash 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.
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.
53 54 55 |
# File 'lib/monovm/whois/whois_handler.rb', line 53 def available? result.available? end |
#inspect ⇒ Object
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.
65 66 67 |
# File 'lib/monovm/whois/whois_handler.rb', line 65 def premium? result.premium? end |
#record ⇒ Parser::Record?
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.
59 60 61 |
# File 'lib/monovm/whois/whois_handler.rb', line 59 def registered? result.registered? end |
#sld ⇒ String Also known as: getSld
Returns 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 |
#status ⇒ Symbol
Returns :available, :registered, :premium, :unknown or :invalid.
91 92 93 |
# File 'lib/monovm/whois/whois_handler.rb', line 91 def status result.status end |
#tld ⇒ String Also known as: getTld
Returns 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_h ⇒ Object
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.
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.
76 77 78 |
# File 'lib/monovm/whois/whois_handler.rb', line 76 def valid? !result.invalid? end |
#whois_message ⇒ Object 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 result. end |