mirror of
https://github.com/internetee/registry.git
synced 2025-07-02 01:03:35 +02:00
Refactor contact type parsing to dynamic
This commit is contained in:
parent
8bff2fb34c
commit
292daa66e0
2 changed files with 13 additions and 19 deletions
|
@ -36,13 +36,12 @@ module Epp::DomainsHelper
|
||||||
def domain_contacts
|
def domain_contacts
|
||||||
parsed_frame = Nokogiri::XML(params[:frame]).remove_namespaces!
|
parsed_frame = Nokogiri::XML(params[:frame]).remove_namespaces!
|
||||||
|
|
||||||
res = {tech: [], admin: []}
|
res = {}
|
||||||
parsed_frame.css('contact[type="tech"]').each do |x|
|
Contact::CONTACT_TYPES.each do |ct|
|
||||||
res[:tech] << Hash.from_xml(x.to_s).with_indifferent_access
|
res[ct.to_sym] ||= []
|
||||||
|
parsed_frame.css("contact[type='#{ct}']").each do |x|
|
||||||
|
res[ct.to_sym] << Hash.from_xml(x.to_s).with_indifferent_access
|
||||||
end
|
end
|
||||||
|
|
||||||
parsed_frame.css('contact[type="admin"]').each do |x|
|
|
||||||
res[:admin] << Hash.from_xml(x.to_s).with_indifferent_access
|
|
||||||
end
|
end
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|
|
@ -31,18 +31,13 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def attach_contacts(contacts)
|
def attach_contacts(contacts)
|
||||||
contacts[:tech].each do |x|
|
contacts.each do |k, v|
|
||||||
|
v.each do |x|
|
||||||
domain_contacts.create(
|
domain_contacts.create(
|
||||||
contact: Contact.find_by(code: x[:contact]),
|
contact: Contact.find_by(code: x[:contact]),
|
||||||
contact_type: Contact::CONTACT_TYPE_TECH
|
contact_type: k
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
contacts[:admin].each do |x|
|
|
||||||
domain_contacts.create(
|
|
||||||
contact: Contact.find_by(code: x[:contact]),
|
|
||||||
contact_type: Contact::CONTACT_TYPE_ADMIN
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue