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