lita-irkit 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -4
- data/lib/lita/handlers/irkit.rb +29 -28
- data/lita-irkit.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc4e1799d85b776ce4bb87623d8aa3d567a3a17b
|
4
|
+
data.tar.gz: 5dc5038f08b66dee9a7386832d1dbbc210ea9487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b6add3d4a8d6094c851bf615f1acc1c8e22e3e33d03346ec66c190056497f15aa25b41fc790a182790e07222b63dea8f65335766e4e9f48cba8932bc1b3435d
|
7
|
+
data.tar.gz: 3f097080c6bf1fed561970bf852c6f7e50b1746b5555367bc9564b30163931bbc64f275ee9c16325388f0f00d833a48cec176051e62954529070d21ff216cde9
|
data/README.md
CHANGED
@@ -21,10 +21,20 @@ config.handlers.irkit.clientkey = ENV["IRKIT_CLIENTKEY"]
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```
|
24
|
-
route /^ir list/,
|
25
|
-
route /^ir
|
26
|
-
route /^ir
|
27
|
-
route /^ir
|
24
|
+
route /^ir list/, :ir_list, command: false, help: { "ir list" => "list irkit command names" }
|
25
|
+
route /^ir send (.+)/, :ir_send, command: false, help: { "ir send [command_name]" => "send irkit command" }
|
26
|
+
route /^ir all off/, :ir_send_all_off, command: false, help: { "ir all off" => "send irkit commands which end with 'off'" }
|
27
|
+
route /^ir register (.+)/, :ir_register, command: true, help: { "ir register [command_name]" => "register irkit command" }
|
28
|
+
route /^ir unregister (.+)/, :ir_unregister, command: true, help: { "ir unregister [command_name]" => "unregister irkit command" }
|
29
|
+
route /^ir migrate/, :ir_migrate, command: true
|
30
|
+
```
|
31
|
+
|
32
|
+
## Migration from 0.0.x to 0.1.0
|
33
|
+
Since Redis namespace has been changed at v0.1.0, You must run migration command when upgrading to v0.1.0 or later.
|
34
|
+
|
35
|
+
```
|
36
|
+
@your_bot ir migrate
|
37
|
+
#=> :ok_woman: 10 keys are migrated.
|
28
38
|
```
|
29
39
|
|
30
40
|
## License
|
data/lib/lita/handlers/irkit.rb
CHANGED
@@ -4,74 +4,75 @@ require 'json'
|
|
4
4
|
module Lita
|
5
5
|
module Handlers
|
6
6
|
class Irkit < Handler
|
7
|
-
|
8
|
-
|
9
|
-
handler_config.clientkey = ENV['IRKIT_CLIENTKEY']
|
10
|
-
end
|
7
|
+
config :deviceid, required: true, default: ENV['IRKIT_DEVICEID']
|
8
|
+
config :clientkey, required: true, default: ENV['IRKIT_CLIENTKEY']
|
11
9
|
|
12
10
|
route /^ir list/, :ir_list, command: false, help: { "ir list" => "list irkit command names" }
|
13
11
|
route /^ir send (.+)/, :ir_send, command: false, help: { "ir send [command_name]" => "send irkit command" }
|
14
12
|
route /^ir all off/, :ir_send_all_off, command: false, help: { "ir all off" => "send irkit commands which end with 'off'" }
|
15
13
|
route /^ir register (.+)/, :ir_register, command: true, help: { "ir register [command_name]" => "register irkit command" }
|
16
14
|
route /^ir unregister (.+)/, :ir_unregister, command: true, help: { "ir unregister [command_name]" => "unregister irkit command" }
|
15
|
+
route /^ir migrate/, :ir_migrate, command: true
|
17
16
|
|
18
17
|
def ir_list(response)
|
19
|
-
response.reply
|
18
|
+
response.reply redis.keys.map{ |key| key.sub(/^messages:/, '') }.join(', ')
|
20
19
|
end
|
21
20
|
|
22
21
|
def ir_register(response)
|
23
22
|
cmd = response.matches[0][0]
|
24
|
-
ir_data = irkit_api.get('
|
23
|
+
ir_data = irkit_api.get('messages', clientkey: config.clientkey).body
|
25
24
|
return response.reply "ir data not found" if ir_data.length == 0
|
26
25
|
|
27
|
-
|
26
|
+
redis["messages:#{cmd}"] = JSON.parse(ir_data)['message'].to_json
|
28
27
|
response.reply ":ok_woman:"
|
29
28
|
end
|
30
29
|
|
31
30
|
def ir_send(response)
|
32
31
|
cmd = response.matches[0][0]
|
33
|
-
message = Lita.redis[key_for_cmd(cmd)]
|
34
|
-
return response.reply 'ir data not found' unless message
|
35
32
|
|
36
|
-
|
37
|
-
|
33
|
+
if send_command(cmd)
|
34
|
+
response.reply ":ok_woman:"
|
35
|
+
else
|
36
|
+
response.reply 'ir data not found' unless message
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def ir_send_all_off(response)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
send_message(message)
|
41
|
+
cmds = redis.keys('messages:*off').map{ |key| key.sub(/^messages:/, '') }
|
42
|
+
cmds.each do |cmd|
|
43
|
+
send_command(cmd)
|
45
44
|
end
|
46
45
|
response.reply ":ok_woman:"
|
47
46
|
end
|
48
47
|
|
49
48
|
def ir_unregister(response)
|
50
49
|
cmd = response.matches[0][0]
|
51
|
-
|
50
|
+
redis.del "messages:#{cmd}"
|
52
51
|
response.reply ":ok_woman:"
|
53
52
|
end
|
54
53
|
|
55
|
-
|
54
|
+
def ir_migrate(response)
|
55
|
+
keys = Lita.redis.keys('irkit:messages:*')
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
Lita.redis.pipelined do
|
58
|
+
keys.each do |key|
|
59
|
+
Lita.redis.rename key, key.sub(/^irkit:messages:/, 'handlers:irkit:messages:')
|
60
|
+
end
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
"irkit:messages:*off"
|
63
|
+
response.reply ":ok_woman: #{keys.size} keys are migrated."
|
63
64
|
end
|
64
65
|
|
65
|
-
def
|
66
|
-
|
67
|
-
end
|
66
|
+
def send_command(command)
|
67
|
+
return false unless message = redis["messages:#{command}"]
|
68
68
|
|
69
|
-
|
70
|
-
Lita.config.handlers.irkit
|
69
|
+
irkit_api.post('messages', clientkey: config.clientkey, deviceid: config.deviceid, message: message)
|
71
70
|
end
|
72
71
|
|
72
|
+
private
|
73
|
+
|
73
74
|
def irkit_api
|
74
|
-
@conn ||= Faraday.new(url: 'https://api.getirkit.com') do |faraday|
|
75
|
+
@conn ||= Faraday.new(url: 'https://api.getirkit.com/1') do |faraday|
|
75
76
|
faraday.request :url_encoded # form-encode POST params
|
76
77
|
faraday.response :logger # log requests to STDOUT
|
77
78
|
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fukayatsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.4.5
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: Use IRKit on Lita
|