Skip to content

Commit

Permalink
Refactored xml_console_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Tsoganov authored and Sergei Tsoganov committed Nov 30, 2022
1 parent 30d7fcb commit 48616ec
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions app/controllers/repp/v1/registrar/xml_console_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ class XmlConsoleController < BaseController
THROTTLED_ACTIONS = %i[load_xml].freeze
include Shunter::Integration::Throttle

PREFS = %w[
domain-ee
contact-ee
eis
epp-ee
].freeze
PREFS = %w[domain-ee contact-ee eis epp-ee].freeze

SCHEMA_VERSIONS = {
'epp-ee' => '1.0',
'eis' => '1.0',
'contact-ee' => '1.1',
'default' => '1.2',
}.freeze

def load_xml
cl_trid = "#{current_user.username}-#{Time.zone.now.to_i}"
Expand All @@ -37,23 +39,16 @@ def prepare_payload(xml, cl_trid)
end

def load_schema_by_prefix(pref, xml)
case pref
when 'epp-ee'
insert_prefix_and_version(xml, pref, '1.0')
when 'eis'
insert_prefix_and_version(xml, pref, '1.0')
when 'contact-ee'
insert_prefix_and_version(xml, pref, '1.1')
else
insert_prefix_and_version(xml, pref, '1.2')
end
end

def insert_prefix_and_version(xml, pref, version)
version = version_by_prefix(pref)
xml.gsub!("\"#{pref}\"",
"\"#{Xsd::Schema.filename(for_prefix: pref.to_s, for_version: version)}\"")
xml
end

def version_by_prefix(pref)
key = SCHEMA_VERSIONS.key?(pref) ? pref : 'default'
SCHEMA_VERSIONS[key]
end
end
end
end
Expand Down

0 comments on commit 48616ec

Please sign in to comment.