Updated REPP API for new registrar portal

This commit is contained in:
Sergei Tsõganov 2022-06-06 13:43:30 +03:00
parent e17b21436d
commit a5ffce290d
61 changed files with 1269 additions and 408 deletions

View file

@ -3,22 +3,32 @@ module Serializers
class Contact
attr_reader :contact
def initialize(contact, show_address:)
def initialize(contact, options = {})
@contact = contact
@show_address = show_address
@show_address = options[:show_address]
@domain_params = options[:domain_params] || nil
@simplify = options[:simplify] || false
end
def to_json(obj = contact)
json = { id: obj.code, name: obj.name, ident: ident,
email: obj.email, phone: obj.phone,
auth_info: obj.auth_info, statuses: obj.statuses,
disclosed_attributes: obj.disclosed_attributes }
return simple_object if @simplify
json = { id: obj.uuid, code: obj.code, name: obj.name, ident: ident,
email: obj.email, phone: obj.phone, created_at: obj.created_at,
auth_info: obj.auth_info, statuses: statuses,
disclosed_attributes: obj.disclosed_attributes, registrar: registrar }
json[:address] = address if @show_address
if @domain_params
json[:domains] = domains
json[:domains_count] = obj.qualified_domain_ids(@domain_params[:domain_filter]).size
end
json
end
def registrar
contact.registrar.as_json(only: %i[name website])
end
def ident
{
code: contact.ident,
@ -31,6 +41,34 @@ module Serializers
{ street: contact.street, zip: contact.zip, city: contact.city,
state: contact.state, country_code: contact.country_code }
end
def domains
contact.all_domains(page: @domain_params[:page],
per: @domain_params[:per_page],
params: @domain_params)
.map do |d|
{ id: d.uuid, name: d.name, registrar: { name: d.registrar.name },
valid_to: d.valid_to, roles: d.roles }
end
end
def statuses
statuses_with_notes = contact.status_notes
contact.statuses.each do |status|
statuses_with_notes.merge!({ "#{status}": '' }) unless statuses_with_notes.key?(status)
end
statuses_with_notes
end
private
def simple_object
{
id: contact.uuid,
code: contact.code,
name: contact.name,
}
end
end
end
end

View file

@ -3,19 +3,25 @@ module Serializers
class Domain
attr_reader :domain
def initialize(domain, sponsored: true)
def initialize(domain, sponsored: true, simplify: false)
@domain = domain
@sponsored = sponsored
@simplify = simplify
end
# rubocop:disable Metrics/AbcSize
def to_json(obj = domain)
return simple_object if @simplify
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,
contacts: contacts, nameservers: nameservers, dnssec_keys: dnssec_keys,
statuses: obj.status_notes, registrar: registrar
id: obj.uuid, name: obj.name, registrant: registrant,
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, contacts: contacts,
nameservers: nameservers, dnssec_keys: dnssec_keys,
statuses: statuses, registrar: registrar,
dispute: Dispute.active.exists?(domain_name: obj.name)
}
json[:transfer_code] = obj.auth_info if @sponsored
json
@ -23,22 +29,54 @@ module Serializers
# rubocop:enable Metrics/AbcSize
def contacts
domain.domain_contacts.map { |c| { code: c.contact.code, 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: nssec.flags, protocol: nssec.protocol, alg: nssec.alg,
public_key: nssec.public_key }
domain.domain_contacts.includes(:contact).map do |dc|
contact = dc.contact
{ code: contact.code, type: dc.type,
name: contact.name_disclosed_by_registrar(domain.registrar_id) }
end
end
def nameservers
domain.nameservers.order(:created_at).as_json(only: %i[id hostname ipv4 ipv6])
end
def dnssec_keys
domain.dnskeys.order(:updated_at).as_json(only: %i[id flags protocol alg public_key])
end
def registrar
{ name: domain.registrar.name, website: domain.registrar.website }
domain.registrar.as_json(only: %i[name website])
end
def registrant
rant = domain.registrant
{
id: rant.uuid,
name: rant.name,
code: rant.code,
}
end
def statuses
statuses_with_notes = domain.status_notes
domain.statuses.each do |status|
statuses_with_notes.merge!({ "#{status}": '' }) unless statuses_with_notes.key?(status)
end
statuses_with_notes
end
private
def simple_object
json = {
id: domain.uuid,
name: domain.name,
expire_time: domain.expire_time,
registrant: registrant,
statuses: statuses,
}
json[:transfer_code] = domain.auth_info if @sponsored
json
end
end
end

View file

@ -0,0 +1,85 @@
module Serializers
module Repp
class Invoice
attr_reader :invoice
def initialize(invoice, simplify: false)
@invoice = invoice
@simplify = simplify
end
def to_json(obj = invoice)
return simple_object if @simplify
{
id: obj.id, issue_date: obj.issue_date, cancelled_at: obj.cancelled_at,
paid: obj.paid?, payable: obj.payable?, cancellable: invoice.cancellable?,
receipt_date: obj.receipt_date, payment_link: obj.payment_link,
number: obj.number, subtotal: obj.subtotal, vat_amount: obj.vat_amount,
vat_rate: obj.vat_rate, total: obj.total,
description: obj.description, reference_no: obj.reference_no,
created_at: obj.created_at, updated_at: obj.updated_at,
due_date: obj.due_date, currency: obj.currency,
seller: seller, buyer: buyer, items: items,
recipient: obj.buyer.billing_email
}
end
private
def seller
{
name: invoice.seller_name,
reg_no: invoice.seller_reg_no,
iban: invoice.seller_iban,
bank: invoice.seller_bank,
swift: invoice.seller_swift,
vat_no: invoice.seller_vat_no,
address: invoice.seller_address,
country: invoice.seller_country.name,
phone: invoice.seller_phone,
url: invoice.seller_url,
email: invoice.seller_email,
contact_name: invoice.seller_contact_name,
}
end
def buyer
{
name: invoice.buyer_name,
reg_no: invoice.buyer_reg_no,
address: invoice.buyer_address,
country: invoice.buyer_country.name,
phone: invoice.buyer_phone,
url: invoice.buyer_url,
email: invoice.buyer_email,
}
end
def items
invoice.items.map do |item|
{ description: item.description, unit: item.unit,
quantity: item.quantity, price: item.price,
sum_without_vat: item.item_sum_without_vat,
vat_amount: item.vat_amount, total: item.total }
end
end
def simple_object
{
id: invoice.id,
number: invoice.number,
paid: invoice.paid?,
payable: invoice.payable?,
payment_link: invoice.payment_link,
receipt_date: invoice.receipt_date,
cancelled: invoice.cancelled?,
cancellable: invoice.cancellable?,
due_date: invoice.due_date,
total: invoice.total,
recipient: invoice.buyer.billing_email,
}
end
end
end
end