From 9a7827107f944e10fa1e49de5fa65cc5e3d1bd92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 26 Jan 2021 17:38:13 +0200 Subject: [PATCH] REPP: Create domain serializer --- lib/serializers/repp/domain.rb | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/serializers/repp/domain.rb diff --git a/lib/serializers/repp/domain.rb b/lib/serializers/repp/domain.rb new file mode 100644 index 000000000..a623ab184 --- /dev/null +++ b/lib/serializers/repp/domain.rb @@ -0,0 +1,37 @@ +module Serializers + module Repp + class Domain + attr_reader :domain + + def initialize(domain) + @domain = domain + end + + def to_json(obj = domain) + json = { + name: obj.name, registrant: obj.registrant.code, created_at: obj.created_at, + updated_at: obj.updated_at, expire_time: obj.expire_time, outzone_at: obj.outzone_at, + delete_date: obj.delete_date, force_delete_date: obj.force_delete_date, + authorization_code: obj.auth_info, contacts: contacts, nameservers: nameservers, + dnssec_keys: dnssec_keys, statuses: obj.statuses, + } + + json + end + + def contacts + domain.domain_contacts.map { |c| { code: c.contact_code_cache, type: c.type } } + end + + def nameservers + domain.nameservers.map { |ns| { hostname: ns.hostname, ipv4: ns.ipv4, ipv6: ns.ipv6 } } + end + + def dnssec_keys + domain.dnskeys.map do |nssec| + { flags: nsec.flags, protocol: nssec.protocol, alg: nssec.alg, public_key: nssec.public_key } + end + end + end + end +end