Class: MonoVM::Whois::Result

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain:, status:, sld: nil, tld: nil, verdict: nil, record: nil, response: nil, error: nil) ⇒ Result

Returns a new instance of Result.

Raises:

  • (ArgumentError)


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

#domainObject (readonly)

Returns the value of attribute domain.



15
16
17
# File 'lib/monovm/whois/result.rb', line 15

def domain
  @domain
end

#errorObject (readonly)

Returns the value of attribute error.



15
16
17
# File 'lib/monovm/whois/result.rb', line 15

def error
  @error
end

#recordObject (readonly)

Returns the value of attribute record.



15
16
17
# File 'lib/monovm/whois/result.rb', line 15

def record
  @record
end

#responseObject (readonly)

Returns the value of attribute response.



15
16
17
# File 'lib/monovm/whois/result.rb', line 15

def response
  @response
end

#sldObject (readonly)

Returns the value of attribute sld.



15
16
17
# File 'lib/monovm/whois/result.rb', line 15

def sld
  @sld
end

#statusObject (readonly)

Returns the value of attribute status.



15
16
17
# File 'lib/monovm/whois/result.rb', line 15

def status
  @status
end

#tldObject (readonly)

Returns the value of attribute tld.



15
16
17
# File 'lib/monovm/whois/result.rb', line 15

def tld
  @tld
end

#verdictObject (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

Returns:

  • (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.

Returns:

  • (Boolean)


73
74
75
# File 'lib/monovm/whois/result.rb', line 73

def conclusive?
  available? || registered? || premium?
end

#inspectObject



109
110
111
# File 'lib/monovm/whois/result.rb', line 109

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

#invalid?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/monovm/whois/result.rb', line 68

def invalid?
  status == :invalid
end

#nameObject

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/monovm/whois/result.rb', line 60

def premium?
  status == :premium
end

#reasonObject

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

Returns:

  • (Boolean)


56
57
58
# File 'lib/monovm/whois/result.rb', line 56

def registered?
  status == :registered
end

#to_hObject



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

Returns:

  • (Boolean)


64
65
66
# File 'lib/monovm/whois/result.rb', line 64

def unknown?
  status == :unknown
end

#whois_messageObject 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 whois_message
  return response.text if response

  error.to_s
end