easy_upnp 0.1.7 → 0.1.8

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: d06b0e0d67f895da180b202c270c0407761dfaad
4
- data.tar.gz: 199921fe3b7074fa1a1049e13649fe12a7c3b592
3
+ metadata.gz: 017b7021b1d9c35fab09ff9f670a660c96758443
4
+ data.tar.gz: 793f938414da9e550a12b94aa90a05ba0de81480
5
5
  SHA512:
6
- metadata.gz: 183c88f2434861fe2ece10d326e6d7917c17ddc1a6d1c2dfc0547e7f1e5cfd4e986411e51529252ab94c0f780a6a1429fa289e0124ba9e4c54469501521adfe3
7
- data.tar.gz: 8abb23495b5cc314f310daac1999a0ce55519176250d5121a134e93939cafc44b9390dbda3ff250513dc391f58ef2cceaa51d0555f02f4db84ef0dff29853145
6
+ metadata.gz: 71e31a046b94b3e99cb6f79d87da6f2ee92fd06f209960ae67d0cb7457864bac839dfda9312ce8205b5fb4d8ac57d6c81f6673643343c6f84f044ff15b4e45ac
7
+ data.tar.gz: 689804ce65c657638e8098403d7ea33571b0b6ca69bfc2cc16f63488fcc9d74b3639eb03d0da63facf86a1fc11bdfbf8f05871123e81ce048091f970a4ae561b
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+ task test: :spec
@@ -10,8 +10,6 @@ module EasyUpnp
10
10
  MULTICAST_PORT = 1900
11
11
 
12
12
  DEFAULT_OPTIONS = {
13
- :bind_addr => '0.0.0.0',
14
-
15
13
  # Number of seconds to wait for responses
16
14
  :timeout => 2,
17
15
 
@@ -35,13 +33,12 @@ module EasyUpnp
35
33
  end
36
34
 
37
35
  def search urn
38
- listen_socket = build_listen_socket
39
- send_socket = build_send_socket
36
+ socket = build_socket
40
37
  packet = construct_msearch_packet(urn)
41
38
 
42
39
  # Send M-SEARCH packet over UDP socket
43
40
  option(:repeat_queries).times do
44
- send_socket.send packet, 0, MULTICAST_ADDR, MULTICAST_PORT
41
+ socket.send packet, 0, MULTICAST_ADDR, MULTICAST_PORT
45
42
  end
46
43
 
47
44
  raw_messages = []
@@ -50,14 +47,13 @@ module EasyUpnp
50
47
  begin
51
48
  Timeout::timeout(option :timeout) do
52
49
  loop do
53
- raw_messages.push(send_socket.recv(4196))
50
+ raw_messages.push(socket.recv(4196))
54
51
  end
55
52
  end
56
53
  rescue Timeout::Error
57
54
  # This is expected
58
55
  ensure
59
- send_socket.close
60
- listen_socket.close
56
+ socket.close
61
57
  end
62
58
 
63
59
  # Parse messages (extract HTTP headers)
@@ -101,22 +97,7 @@ ST: #{urn}\r
101
97
 
102
98
  private
103
99
 
104
- def build_listen_socket
105
- socket = UDPSocket.new
106
- socket.do_not_reverse_lookup = true
107
-
108
- membership = IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new(option :bind_addr).hton
109
-
110
- socket.setsockopt(:IPPROTO_IP, :IP_ADD_MEMBERSHIP, membership)
111
- socket.setsockopt(:SOL_SOCKET, :SO_REUSEADDR, true)
112
- socket.setsockopt(:IPPROTO_IP, :IP_TTL, 1)
113
-
114
- socket.bind(option(:bind_addr), MULTICAST_PORT)
115
-
116
- socket
117
- end
118
-
119
- def build_send_socket
100
+ def build_socket
120
101
  socket = UDPSocket.open
121
102
  socket.do_not_reverse_lookup = true
122
103
 
@@ -126,4 +107,4 @@ ST: #{urn}\r
126
107
  socket
127
108
  end
128
109
  end
129
- end
110
+ end
@@ -27,12 +27,17 @@ module EasyUpnp
27
27
  end
28
28
 
29
29
  # Download one of the definitions to get the name of this device
30
- service_location = @service_definitions.first[:location]
30
+ if @service_definitions.any?
31
+ service_location = @service_definitions.first[:location]
31
32
 
32
- xml = Nokogiri::XML(open(service_location))
33
- xml.remove_namespaces!
34
- @name = xml.xpath('//device/friendlyName').text
35
- @host = URI.parse(service_location).host
33
+ xml = Nokogiri::XML(open(service_location))
34
+ xml.remove_namespaces!
35
+ @name = xml.xpath('//device/friendlyName').text
36
+ @host = URI.parse(service_location).host
37
+ else
38
+ @name = 'UNKNOWN'
39
+ @host = 'UNKNOWN'
40
+ end
36
41
  end
37
42
 
38
43
  def all_services
@@ -1,3 +1,3 @@
1
1
  module EasyUpnp
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
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.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mullins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-30 00:00:00.000000000 Z
11
+ date: 2015-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -90,6 +90,7 @@ files:
90
90
  - Gemfile
91
91
  - LICENSE
92
92
  - README.md
93
+ - Rakefile
93
94
  - easy_upnp.gemspec
94
95
  - lib/easy_upnp/device_control_point.rb
95
96
  - lib/easy_upnp/ssdp_searcher.rb