class OpenSRS::XmlProcessor::Nokogiri

Nokogiri

Public Class Methods

build(data) click to toggle source
# File lib/opensrs/xml_processor/nokogiri.rb, line 12
def self.build(data)
  builder = ::Nokogiri::XML::Builder.new

  envelope   = ::Nokogiri::XML::Node.new('OPS_envelope', builder.doc)
  header     = ::Nokogiri::XML::Node.new('header', builder.doc)
  version    = ::Nokogiri::XML::Node.new('version', builder.doc)
  body       = ::Nokogiri::XML::Node.new('body', builder.doc)
  data_block = ::Nokogiri::XML::Node.new('data_block', builder.doc)
  other_data = encode_data(data, builder.doc)
  version << '0.9'
  header << version
  envelope << header
  builder.doc << envelope
  data_block << other_data
  body << data_block
  envelope << body

  OpenSRS::SanitizableString.new(builder.to_xml, sanitize(builder.to_xml))
end
data_block_element(response) click to toggle source
# File lib/opensrs/xml_processor/nokogiri.rb, line 44
def self.data_block_element(response)
  doc = ::Nokogiri::XML(response)
  doc.xpath('//OPS_envelope/body/data_block/*')
end
decode_dt_array_data(element) click to toggle source
# File lib/opensrs/xml_processor/nokogiri.rb, line 49
def self.decode_dt_array_data(element)
  dt_array = []

  element.children.each do |item|
    next if item.content.strip.empty?

    dt_array[item.attributes['key'].value.to_i] = decode_data(item.children)
  end

  dt_array
end
decode_dt_assoc_data(element) click to toggle source
# File lib/opensrs/xml_processor/nokogiri.rb, line 61
def self.decode_dt_assoc_data(element)
  dt_assoc = {}

  element.children.each do |item|
    next if item.content.strip.empty?

    dt_assoc[item.attributes['key'].value] = decode_data(item.children)
  end

  dt_assoc
end
new_element(element_name, container) click to toggle source
# File lib/opensrs/xml_processor/nokogiri.rb, line 73
def self.new_element(element_name, container)
  ::Nokogiri::XML::Node.new(element_name.to_s, container.document)
end

Private Class Methods

sanitize(xml_string) click to toggle source
# File lib/opensrs/xml_processor/nokogiri.rb, line 32
def self.sanitize(xml_string)
  doc = ::Nokogiri::XML(xml_string)
  doc.xpath("//item[@key='reg_username']").each do |node|
    node.content = 'FILTERED'
  end
  doc.xpath("//item[@key='reg_password']").each do |node|
    node.content = 'FILTERED'
  end
  doc.to_xml
end