Class: UPnP::SSDP::Notification
- Inherits:
-
Advertisement
- Object
- Advertisement
- UPnP::SSDP::Notification
- Defined in:
- lib/UPnP/SSDP.rb
Overview
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.
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Date the notification was received.
-
#host ⇒ Object
readonly
Host the notification was sent from.
-
#location ⇒ Object
readonly
Location of the advertised service or device.
-
#max_age ⇒ Object
readonly
Maximum age the advertisement is valid for.
-
#name ⇒ Object
readonly
Unique Service Name of the advertisement.
-
#port ⇒ Object
readonly
Port the notification was sent from.
-
#server ⇒ Object
readonly
Server name and version of the advertised service or device.
-
#sub_type ⇒ Object
readonly
Notification sub-type.
-
#type ⇒ Object
readonly
Type of the advertised service or device.
Class Method Summary collapse
-
.parse(advertisement) ⇒ Object
Parses a NOTIFY advertisement into its component pieces.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Returns true if this is a notification for a resource being alive.
-
#byebye? ⇒ Boolean
Returns true if this is a notification for a resource going away.
-
#initialize(date, max_age, host, port, location, type, sub_type, server, name) ⇒ Notification
constructor
Creates a new Notification.
-
#inspect ⇒ Object
A friendlier inspect.
Methods inherited from Advertisement
Constructor Details
#initialize(date, max_age, host, port, location, type, sub_type, server, name) ⇒ Notification
Creates a new Notification
147 148 149 150 151 152 153 154 155 156 157 158 |
# 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 |
Instance Attribute Details
#date ⇒ Object (readonly)
Date the notification was received
70 71 72 |
# File 'lib/UPnP/SSDP.rb', line 70 def date @date end |
#host ⇒ Object (readonly)
Host the notification was sent from
75 76 77 |
# File 'lib/UPnP/SSDP.rb', line 75 def host @host end |
#location ⇒ Object (readonly)
Location of the advertised service or device
85 86 87 |
# File 'lib/UPnP/SSDP.rb', line 85 def location @location end |
#max_age ⇒ Object (readonly)
Maximum age the advertisement is valid for
90 91 92 |
# File 'lib/UPnP/SSDP.rb', line 90 def max_age @max_age end |
#name ⇒ Object (readonly)
Unique Service Name of the advertisement
95 96 97 |
# File 'lib/UPnP/SSDP.rb', line 95 def name @name end |
#port ⇒ Object (readonly)
Port the notification was sent from
80 81 82 |
# File 'lib/UPnP/SSDP.rb', line 80 def port @port end |
#server ⇒ Object (readonly)
Server name and version of the advertised service or device
100 101 102 |
# File 'lib/UPnP/SSDP.rb', line 100 def server @server end |
#sub_type ⇒ Object (readonly)
Notification sub-type
105 106 107 |
# File 'lib/UPnP/SSDP.rb', line 105 def sub_type @sub_type end |
#type ⇒ Object (readonly)
Type of the advertised service or device
110 111 112 |
# File 'lib/UPnP/SSDP.rb', line 110 def type @type end |
Class Method Details
.parse(advertisement) ⇒ Object
Parses a NOTIFY advertisement into its component pieces
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/UPnP/SSDP.rb', line 115 def self.parse(advertisement) advertisement = advertisement.gsub "\r", '' advertisement =~ /^host:\s*(\S*)/i host, port = $1.split ':' advertisement =~ /^nt:\s*(\S*)/i type = $1 advertisement =~ /^nts:\s*(\S*)/i sub_type = $1 advertisement =~ /^usn:\s*(\S*)/i name = $1 if sub_type == 'ssdp:alive' then advertisement =~ /^cache-control:\s*max-age\s*=\s*(\d+)/i max_age = Integer $1 advertisement =~ /^location:\s*(\S*)/i location = URI.parse $1 advertisement =~ /^server:\s*(.*)/i server = $1.strip end new Time.now, max_age, host, port, location, type, sub_type, server, name end |
Instance Method Details
#alive? ⇒ Boolean
Returns true if this is a notification for a resource being alive
163 164 165 |
# File 'lib/UPnP/SSDP.rb', line 163 def alive? sub_type == 'ssdp:alive' end |
#byebye? ⇒ Boolean
Returns true if this is a notification for a resource going away
170 171 172 |
# File 'lib/UPnP/SSDP.rb', line 170 def byebye? sub_type == 'ssdp:byebye' end |
#inspect ⇒ Object
A friendlier inspect
177 178 179 180 |
# 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 |