class UPnPSoapResponse

Attributes

action_name[RW]
service_type[RW]

Public Class Methods

new(service_type = nil, action_name = nil) click to toggle source
# File lib/upnp_soap.rb, line 53
def initialize(service_type = nil, action_name = nil)
  @service_type = service_type
  @action_name = action_name
end
read(xml) click to toggle source
# File lib/upnp_soap.rb, line 84
def UPnPSoapResponse.read(xml)
  soap_res = UPnPSoapResponse.new
  doc = Nokogiri::XML(xml)
  action_elem = doc.root.first_element_child.first_element_child
  soap_res.service_type = action_elem.namespace.href
  soap_res.action_name = action_elem.name[0..-'Response'.length]
  action_elem.elements.each do |node|
    name = node.name
    value = node.text
    soap_res[name] = value
  end
  soap_res
end
to_xml_doc(soap_res) click to toggle source
# File lib/upnp_soap.rb, line 80
def UPnPSoapResponse.to_xml_doc(soap_res)
  return '<?xml version="1.0" encoding="utf-8"?>' + "\n#{soap_res.to_xml}"
end

Public Instance Methods

to_xml() click to toggle source
# File lib/upnp_soap.rb, line 60
def to_xml
  tag = XmlTag.new 's:Envelope'
  tag.attributes = {
    's:encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/",
        'xmlns:s' => "http://schemas.xmlsoap.org/soap/envelope/"
  }
  body = tag.append XmlTag.new('s:Body')
  action = body.append XmlTag.new("u:#{@action_name}Response")
  action.attributes = {
    'xmlns:u' => @service_type
  }
  self.each do |k,v|
    prop = action.append XmlTag.new(k)
    prop.append XmlText.new(v)
  end

  return tag.to_s
end