easy_upnp 1.1.12 → 1.2.0

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
  SHA256:
3
- metadata.gz: babc894636ff772c95cdc3f7bbc1aa68f921b82a1ce6ffdc08e329f51aa9a115
4
- data.tar.gz: 5d2ae887cbc1a98e63b8ddd14cb2c7a33bff2f8556aead0d0e258a0ff2388f49
3
+ metadata.gz: 6da8d74ad1d393322eabbd9230e30806db4f3d98c7ccbb80444335f8969e1a73
4
+ data.tar.gz: ca9b39475ba3a8aacb598361ca2d0e56185cd15b84e03ba35921aa4fb2aff9fe
5
5
  SHA512:
6
- metadata.gz: 2878ae8736a92cc5a9bc32736b5da23f388eeffe30bd9bcd29321802e6858b3dd22819565352904b65260c0c78843af6ea25496fdd42817a1b07c68bb4de1fd8
7
- data.tar.gz: d95f475abf525a1aadb83417abdcab789266758ac13bd49778e1707ae92c45dc669fb44816fae0ceb028772a76b3ddd58492a89875d29ee2fae446406467bf9a
6
+ metadata.gz: 460fae3cfe1f5c2e29420668d45d9a866599aaf959e730129d07af12167bce2409622cc5035e52d2771b18511376d2d7ef977f69174bbc281b7b426120f95aaf
7
+ data.tar.gz: d64e502edc4b242ecf80262533fe8314cb819dfaa2cfc17324869690198035ef0b209c67fbe191ee6cfdcc8ec58c6fce4557075fcd1309cf78682830ae3534c0
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # easy_upnp
1
+ # easy_upnp [![Gem Version][shield-gem]][info-gem] [![Build Status][shield-travis]][info-travis]
2
+
2
3
  A super simple UPnP control point client for Ruby
3
4
 
4
5
  ## Installing
@@ -26,7 +27,7 @@ The `search` method takes one argument -- the "search target". This controls a h
26
27
  ```ruby
27
28
  require 'easy_upnp'
28
29
 
29
- searcher = EasyUpnp::SsdpSearcher.new
30
+ searcher = EasyUpnp::SsdpSearcher.new
30
31
  devices = searcher.search 'ssdp:all'
31
32
  ```
32
33
 
@@ -79,8 +80,8 @@ By default, logs will be printed to `$stdout` at the `:error` level. To change t
79
80
 
80
81
  ```ruby
81
82
  service = client.service(
82
- 'urn:schemas-upnp-org:service:ContentDirectory:1',
83
- log_enabled: true,
83
+ 'urn:schemas-upnp-org:service:ContentDirectory:1',
84
+ log_enabled: true,
84
85
  log_level: :info
85
86
  )
86
87
 
@@ -164,7 +165,7 @@ There are two ways you can subscribe to events with easy_upnp:
164
165
  1. Registering a custom HTTP endpoint.
165
166
  2. Providing a callback `lambda` or `Proc` which is called each time an event is fired.
166
167
 
167
- In the case of (2), easy_upnp behind the scenes starts a WEBrick HTTP server, which calls the provided callback whenever it receives an HTTP `NOTIFY` request.
168
+ In the case of (2), easy_upnp behind the scenes starts a WEBrick HTTP server, which calls the provided callback whenever it receives an HTTP `NOTIFY` request.
168
169
 
169
170
  Because event subscriptions expire, easy_upnp starts a background thread to renew the subscription on an interval.
170
171
 
@@ -177,7 +178,7 @@ To add a URL to be called on events:
177
178
  # URL will be called with HTTP NOTIFY requests from the service.
178
179
  manager = service.add_event_callback('http://myserver/path/to/callback')
179
180
 
180
- # The object that's returned allows you to manage the event subscription. To
181
+ # The object that's returned allows you to manage the event subscription. To
181
182
  # cancel the subscription, for example:
182
183
  manager.unsubscribe
183
184
 
@@ -199,7 +200,7 @@ end
199
200
 
200
201
  #### Calling ruby code
201
202
 
202
- If you don't want to have to set up an HTTP endpoint to listen to events, you can have easy_upnp do it for you. The `on_event` starts an internal HTTP server on an ephemeral port behind the scenes and triggers the provided callback each time a request is recieved.
203
+ If you don't want to have to set up an HTTP endpoint to listen to events, you can have easy_upnp do it for you. The `on_event` starts an internal HTTP server on an ephemeral port behind the scenes and triggers the provided callback each time a request is recieved.
203
204
 
204
205
  ```ruby
205
206
  # Parse and print the XML body of the request
@@ -239,8 +240,11 @@ manager = service.on_event(callback) do |c|
239
240
  c.configure_http_listener do |l|
240
241
  l.listen_port = 8888
241
242
  l.bind_address = '192.168.1.100'
243
+
244
+ # Don't parse XML body, pass raw contents to callback
245
+ l.event_parser = EasyUpnp::NoOpEventParser
242
246
  end
243
-
247
+
244
248
  c.configure_subscription_manager do |m|
245
249
  m.requested_timeout = 1800
246
250
  m.resubscription_interval_buffer = 60
@@ -249,3 +253,12 @@ manager = service.on_event(callback) do |c|
249
253
  end
250
254
  end
251
255
  ```
256
+
257
+ [info-gem]: https://rubygems.org/gems/easy_upnp
258
+ [shield-gem]: https://img.shields.io/gem/v/easy_upnp.svg
259
+
260
+ [info-travis]: https://travis-ci.org/sidoh/easy_upnp
261
+ [shield-travis]: https://img.shields.io/travis/sidoh/easy_upnp.svg
262
+
263
+ [info-coveralls]: https://coveralls.io/github/sidoh/easy_upnp
264
+ [shield-coveralls]: https://img.shields.io/coveralls/github/sidoh/easy_upnp.svg
@@ -1,7 +1,7 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  module EasyUpnp
4
- class EventParser
4
+ class DefaultEventParser
5
5
  def parse(event_xml)
6
6
  x = Nokogiri::XML(event_xml)
7
7
  prop_changes = x.xpath('//e:propertyset/e:property/*', e: 'urn:schemas-upnp-org:event-1-0').map do |n|
@@ -11,4 +11,10 @@ module EasyUpnp
11
11
  Hash[prop_changes]
12
12
  end
13
13
  end
14
+
15
+ class NoOpEventParser
16
+ def parse(event_xml)
17
+ event_xml
18
+ end
19
+ end
14
20
  end
@@ -1,7 +1,7 @@
1
1
  require 'webrick'
2
2
  require 'thread'
3
3
 
4
- require 'easy_upnp/events/event_parser'
4
+ require 'easy_upnp/events/event_parsers'
5
5
 
6
6
  module EasyUpnp
7
7
  class HttpListener
@@ -18,7 +18,11 @@ module EasyUpnp
18
18
  # By default, event callback just prints the changed state vars
19
19
  callback: ->(state_vars) {
20
20
  puts state_vars.inspect
21
- }
21
+ },
22
+
23
+ # Parses event bodies. By default parse the XML into a hash. Use
24
+ # EasyUpnp::NoOpEventParser to skip parsing
25
+ event_parser: EasyUpnp::DefaultEventParser
22
26
  }
23
27
 
24
28
  def initialize(options)
@@ -37,7 +41,7 @@ module EasyUpnp
37
41
  AccessLog: [],
38
42
  BindAddress: @options.bind_address
39
43
  )
40
- @server.mount('/', NotifyServlet, @options.callback)
44
+ @server.mount('/', NotifyServlet, @options.callback, @options.event_parser.new)
41
45
  end
42
46
 
43
47
  @listen_thread ||= Thread.new do
@@ -67,9 +71,9 @@ module EasyUpnp
67
71
  end
68
72
 
69
73
  class NotifyServlet < WEBrick::HTTPServlet::AbstractServlet
70
- def initialize(_server, block)
74
+ def initialize(_server, block, parser)
71
75
  @callback = block
72
- @parser = EasyUpnp::EventParser.new
76
+ @parser = parser
73
77
  end
74
78
 
75
79
  def do_NOTIFY(request, response)
@@ -1,3 +1,3 @@
1
1
  module EasyUpnp
2
- VERSION = '1.1.12'
2
+ VERSION = '1.2.0'
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: 1.1.12
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mullins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2017-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -87,7 +87,7 @@ files:
87
87
  - lib/easy_upnp/control_point/service_method.rb
88
88
  - lib/easy_upnp/control_point/validator_provider.rb
89
89
  - lib/easy_upnp/events/event_client.rb
90
- - lib/easy_upnp/events/event_parser.rb
90
+ - lib/easy_upnp/events/event_parsers.rb
91
91
  - lib/easy_upnp/events/http_listener.rb
92
92
  - lib/easy_upnp/events/subscription_manager.rb
93
93
  - lib/easy_upnp/options_base.rb
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.7.3
117
+ rubygems_version: 2.7.4
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: A super easy to use UPnP control point client