Class: Mihari::Clients::Whois

Inherits:
Object
  • Object
show all
Defined in:
lib/mihari/clients/whois.rb

Overview

Whois client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout: nil) ⇒ Whois

Returns a new instance of Whois.

Parameters:

  • timeout (Integer, nil) (defaults to: nil)


20
21
22
23
24
25
26
27
28
# File 'lib/mihari/clients/whois.rb', line 20

def initialize(timeout: nil)
  @timeout = timeout

  @client = lambda do
    return ::Whois::Client.new if timeout.nil?

    ::Whois::Client.new(timeout:)
  end.call
end

Instance Attribute Details

#client::Whois::Client (readonly)

Returns:

  • (::Whois::Client)


15
16
17
# File 'lib/mihari/clients/whois.rb', line 15

def client
  @client
end

#timeoutInteger? (readonly)

Returns:

  • (Integer, nil)


12
13
14
# File 'lib/mihari/clients/whois.rb', line 12

def timeout
  @timeout
end

Instance Method Details

#lookup(domain) ⇒ Object

Query IAIA Whois API

Parameters:



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mihari/clients/whois.rb', line 36

def lookup(domain)
  record = client.lookup(domain)
  return if record.parser.available?

  Models::WhoisRecord.new(
    domain:,
    created_on: get_created_on(record.parser),
    updated_on: get_updated_on(record.parser),
    expires_on: get_expires_on(record.parser),
    registrar: get_registrar(record.parser),
    contacts: get_contacts(record.parser)
  )
end