easy_upnp 0.2.5 → 0.3.1

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: 664553443adb7bbc4003b3fe22d361fc6cee121a
4
- data.tar.gz: cc018adaff76a026018bb087779ca166098e30fc
3
+ metadata.gz: 09a7cd37e19fa3000aba9c64319d21705c2baec4
4
+ data.tar.gz: 4bd49da3316961699db45017841c6ec125c07114
5
5
  SHA512:
6
- metadata.gz: cb5c3136247b07d5b2ebcb0203b95712e4a808ad51d63b0cf1edef837f9c70595459de0fe104a2aedcffb3fd747024b0cc08a58172e6d6e1901fd68104df8700
7
- data.tar.gz: cdcee4ca55bdfe97d4c9fee3d3a8086ec2e31dff7c33d985187b75e61b6d489476c205646cef772fa552315d9ef0f8802a7c2f80bc6884ce209ad8f33b34b699
6
+ metadata.gz: f8727fe45dbd3888450c601afff69901ab18493d839afd49a4f6e1a460c1b29ad292ab0d4dba86d4ba7fea1f2fb03dbc033389032a7a713ff6f02aedd5c455d2
7
+ data.tar.gz: c1a7e693d5ce5b119e793a29f5f8cc1f1835d1430509fbb2a7e3000e121385d3b49c745289b8e6b452a20df01e1d24a3ac908f4591968a4084c98ad051eccf13
data/README.md CHANGED
@@ -72,3 +72,15 @@ client = EasyUpnp::DeviceControlPoint.from_params(params)
72
72
  client.GetSystemUpdateID
73
73
  => {:Id=>"258"}
74
74
  ```
75
+
76
+ ## Logging
77
+
78
+ By default, logs will be printed to `$stdout` at the `:info` level. To change this behavior, you can use the following:
79
+
80
+ ```ruby
81
+ # Disable logging
82
+ EasyUpnp::Log.enabled = false
83
+
84
+ # Change log level (only has an effect if logging is enabled)
85
+ EasyUpnp::Log.level = :debug
86
+ ```
@@ -8,11 +8,36 @@ module EasyUpnp
8
8
  class DeviceControlPoint
9
9
  attr_reader :service_methods, :service_endpoint
10
10
 
11
- def initialize(urn, service_endpoint, definition, options)
11
+ class Options
12
+ DEFAULTS = {
13
+ advanced_typecasting: true
14
+ }
15
+
16
+ attr_reader :options
17
+
18
+ def initialize(o = {}, &block)
19
+ @options = o.merge(DEFAULTS)
20
+
21
+ @options.map do |k, v|
22
+ define_singleton_method(k) do
23
+ @options[k]
24
+ end
25
+
26
+ define_singleton_method("#{k}=") do |v|
27
+ @options[k] = v
28
+ end
29
+ end
30
+
31
+ block.call(self) unless block.nil?
32
+ end
33
+ end
34
+
35
+ def initialize(urn, service_endpoint, definition, call_options, &block)
12
36
  @urn = urn
13
37
  @service_endpoint = service_endpoint
14
- @options = options
38
+ @call_options = call_options
15
39
  @definition = definition
40
+ @options = Options.new(&block)
16
41
 
17
42
  @client = Savon.client(log: EasyUpnp::Log.enabled?, log_level: EasyUpnp::Log.level) do |c|
18
43
  c.endpoint service_endpoint
@@ -44,7 +69,8 @@ module EasyUpnp
44
69
  urn: @urn,
45
70
  service_endpoint: @service_endpoint,
46
71
  definition: @definition,
47
- options: @options
72
+ call_options: @call_options,
73
+ options: @options.options
48
74
  }
49
75
  end
50
76
 
@@ -53,11 +79,13 @@ module EasyUpnp
53
79
  params[:urn],
54
80
  params[:service_endpoint],
55
81
  params[:definition],
56
- params[:options]
57
- )
82
+ params[:call_options]
83
+ ) { |c|
84
+ params[:options].map { |k, v| c.options[k] = v }
85
+ }
58
86
  end
59
87
 
60
- def self.from_service_definition(definition, options = {})
88
+ def self.from_service_definition(definition, call_options = {}, &block)
61
89
  urn = definition[:st]
62
90
  root_uri = definition[:location]
63
91
 
@@ -77,7 +105,8 @@ module EasyUpnp
77
105
  urn,
78
106
  URI.join(root_uri, service.xpath('service/controlURL').text).to_s,
79
107
  service_definition,
80
- options
108
+ call_options,
109
+ &block
81
110
  )
82
111
  end
83
112
  end
@@ -114,9 +143,10 @@ module EasyUpnp
114
143
  attributes: {
115
144
  :'xmlns:u' => @urn
116
145
  },
117
- }.merge(@options)
146
+ }.merge(@call_options)
118
147
 
119
148
  response = @client.call action['name'], attrs do
149
+ advanced_typecasting @options.advanced_typecasting
120
150
  message(args_hash)
121
151
  end
122
152
 
@@ -53,11 +53,11 @@ module EasyUpnp
53
53
  !service_definition(urn).nil?
54
54
  end
55
55
 
56
- def service(urn, options = {})
56
+ def service(urn, options = {}, &block)
57
57
  definition = service_definition(urn)
58
58
 
59
59
  if !definition.nil?
60
- DeviceControlPoint.from_service_definition(definition, options)
60
+ DeviceControlPoint.from_service_definition(definition, options, &block)
61
61
  end
62
62
  end
63
63
 
@@ -1,3 +1,3 @@
1
1
  module EasyUpnp
2
- VERSION = '0.2.5'
2
+ VERSION = '0.3.1'
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.5
4
+ version: 0.3.1
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-28 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake