Class: Druzy::Upnp::UpnpService
- Inherits:
-
Object
- Object
- Druzy::Upnp::UpnpService
- Defined in:
- lib/druzy/upnp/upnp_service.rb
Instance Attribute Summary collapse
-
#control_url ⇒ Object
readonly
Returns the value of attribute control_url.
-
#event_sub_url ⇒ Object
readonly
Returns the value of attribute event_sub_url.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#service_id ⇒ Object
readonly
Returns the value of attribute service_id.
-
#service_type ⇒ Object
readonly
Returns the value of attribute service_type.
Instance Method Summary collapse
-
#initialize(args) ⇒ UpnpService
constructor
A new instance of UpnpService.
Constructor Details
#initialize(args) ⇒ UpnpService
Returns a new instance of UpnpService.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/druzy/upnp/upnp_service.rb', line 11 def initialize(args) @service_type = args[:service_type] @service_id = args[:service_id] @location = args[:location] @control_url = args[:control_url] @event_sub_url = args[:event_sub_url] uri = URI(@location) xml=Net::HTTP.get(uri) xml_nok = Nokogiri::XML(xml) xml_nok.remove_namespaces! xml_nok.xpath('scpd/actionList/action').to_a.each do |el| action_name = el.xpath('name').text define_singleton_method(action_name.to_sym) do |arguments={}| = <<-MESSAGE <?xml version="1.0"?> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <s:Body> <u:#{action_name} xmlns:u="#{@service_type}"> MESSAGE arguments.each do |cle, valeur| .concat <<-MESSAGE <#{cle.to_s}>#{valeur.to_s}</#{cle.to_s}> MESSAGE end .concat <<-MESSAGE </u:#{action_name}> </s:Body> </s:Envelope> MESSAGE header = { "HOST" => uri.host.to_s+':'+uri.port.to_s, "CONTENT-LENGTH" => .size.to_s, "CONTENT-TYPE" => 'text/xml; charset="utf-8"', "SOAPACTION" => @service_type.to_s+"#"+action_name.to_s } http = Net::HTTP.new(uri.host,uri.port) request = Net::HTTP::Post.new(uri.request_uri,header) request.body = response = http.request(request) xml = Nokogiri.XML(response.body) xml.remove_namespaces! result = {} xml.xpath("Envelope/Body/"+action_name.to_s+"Response").children.each do |child| result[child.name.to_s] = child.text end return result end end end |
Instance Attribute Details
#control_url ⇒ Object (readonly)
Returns the value of attribute control_url.
9 10 11 |
# File 'lib/druzy/upnp/upnp_service.rb', line 9 def control_url @control_url end |
#event_sub_url ⇒ Object (readonly)
Returns the value of attribute event_sub_url.
9 10 11 |
# File 'lib/druzy/upnp/upnp_service.rb', line 9 def event_sub_url @event_sub_url end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
9 10 11 |
# File 'lib/druzy/upnp/upnp_service.rb', line 9 def location @location end |
#service_id ⇒ Object (readonly)
Returns the value of attribute service_id.
9 10 11 |
# File 'lib/druzy/upnp/upnp_service.rb', line 9 def service_id @service_id end |
#service_type ⇒ Object (readonly)
Returns the value of attribute service_type.
9 10 11 |
# File 'lib/druzy/upnp/upnp_service.rb', line 9 def service_type @service_type end |