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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f221d9078fe102b8e77ebb58ca47ed42fb2aee9
4
- data.tar.gz: 4d5923c767676e4736119861c8a3227f1069899a
3
+ metadata.gz: 1338c1f0db214e261d4ecbbab5399d76cf2c9b49
4
+ data.tar.gz: 8aa4df3b3988b7e9d7b61f1f93a90a7f62640103
5
5
  SHA512:
6
- metadata.gz: ee249aa826dacdaa9dc626278f682fd4f3fffcc3ee10ed23fe17db91e8bc1568febbb6fdc3b4e1a2ee5736994befe9cfb10caa97b4562dca0d4eb34ae20ecbb3
7
- data.tar.gz: cd0d118f709621db1d31ec90143f81962d9b920999ff9da1e378d16f7617f9c50379efe56f37b0b615a1b15a73ba6d14db8cb89f15a6ff697000bf78f25d06b5
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
- def self.default_config(handler_config)
18
- config.handlers.irkit.deviceid = ENV["IRKIT_DEVICEID"]
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
@@ -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, 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 register (.+)/, :ir_register, command: true, help: { "ir register [command_name]" => "register irkit command" }
15
- route /^ir unregister (.+)/, :ir_unregister, command: true, help: { "ir unregister [command_name]" => "unregister irkit command" }
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["irkit:messages:#{cmd}"] = JSON.parse(ir_data)['message'].to_json
27
- response.reply "ir data saved: #{cmd}"
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["irkit:messages:#{cmd}"]
33
+ message = Lita.redis[key_for_cmd(cmd)]
33
34
  return response.reply 'ir data not found' unless message
34
35
 
35
- irkit_api.post('/1/messages', clientkey: config.clientkey, deviceid: config.deviceid, message: message)
36
- response.reply "ir data send: #{cmd}"
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 "irkit:messages:#{cmd}"
42
- response.reply "ir data deleted: #{cmd}"
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-irkit"
3
- spec.version = "0.0.3"
3
+ spec.version = "0.0.4"
4
4
  spec.authors = ["fukayatsu"]
5
5
  spec.email = ["fukayatsu@gmail.com"]
6
6
  spec.description = %q{Use IRKit on Lita}
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.3
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-15 00:00:00.000000000 Z
11
+ date: 2014-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita