Class: EasyUpnp::DeviceControlPoint
- Inherits:
-
Object
- Object
- EasyUpnp::DeviceControlPoint
- Defined in:
- lib/easy_upnp/device_control_point.rb
Instance Attribute Summary collapse
-
#service_methods ⇒ Object
readonly
Returns the value of attribute service_methods.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(urn, service_endpoint, definition, options) ⇒ DeviceControlPoint
constructor
A new instance of DeviceControlPoint.
- #to_params ⇒ Object
Constructor Details
#initialize(urn, service_endpoint, definition, options) ⇒ DeviceControlPoint
Returns a new instance of DeviceControlPoint.
9 10 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 |
# File 'lib/easy_upnp/device_control_point.rb', line 9 def initialize(urn, service_endpoint, definition, ) @urn = urn @service_endpoint = service_endpoint = @definition = definition @client = Savon.client do |c| c.endpoint service_endpoint c.namespace urn # I found this was necessary on some of my UPnP devices (namely, a Sony TV). c.namespaces({:'s:encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"}) # This makes XML tags be like <ObjectID> instead of <objectID>. c.convert_request_keys_to :camelcase c.namespace_identifier :u c.env_namespace :s end definition_xml = Nokogiri::XML(definition) definition_xml.remove_namespaces! service_methods = [] definition_xml.xpath('//actionList/action').map do |action| service_methods.push define_action(action) end @service_methods = service_methods end |
Instance Attribute Details
#service_methods ⇒ Object (readonly)
Returns the value of attribute service_methods.
7 8 9 |
# File 'lib/easy_upnp/device_control_point.rb', line 7 def service_methods @service_methods end |
Class Method Details
.from_params(params) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/easy_upnp/device_control_point.rb', line 49 def self.from_params(params) DeviceControlPoint.new( params[:urn], params[:service_endpoint], params[:definition], params[:options] ) end |
.from_service_definition(definition, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/easy_upnp/device_control_point.rb', line 58 def self.from_service_definition(definition, = {}) urn = definition[:st] root_uri = definition[:location] xml = Nokogiri::XML(open(root_uri)) xml.remove_namespaces! service = xml.xpath("//device/serviceList/service[serviceType=\"#{urn}\"]").first if service.nil? raise RuntimeError.new "Couldn't find service with urn: #{urn}" else service = Nokogiri::XML(service.to_xml) service_definition_uri = URI.join(root_uri, service.xpath('service/SCPDURL').text).to_s service_definition = open(service_definition_uri) { |f| f.read } DeviceControlPoint.new( urn, URI.join(root_uri, service.xpath('service/controlURL').text).to_s, service_definition, ) end end |
Instance Method Details
#to_params ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/easy_upnp/device_control_point.rb', line 40 def to_params { urn: @urn, service_endpoint: @service_endpoint, definition: @definition, options: } end |