Class: Druzy::Upnp::UpnpDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/druzy/upnp/upnp_device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ UpnpDevice

Returns a new instance of UpnpDevice.



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_device.rb', line 16

def initialize(args)
  
  if args[:ssdp_message] != nil
    
    mess = args[:ssdp_message]
    location=mess.split("\n").reject{|line| line==nil || line["LOCATION"]==nil}.first
    initialize(:location => location[location.index(" ")+1..location.size-2])
  
  elsif args[:location] != nil

    uri = URI(args[:location])
    xml=Net::HTTP.get(uri)
    xml_nok = Nokogiri::XML(xml)
    xml_nok.remove_namespaces!
    initialize(:uri => uri, :xml => Nokogiri::XML(xml_nok.xpath('root/device').to_s))
    
  else
    
    uri = args[:uri]
    xml_nok = args[:xml]
    @url_base = uri.scheme+'://'+uri.host+":"+uri.port.to_s
    @device_type = xml_nok.xpath('device/deviceType').text
    @friendly_name = xml_nok.xpath('device/friendlyName').text
    @manufacturer = xml_nok.xpath('device/manufacturer').text
    @manufacturer_url = xml_nok.xpath('device/manufacturerURL').text
    @model_description = xml_nok.xpath('device/modelDescription').text
    @model_name = xml_nok.xpath('device/modelName').text
    @model_number = xml_nok.xpath('device/modelNumber').text
    @model_url = xml_nok.xpath('device/modelURL').text
    @serial_number = xml_nok.xpath('device/serialNumber').text
    @udn = xml_nok.xpath('device/UDN').text
    @upc = xml_nok.xpath('device/UPC').text
    @icon_list = xml_nok.xpath('device/iconList/icon/url').to_a.collect{|el| @url_base+el.text}
    @service_list = xml_nok.xpath('device/serviceList/service').to_a.collect{|el| UpnpService.new(
      :service_type => el.xpath("serviceType").text,
      :service_id => el.xpath("serviceId").text,
      :location => @url_base+el.xpath("SCPDURL").text,
      :control_url => @url_base+el.xpath("controlURL").text,
      :event_sub_url => @url_base+el.xpath("eventSubURL").text
    )}
    @service_list.each do |service|
      method_name = service.service_id[service.service_id.rindex(':')+1..-1]
      define_singleton_method(method_name.to_sym) do
        return service
      end
    end
    
    @device_list = xml_nok.xpath('device/deviceList/device').to_a.collect{|el|
      UpnpDevice.new(
      :uri => uri,
      :xml => Nokogiri::XML(el.to_s)
    )}

  end
end

Instance Attribute Details

#device_listObject (readonly)

Returns the value of attribute device_list.



14
15
16
# File 'lib/druzy/upnp/upnp_device.rb', line 14

def device_list
  @device_list
end

#device_typeObject (readonly)

Returns the value of attribute device_type.



12
13
14
# File 'lib/druzy/upnp/upnp_device.rb', line 12

def device_type
  @device_type
end

#friendly_nameObject (readonly)

Returns the value of attribute friendly_name.



12
13
14
# File 'lib/druzy/upnp/upnp_device.rb', line 12

def friendly_name
  @friendly_name
end

#icon_listObject (readonly)

Returns the value of attribute icon_list.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def icon_list
  @icon_list
end

#manufacturerObject (readonly)

Returns the value of attribute manufacturer.



12
13
14
# File 'lib/druzy/upnp/upnp_device.rb', line 12

def manufacturer
  @manufacturer
end

#manufacturer_urlObject (readonly)

Returns the value of attribute manufacturer_url.



12
13
14
# File 'lib/druzy/upnp/upnp_device.rb', line 12

def manufacturer_url
  @manufacturer_url
end

#model_descriptionObject (readonly)

Returns the value of attribute model_description.



12
13
14
# File 'lib/druzy/upnp/upnp_device.rb', line 12

def model_description
  @model_description
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def model_name
  @model_name
end

#model_numberObject (readonly)

Returns the value of attribute model_number.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def model_number
  @model_number
end

#model_urlObject (readonly)

Returns the value of attribute model_url.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def model_url
  @model_url
end

#serial_numberObject (readonly)

Returns the value of attribute serial_number.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def serial_number
  @serial_number
end

#service_listObject (readonly)

Returns the value of attribute service_list.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def service_list
  @service_list
end

#udnObject (readonly)

Returns the value of attribute udn.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def udn
  @udn
end

#upcObject (readonly)

Returns the value of attribute upc.



13
14
15
# File 'lib/druzy/upnp/upnp_device.rb', line 13

def upc
  @upc
end

#url_baseObject (readonly)

Returns the value of attribute url_base.



12
13
14
# File 'lib/druzy/upnp/upnp_device.rb', line 12

def url_base
  @url_base
end