Class: MonoVM::Whois::Result
- Inherits:
-
Object
- Object
- MonoVM::Whois::Result
- Defined in:
- lib/monovm/whois/result.rb
Overview
What a lookup produced: the verdict, the parsed record, and the raw response that backs both.
#status adds :invalid to the four Availability::Verdict statuses, for
names that never reached a server — malformed input, or a TLD with no known
endpoint. That distinction matters to a caller building a UI: :invalid is
the user's problem to fix, :unknown is ours to retry.
Constant Summary collapse
- STATUSES =
%i[available registered premium unknown invalid].freeze
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#sld ⇒ Object
readonly
Returns the value of attribute sld.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tld ⇒ Object
readonly
Returns the value of attribute tld.
-
#verdict ⇒ Object
readonly
Returns the value of attribute verdict.
Class Method Summary collapse
-
.invalid(domain, reason:, sld: nil, tld: nil) ⇒ Object
A name that could not be looked up at all.
-
.unknown(domain, reason:, sld: nil, tld: nil, response: nil) ⇒ Object
A lookup that reached a server but produced no verdict.
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#conclusive? ⇒ Boolean
True when the lookup produced an actionable answer about the domain.
-
#initialize(domain:, status:, sld: nil, tld: nil, verdict: nil, record: nil, response: nil, error: nil) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
- #invalid? ⇒ Boolean
-
#name ⇒ Object
The name as a string, in its Unicode form.
- #premium? ⇒ Boolean
-
#reason ⇒ Object
Why the verdict came out this way, for logging and bug reports.
- #registered? ⇒ Boolean
- #to_h ⇒ Object
- #unknown? ⇒ Boolean
-
#whois_message ⇒ Object
(also: #message)
The raw text the registry sent, or the explanatory message when no server was reached.
Constructor Details
#initialize(domain:, status:, sld: nil, tld: nil, verdict: nil, record: nil, response: nil, error: nil) ⇒ Result
Returns a new instance of Result.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/monovm/whois/result.rb', line 37 def initialize(domain:, status:, sld: nil, tld: nil, verdict: nil, record: nil, response: nil, error: nil) raise ArgumentError, "unknown result status #{status.inspect}" unless STATUSES.include?(status) @domain = domain @status = status @sld = sld @tld = tld @verdict = verdict @record = record @response = response @error = error freeze end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def domain @domain end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def error @error end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def record @record end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def response @response end |
#sld ⇒ Object (readonly)
Returns the value of attribute sld.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def sld @sld end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def status @status end |
#tld ⇒ Object (readonly)
Returns the value of attribute tld.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def tld @tld end |
#verdict ⇒ Object (readonly)
Returns the value of attribute verdict.
15 16 17 |
# File 'lib/monovm/whois/result.rb', line 15 def verdict @verdict end |
Class Method Details
.invalid(domain, reason:, sld: nil, tld: nil) ⇒ Object
A name that could not be looked up at all.
19 20 21 |
# File 'lib/monovm/whois/result.rb', line 19 def invalid(domain, reason:, sld: nil, tld: nil) new(domain: domain, status: :invalid, sld: sld, tld: tld, error: reason) end |
.unknown(domain, reason:, sld: nil, tld: nil, response: nil) ⇒ Object
A lookup that reached a server but produced no verdict.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/monovm/whois/result.rb', line 24 def unknown(domain, reason:, sld: nil, tld: nil, response: nil) new( domain: domain, status: :unknown, sld: sld, tld: tld, response: response, error: reason, verdict: Availability::Verdict.unknown(reason: reason) ) end |
Instance Method Details
#available? ⇒ Boolean
52 53 54 |
# File 'lib/monovm/whois/result.rb', line 52 def available? status == :available end |
#conclusive? ⇒ Boolean
True when the lookup produced an actionable answer about the domain.
73 74 75 |
# File 'lib/monovm/whois/result.rb', line 73 def conclusive? available? || registered? || premium? end |
#inspect ⇒ Object
109 110 111 |
# File 'lib/monovm/whois/result.rb', line 109 def inspect "#<#{self.class.name} #{name.inspect} #{status}>" end |
#invalid? ⇒ Boolean
68 69 70 |
# File 'lib/monovm/whois/result.rb', line 68 def invalid? status == :invalid end |
#name ⇒ Object
The name as a string, in its Unicode form.
78 79 80 |
# File 'lib/monovm/whois/result.rb', line 78 def name domain.to_s end |
#premium? ⇒ Boolean
60 61 62 |
# File 'lib/monovm/whois/result.rb', line 60 def premium? status == :premium end |
#reason ⇒ Object
Why the verdict came out this way, for logging and bug reports.
92 93 94 |
# File 'lib/monovm/whois/result.rb', line 92 def reason verdict&.reason || error end |
#registered? ⇒ Boolean
56 57 58 |
# File 'lib/monovm/whois/result.rb', line 56 def registered? status == :registered end |
#to_h ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/monovm/whois/result.rb', line 96 def to_h { domain: name, sld: sld, tld: tld, status: status, reason: reason, rule: verdict&.rule, record: record&.to_h, response: response&.to_h }.compact end |
#unknown? ⇒ Boolean
64 65 66 |
# File 'lib/monovm/whois/result.rb', line 64 def unknown? status == :unknown end |
#whois_message ⇒ Object Also known as: message
The raw text the registry sent, or the explanatory message when no server
was reached. Also aliased as getWhoisMessage on WhoisHandler.
84 85 86 87 88 |
# File 'lib/monovm/whois/result.rb', line 84 def return response.text if response error.to_s end |