Implement partial domain deserializer

This commit is contained in:
Karl Erik Õunapuu 2020-11-30 10:33:23 +02:00
parent 7459d7e0c5
commit b683fe813c
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,49 @@
module Deserializers
module Xml
class Domain
attr_reader :frame
def initialize(frame)
@frame = frame
end
def call
attributes = {
name: if_present('name'),
registrar_id: current_user.registrar.id,
reserved_pw: if_present('reserved > pw'),
period: Integer(frame.css('period').text, 1),
period_unit: parsed_frame.css('period').first ? parsed_frame.css('period').first[:unit] : 'y'
}
pw = frame.css('authInfo > pw').text
attributes[:transfer_code] = pw if pw.present?
attributes.compact
end
def if_present(css_path)
return if frame.css(css_path).blank?
frame.css(css_path).text
end
def statuses_to_add
statuses_frame = frame.css('add')
return if statuses_frame.blank?
statuses_frame.css('status').map do |status|
status['s']
end
end
def statuses_to_remove
statuses_frame = frame.css('rem')
return if statuses_frame.blank?
statuses_frame.css('status').map do |status|
status['s']
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'deserializers/xml/legal_document'
require 'deserializers/xml/ident'
require 'deserializers/xml/contact'
module Deserializers
module Xml
class ContactUpdate
attr_reader :frame
def initialize(frame)
@frame = frame
end
def contact
@contact ||= ::Deserializers::Xml::Contact.new(frame).call
end
def ident
@ident ||= ::Deserializers::Xml::Ident.new(frame).call
end
def legal_document
@legal_document ||= ::Deserializers::Xml::LegalDocument.new(frame).call
end
end
end
end