Class: MonoVM::Whois::Parser::RdapJson

Inherits:
Base
  • Object
show all
Defined in:
lib/monovm/whois/parser/rdap_json.rb

Overview

Parses an RDAP domain object (RFC 9083).

RDAP is where structured data was the point, so this parser reads fields instead of guessing at prose. Two parts of the format still need translating: dates live in an events array keyed by eventAction rather than in named fields, and contacts are jCard/vCard arrays (RFC 7095) — a nested array of [name, params, type, value] tuples that has to be walked to find an email.

Constant Summary collapse

EVENTS =

eventAction values mapped to the record fields they populate.

{
  "registration" => :created_on,
  "last changed" => :updated_on,
  "last update of rdap database" => nil, # about the database, not the domain
  "expiration" => :expires_on
}.freeze
ROLES =
{
  "registrant" => :registrant,
  "administrative" => :admin,
  "technical" => :tech,
  "billing" => :billing,
  "registrar" => :registrar
}.freeze
VCARD_FIELDS =

jCard property name => the record field it populates. adr is absent because its value is a structured array rather than a plain string.

{ "fn" => :fn, "org" => :org, "email" => :email, "tel" => :tel }.freeze

Constants inherited from Base

Base::DATE_FORMATS, Base::PLAUSIBLE_YEARS

Instance Method Summary collapse

Methods inherited from Base

#name, snake_case

Instance Method Details

#applicable?(response) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/monovm/whois/parser/rdap_json.rb', line 36

def applicable?(response)
  document = response.json
  return false if document.nil?

  document.key?("objectClassName") || document.key?("ldhName") ||
    document.key?("rdapConformance")
end

#parse(response) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/monovm/whois/parser/rdap_json.rb', line 44

def parse(response)
  document = response.json || {}
  events = extract_events(document)
  entities = extract_entities(document)
  registrar = entities[:registrar] || {}

  Record.new(
    domain: document["unicodeName"] || document["ldhName"],
    registry_id: document["handle"],
    registrar: registrar[:organization] || registrar[:name],
    registrar_iana_id: registrar[:iana_id],
    registrant: entities.dig(:registrant, :organization) || entities.dig(:registrant, :name),
    statuses: Array(document["status"]),
    nameservers: extract_nameservers(document),
    created_on: events[:created_on],
    updated_on: events[:updated_on],
    expires_on: events[:expires_on],
    dnssec: extract_dnssec(document),
    contacts: entities.except(:registrar),
    fields: document,
    source: name
  )
end