guh 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/guh.gemspec +1 -0
- data/lib/guh.rb +4 -0
- data/lib/guh/base.rb +1 -1
- data/lib/guh/em/connection.rb +52 -0
- data/lib/guh/em/notifications.rb +13 -0
- data/lib/guh/rule.rb +3 -10
- data/lib/guh/rule_type.rb +7 -0
- data/lib/guh/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87351db5068f587695299eea4fd4265a42b3df8d
|
4
|
+
data.tar.gz: 11db8d20180f51f8f6ace596a091f27186e02d7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2f7884c6fb3d682f6031fea70e4a80b546f1a933b9b6b7c62691fc4eae5027473444fc506f9eaf060d09e69cba08f6ec83601542f0fa81d6f3557c900558d35
|
7
|
+
data.tar.gz: 4572217d7b13034211ce34a8f42f5f26844921be02778fe7a93ac3aa4682f2b6e8303a2bdcef5e4d8230b4c65cbeb5ab7d32503e394b0028624fb2bb3757e4a1
|
data/Rakefile
CHANGED
data/guh.gemspec
CHANGED
data/lib/guh.rb
CHANGED
@@ -11,9 +11,13 @@ require "guh/device_class"
|
|
11
11
|
require "guh/event_type"
|
12
12
|
require "guh/event"
|
13
13
|
require "guh/plugin"
|
14
|
+
require "guh/rule_type"
|
14
15
|
require "guh/rule"
|
15
16
|
require "guh/vendor"
|
16
17
|
|
18
|
+
require "guh/em/connection"
|
19
|
+
require "guh/em/notifications"
|
20
|
+
|
17
21
|
module Guh
|
18
22
|
# Your code goes here...
|
19
23
|
|
data/lib/guh/base.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
module Guh
|
4
|
+
##
|
5
|
+
# This class wraps everything related to Notifications.
|
6
|
+
#
|
7
|
+
|
8
|
+
module EM
|
9
|
+
class Connection < ::EventMachine::Connection
|
10
|
+
|
11
|
+
def onmessage(&block)
|
12
|
+
@onmessage = block
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_init
|
16
|
+
request_string = Guh::Base.hash_to_json({id: Guh::Base.generate_request_id, method: "JSONRPC.SetNotificationStatus", params: { enabled: true } })
|
17
|
+
send_data(request_string)
|
18
|
+
|
19
|
+
@message = ""
|
20
|
+
end
|
21
|
+
|
22
|
+
def receive_data(data)
|
23
|
+
|
24
|
+
data.each_line do |line|
|
25
|
+
@message << line
|
26
|
+
|
27
|
+
if line.match(/^\}\n/)
|
28
|
+
trigger_on_message(@message)
|
29
|
+
|
30
|
+
@message = ""
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def unbind
|
36
|
+
# TODO implement a callback to enable the notification of all clients about lost connection
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def trigger_on_message(message)
|
42
|
+
begin
|
43
|
+
@onmessage.call(JSON::parse(message))
|
44
|
+
rescue Exception => e
|
45
|
+
puts "--> rescue in guh.rb: #{e.inspect}"
|
46
|
+
return {}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/guh/rule.rb
CHANGED
@@ -27,20 +27,13 @@ module Guh
|
|
27
27
|
#
|
28
28
|
# Example:
|
29
29
|
#
|
30
|
-
# Guh::Rule.add(
|
30
|
+
# Guh::Rule.add(params)
|
31
31
|
#
|
32
|
-
def self.add(
|
33
|
-
unless actions.is_a?(Array)
|
34
|
-
actions = [actions]
|
35
|
-
end
|
36
|
-
|
32
|
+
def self.add(params)
|
37
33
|
get({
|
38
34
|
id: generate_request_id,
|
39
35
|
method: "Rules.AddRule",
|
40
|
-
params:
|
41
|
-
eventDescriptorList: event_descriptor_list,
|
42
|
-
actions: actions
|
43
|
-
}
|
36
|
+
params: params
|
44
37
|
})
|
45
38
|
end
|
46
39
|
|
data/lib/guh/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Edthofer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.8'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: eventmachine
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: bundler
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,10 +117,13 @@ files:
|
|
103
117
|
- lib/guh/base.rb
|
104
118
|
- lib/guh/device.rb
|
105
119
|
- lib/guh/device_class.rb
|
120
|
+
- lib/guh/em/connection.rb
|
121
|
+
- lib/guh/em/notifications.rb
|
106
122
|
- lib/guh/event.rb
|
107
123
|
- lib/guh/event_type.rb
|
108
124
|
- lib/guh/plugin.rb
|
109
125
|
- lib/guh/rule.rb
|
126
|
+
- lib/guh/rule_type.rb
|
110
127
|
- lib/guh/vendor.rb
|
111
128
|
- lib/guh/version.rb
|
112
129
|
- spec/helper.rb
|