lita-irkit 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/lib/lita/handlers/irkit.rb +34 -11
- data/lita-irkit.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1338c1f0db214e261d4ecbbab5399d76cf2c9b49
|
4
|
+
data.tar.gz: 8aa4df3b3988b7e9d7b61f1f93a90a7f62640103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b01628c98fea3a0e180a7bbd579f06c54fcc73673bef58665baf874e7ff775e8b7a9437bada57a0e949908cb6d29fecef4cf321177e85477bfa09ead4def90b4
|
7
|
+
data.tar.gz: c77db23ff6167d0ca79658bb1067a97560806b2cdff83e753c4497e222c6fe523f4b0d347e78783364b6f1e90689dda75bb34dce667841c99bdcc561c65410c9
|
data/README.md
CHANGED
@@ -14,10 +14,8 @@ gem "lita-irkit"
|
|
14
14
|
## Configuration
|
15
15
|
|
16
16
|
```
|
17
|
-
|
18
|
-
|
19
|
-
config.handlers.irkit.clientkey = ENV["IRKIT_CLIENTKEY"]
|
20
|
-
end
|
17
|
+
config.handlers.irkit.deviceid = ENV["IRKIT_DEVICEID"]
|
18
|
+
config.handlers.irkit.clientkey = ENV["IRKIT_CLIENTKEY"]
|
21
19
|
```
|
22
20
|
|
23
21
|
## Usage
|
data/lib/lita/handlers/irkit.rb
CHANGED
@@ -9,10 +9,11 @@ module Lita
|
|
9
9
|
handler_config.clientkey = ENV['IRKIT_CLIENTKEY']
|
10
10
|
end
|
11
11
|
|
12
|
-
route /^ir list/, :ir_list,
|
13
|
-
route /^ir send (.+)/, :ir_send,
|
14
|
-
route /^ir
|
15
|
-
route /^ir
|
12
|
+
route /^ir list/, :ir_list, command: false, help: { "ir list" => "list irkit command names" }
|
13
|
+
route /^ir send (.+)/, :ir_send, command: false, help: { "ir send [command_name]" => "send irkit command" }
|
14
|
+
route /^ir all off/, :ir_send_all_off, command: false, help: { "ir all off" => "send irkit commands which end with 'off'" }
|
15
|
+
route /^ir register (.+)/, :ir_register, command: true, help: { "ir register [command_name]" => "register irkit command" }
|
16
|
+
route /^ir unregister (.+)/, :ir_unregister, command: true, help: { "ir unregister [command_name]" => "unregister irkit command" }
|
16
17
|
|
17
18
|
def ir_list(response)
|
18
19
|
response.reply Lita.redis.keys('irkit:messages:*').map{|key| key.gsub(/^irkit:messages:/, '')}.join(', ')
|
@@ -23,23 +24,45 @@ module Lita
|
|
23
24
|
ir_data = irkit_api.get('/1/messages', clientkey: config.clientkey).body
|
24
25
|
return response.reply "ir data not found" if ir_data.length == 0
|
25
26
|
|
26
|
-
Lita.redis[
|
27
|
-
response.reply "
|
27
|
+
Lita.redis[key_for_cmd(cmd)] = JSON.parse(ir_data)['message'].to_json
|
28
|
+
response.reply ":ok_woman:"
|
28
29
|
end
|
29
30
|
|
30
31
|
def ir_send(response)
|
31
32
|
cmd = response.matches[0][0]
|
32
|
-
message = Lita.redis[
|
33
|
+
message = Lita.redis[key_for_cmd(cmd)]
|
33
34
|
return response.reply 'ir data not found' unless message
|
34
35
|
|
35
|
-
|
36
|
-
response.reply "
|
36
|
+
send_message(message)
|
37
|
+
response.reply ":ok_woman:"
|
38
|
+
end
|
39
|
+
|
40
|
+
def ir_send_all_off(response)
|
41
|
+
keys = Lita.redis.keys(key_for_all_off_cmd)
|
42
|
+
keys.each do |key|
|
43
|
+
message = Lita.redis[key]
|
44
|
+
send_message(message)
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
48
|
def ir_unregister(response)
|
40
49
|
cmd = response.matches[0][0]
|
41
|
-
Lita.redis.del
|
42
|
-
response.reply "
|
50
|
+
Lita.redis.del key_for_cmd(cmd)
|
51
|
+
response.reply ":ok_woman:"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def key_for_cmd(cmd)
|
57
|
+
"irkit:messages:#{cmd}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def key_for_all_off_cmd
|
61
|
+
"irkit:messages:*off"
|
62
|
+
end
|
63
|
+
|
64
|
+
def send_message(message)
|
65
|
+
irkit_api.post('/1/messages', clientkey: config.clientkey, deviceid: config.deviceid, message: message)
|
43
66
|
end
|
44
67
|
|
45
68
|
def config
|
data/lita-irkit.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-irkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fukayatsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|