Class: UPnP::SSDP::Response

Inherits:
Advertisement show all
Defined in:
lib/UPnP/SSDP.rb

Overview

Holds information about a M-SEARCH response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Advertisement

#expiration, #expired?

Constructor Details

#initialize(date, max_age, location, server, target, name, ext) ⇒ Response

Creates a new Response



254
255
256
257
258
259
260
261
262
# File 'lib/UPnP/SSDP.rb', line 254

def initialize(date, max_age, location, server, target, name, ext)
  @date = date
  @max_age = max_age
  @location = location
  @server = server
  @target = target
  @name = name
  @ext = ext
end

Instance Attribute Details

#dateObject (readonly)

Date response was created or received



192
193
194
# File 'lib/UPnP/SSDP.rb', line 192

def date
  @date
end

#extObject (readonly)

true if MAN header was understood



197
198
199
# File 'lib/UPnP/SSDP.rb', line 197

def ext
  @ext
end

#locationObject (readonly)

URI where this device or service is described



202
203
204
# File 'lib/UPnP/SSDP.rb', line 202

def location
  @location
end

#max_ageObject (readonly)

Maximum age this advertisement is valid for



207
208
209
# File 'lib/UPnP/SSDP.rb', line 207

def max_age
  @max_age
end

#nameObject (readonly)

Unique Service Name



212
213
214
# File 'lib/UPnP/SSDP.rb', line 212

def name
  @name
end

#serverObject (readonly)

Server version string



217
218
219
# File 'lib/UPnP/SSDP.rb', line 217

def server
  @server
end

#targetObject (readonly)

Search target



222
223
224
# File 'lib/UPnP/SSDP.rb', line 222

def target
  @target
end

Class Method Details

.parse(response) ⇒ Object

Creates a new Response by parsing the text in response



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/UPnP/SSDP.rb', line 227

def self.parse(response)
  response =~ /^cache-control:\s*max-age\s*=\s*(\d+)/i
  max_age = Integer $1

  response =~ /^date:\s*(.*)/i
  date = $1 ? Time.parse($1) : Time.now

  ext = !!(response =~ /^ext:/i)

  response =~ /^location:\s*(\S*)/i
  location = URI.parse $1.strip

  response =~ /^server:\s*(.*)/i
  server = $1.strip

  response =~ /^st:\s*(\S*)/i
  target = $1.strip

  response =~ /^usn:\s*(\S*)/i
  name = $1.strip

  new date, max_age, location, server, target, name, ext
end

Instance Method Details

#inspectObject

A friendlier inspect



267
268
269
# File 'lib/UPnP/SSDP.rb', line 267

def inspect
  "#<#{self.class}:0x#{object_id.to_s 16} #{target} #{location}>"
end