Refactor contact type parsing to dynamic

This commit is contained in:
Martin Lensment 2014-07-31 10:35:32 +03:00
parent 8bff2fb34c
commit 292daa66e0
2 changed files with 13 additions and 19 deletions

View file

@ -36,13 +36,12 @@ module Epp::DomainsHelper
def domain_contacts
parsed_frame = Nokogiri::XML(params[:frame]).remove_namespaces!
res = {tech: [], admin: []}
parsed_frame.css('contact[type="tech"]').each do |x|
res[:tech] << Hash.from_xml(x.to_s).with_indifferent_access
res = {}
Contact::CONTACT_TYPES.each do |ct|
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
parsed_frame.css('contact[type="admin"]').each do |x|
res[:admin] << Hash.from_xml(x.to_s).with_indifferent_access
end
res

View file

@ -31,18 +31,13 @@ class Domain < ActiveRecord::Base
end
def attach_contacts(contacts)
contacts[:tech].each do |x|
contacts.each do |k, v|
v.each do |x|
domain_contacts.create(
contact: Contact.find_by(code: x[:contact]),
contact_type: Contact::CONTACT_TYPE_TECH
contact_type: k
)
end
contacts[:admin].each do |x|
domain_contacts.create(
contact: Contact.find_by(code: x[:contact]),
contact_type: Contact::CONTACT_TYPE_ADMIN
)
end
end