class UPnPSoapRequest
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 6 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 36 def UPnPSoapRequest.read(xml) soap_req = UPnPSoapRequest.new doc = Nokogiri::XML(xml) action_elem = doc.root.first_element_child.first_element_child soap_req.service_type = action_elem.namespace.href soap_req.action_name = action_elem.name action_elem.elements.each do |node| name = node.name value = node.text soap_req[name] = value end soap_req end
to_xml_doc(soap_req)
click to toggle source
# File lib/upnp_soap.rb, line 32 def UPnPSoapRequest.to_xml_doc(soap_req) return '<?xml version="1.0" encoding="utf-8"?>' + "\n#{soap_req.to_xml}" end
Public Instance Methods
to_xml()
click to toggle source
# File lib/upnp_soap.rb, line 12 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}") 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