Holds information about a NOTIFY message. For an alive notification, all fields will be present. For a byebye notification, location, #max_age and server will be nil.
Date the notification was received
Host the notification was sent from
Location of the advertised service or device
Maximum age the advertisement is valid for
Unique Service Name of the advertisement
Port the notification was sent from
Server name and version of the advertised service or device
Notification sub-type
Type of the advertised service or device
Creates a new Notification
# File lib/UPnP/SSDP.rb, line 147 def initialize(date, max_age, host, port, location, type, sub_type, server, name) @date = date @max_age = max_age @host = host @port = port @location = location @type = type @sub_type = sub_type @server = server @name = name end
Parses a NOTIFY advertisement into its component pieces
# File lib/UPnP/SSDP.rb, line 115 def self.parse(advertisement) advertisement = advertisement.gsub "\r", '' advertisement =~ %r^host:\s*(\S*)/ host, port = $1.split ':' advertisement =~ %r^nt:\s*(\S*)/ type = $1 advertisement =~ %r^nts:\s*(\S*)/ sub_type = $1 advertisement =~ %r^usn:\s*(\S*)/ name = $1 if sub_type == 'ssdp:alive' then advertisement =~ %r^cache-control:\s*max-age\s*=\s*(\d+)/ max_age = Integer $1 advertisement =~ %r^location:\s*(\S*)/ location = URI.parse $1 advertisement =~ %r^server:\s*(.*)/ server = $1.strip end new Time.now, max_age, host, port, location, type, sub_type, server, name end
Returns true if this is a notification for a resource being alive
# File lib/UPnP/SSDP.rb, line 163 def alive? sub_type == 'ssdp:alive' end
Returns true if this is a notification for a resource going away
# File lib/UPnP/SSDP.rb, line 170 def byebye? sub_type == 'ssdp:byebye' end
A friendlier inspect
# File lib/UPnP/SSDP.rb, line 177 def inspect location = " #{@location}" if @location "#<#{self.class}:0x#{object_id.to_s 16} #{@type} #{@sub_type}#{location}>" end