easy_upnp 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff03da48709a543a35dbfe13a1ece864d9337db6
4
- data.tar.gz: 61517d04933afc34e2465de2400c577d001b63fb
3
+ metadata.gz: ba225151d956a041aaadd246678194bb56d0dbf3
4
+ data.tar.gz: c75a1966c29b922dd79ec0e64f971f1504f77390
5
5
  SHA512:
6
- metadata.gz: 4dbf1e5b113b33fe94db16655421b17f22f72eb57f5deb80521a2f5d6c83e4b097384495370ace08124fdce9da5e1fef228d8b960fefa408a3cc15c0aefb83ff
7
- data.tar.gz: 50a3d09bd2a1d2fb00f8afab09fca6a95db15c1118a424fdde175e5ab2ddecd537109ef789dc163effac4e1708490c8667342c2c2088a3824dc6474b3c973f75
6
+ metadata.gz: 18148d3f3aacad599e4c618cfafdb3381c27a2fd1e079042f29c0975c0e04de0c408d634beee1b94b93f8db326d8256dfa72fbf854f5ae4fd6ce2462cfaa7dfc
7
+ data.tar.gz: fb9a6f08c5350ed95170705aa662cd638de2fe94b0698b7bea2f07c259ad1b337a33a1cca30cf72cddae434333c029ac3925c94e56cc2e3b9dcfce7dd3997b4a
data/bin/upnp-list ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'easy_upnp/ssdp_searcher'
5
+
6
+ DEFAULT_ST = 'ssdp:all'
7
+
8
+ search_option_keys = [:timeout, :repeat_queries]
9
+ options = {search_target: DEFAULT_ST}
10
+
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: upnp-list [options]"
13
+
14
+ opts.on("-t", "--timeout [SECONDS]") do |v|
15
+ options[:timeout] = v.to_i
16
+ end
17
+
18
+ opts.on("-r", "--repeat-queries [N]") do |v|
19
+ options[:repeat_queries] = v.to_i
20
+ end
21
+
22
+ opts.on("-s", "--search-target [STRING]", String,
23
+ "Specify UPnP search target (default \"ssdp:all\")") do |v|
24
+ options[:search_target] = v
25
+ end
26
+ end.parse!
27
+
28
+ puts "Starting SSDP search..."
29
+
30
+ search_options = options.select { |k, v| search_option_keys.include?(k) }
31
+ devices = EasyUpnp::SsdpSearcher.new(search_options).search(options[:search_target])
32
+
33
+ if devices.any?
34
+ puts "Found #{devices.count} devices:"
35
+ printf "%30s %45s %s\n", "Name", "UUID", "Services"
36
+
37
+ devices.each do |device|
38
+ printf "%30s %45s ", device.device_name, device.uuid
39
+
40
+ services = device.all_services
41
+ if services.any?
42
+ printf "%s\n", services.first
43
+
44
+ services[1..-1].each do |s|
45
+ printf "%30s %45s %s\n", "", "", s
46
+ end
47
+ else
48
+ puts "( None )"
49
+ end
50
+
51
+ puts
52
+ end
53
+ elsif options[:search_target] == DEFAULT_ST
54
+ puts "Couldn't find any UPnP devices."
55
+ else
56
+ puts "Couldn't find any UPnP devices with search target: \"#{options[:search_target]}\""
57
+ end
data/easy_upnp.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.email = 'chris@sidoh.org'
13
13
  gem.homepage = 'http://github.com/sidoh/easy_upnp'
14
14
 
15
- gem.add_dependency 'rake'
15
+ gem.add_dependency 'rake'
16
16
  gem.add_dependency 'savon', '~> 2.11.1'
17
17
  gem.add_dependency 'nori', '~> 2.6.0'
18
18
  gem.add_dependency 'nokogiri', '~> 1.6.6.2'
@@ -27,6 +27,7 @@ Gem::Specification.new do |gem|
27
27
  }
28
28
 
29
29
  gem.files = (all_files_without_ignores + dotfiles).sort
30
+ gem.executables = ["upnp-list"]
30
31
 
31
- gem.require_path = "lib"
32
+ gem.require_path = "lib"
32
33
  end
@@ -33,6 +33,18 @@ module EasyUpnp
33
33
  UpnpDevice.new(uuid, service_definitions)
34
34
  end
35
35
 
36
+ def device_name
37
+ if all_services.empty?
38
+ raise RuntimeError, "Couldn't resolve device name because no endpoints are defined"
39
+ end
40
+
41
+ document = open(service_definition(all_services.first)[:location]) { |f| f.read }
42
+ xml = Nokogiri::XML(document)
43
+ xml.remove_namespaces!
44
+
45
+ xml.xpath("//device/friendlyName").text
46
+ end
47
+
36
48
  def all_services
37
49
  @service_definitions.map { |x| x[:st] }
38
50
  end
@@ -1,3 +1,3 @@
1
1
  module EasyUpnp
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_upnp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mullins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -82,7 +82,8 @@ dependencies:
82
82
  version: 2.0.0
83
83
  description:
84
84
  email: chris@sidoh.org
85
- executables: []
85
+ executables:
86
+ - upnp-list
86
87
  extensions: []
87
88
  extra_rdoc_files: []
88
89
  files:
@@ -91,6 +92,7 @@ files:
91
92
  - LICENSE
92
93
  - README.md
93
94
  - Rakefile
95
+ - bin/upnp-list
94
96
  - easy_upnp.gemspec
95
97
  - lib/easy_upnp/device_control_point.rb
96
98
  - lib/easy_upnp/ssdp_searcher.rb