Class: EasyUpnp::UpnpDevice

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid, service_definitions) ⇒ UpnpDevice

Returns a new instance of UpnpDevice.



12
13
14
15
# File 'lib/easy_upnp/upnp_device.rb', line 12

def initialize(uuid, service_definitions)
  @uuid = uuid
  @service_definitions = service_definitions
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/easy_upnp/upnp_device.rb', line 10

def host
  @host
end

#uuidObject (readonly)

Returns the value of attribute uuid.



10
11
12
# File 'lib/easy_upnp/upnp_device.rb', line 10

def uuid
  @uuid
end

Class Method Details

.from_ssdp_messages(uuid, messages) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/easy_upnp/upnp_device.rb', line 17

def self.from_ssdp_messages(uuid, messages)
  service_definitions = messages.
      # Filter out messages that aren't service definitions. These include
      # the root device and the root UUID
      reject { |message| not message[:st].include? ':service:' }.
      # Distinct by ST header -- might have repeats if we sent multiple
      # M-SEARCH packets
      group_by { |message| message[:st] }.
      map { |_, matching_messages| matching_messages.first }.
      map do |message|
        {
            :location => message[:location],
            :st => message[:st]
        }
      end

  UpnpDevice.new(uuid, service_definitions)
end

Instance Method Details

#all_servicesObject



44
45
46
# File 'lib/easy_upnp/upnp_device.rb', line 44

def all_services
  @service_definitions.map { |x| x[:st] }
end

#device_nameObject



40
41
42
# File 'lib/easy_upnp/upnp_device.rb', line 40

def device_name
  @device_name ||= fetch_device_name
end

#has_service?(urn) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/easy_upnp/upnp_device.rb', line 48

def has_service?(urn)
  !service_definition(urn).nil?
end

#service(urn, options = {}, &block) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/easy_upnp/upnp_device.rb', line 52

def service(urn, options = {}, &block)
  definition = service_definition(urn)

  if !definition.nil?
    DeviceControlPoint.from_service_definition(definition, options, &block)
  end
end

#service_definition(urn) ⇒ Object



60
61
62
63
64
# File 'lib/easy_upnp/upnp_device.rb', line 60

def service_definition(urn)
  @service_definitions.
      reject { |s| s[:st] != urn }.
      first
end