lita-irkit 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +2 -0
- data/lib/lita/handlers/irkit.rb +12 -7
- data/lita-irkit.gemspec +1 -1
- data/spec/lita/handlers/irkit_spec.rb +122 -0
- 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: dc5a5b5fcf056ff95bf9aba7e0db50dcd547a8f8
|
4
|
+
data.tar.gz: 3bae0c2d114dc0948a31cc5a2f27f0c564e87842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 259034c30629ce1b175f43660d034a13178d8b0586f00e0d4bbcd143320f59a842a57f60af2f7c8447a273caf7f57fe6fdcf8b49d6ec165f19f1c228f9c679d9
|
7
|
+
data.tar.gz: 97abd33ca4bc3c4cafbd83a4bd6d428c0f794f6676bfeecd4dadc8f99944b56de1d531477d952450c685abddf2af13216a9a80daa8cc09d3f58dd3f38768bf50
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/lib/lita/handlers/irkit.rb
CHANGED
@@ -15,15 +15,16 @@ module Lita
|
|
15
15
|
route /^ir migrate/, :ir_migrate, command: true
|
16
16
|
|
17
17
|
def ir_list(response)
|
18
|
-
response.reply
|
18
|
+
response.reply messages_redis.keys.sort.join(', ')
|
19
19
|
end
|
20
20
|
|
21
21
|
def ir_register(response)
|
22
22
|
cmd = response.matches[0][0]
|
23
|
-
|
23
|
+
response.reply "waiting for ir data..."
|
24
|
+
ir_data = irkit_api.get('messages', clientkey: config.clientkey, clear: 1).body
|
24
25
|
return response.reply "ir data not found" if ir_data.length == 0
|
25
26
|
|
26
|
-
|
27
|
+
messages_redis[cmd] = JSON.parse(ir_data)['message'].to_json
|
27
28
|
response.reply ":ok_woman:"
|
28
29
|
end
|
29
30
|
|
@@ -33,12 +34,12 @@ module Lita
|
|
33
34
|
if send_command(cmd)
|
34
35
|
response.reply ":ok_woman:"
|
35
36
|
else
|
36
|
-
response.reply 'ir data not found'
|
37
|
+
response.reply 'ir data not found'
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
41
|
def ir_send_all_off(response)
|
41
|
-
cmds =
|
42
|
+
cmds = messages_redis.keys('*off')
|
42
43
|
cmds.each do |cmd|
|
43
44
|
send_command(cmd)
|
44
45
|
end
|
@@ -47,7 +48,7 @@ module Lita
|
|
47
48
|
|
48
49
|
def ir_unregister(response)
|
49
50
|
cmd = response.matches[0][0]
|
50
|
-
|
51
|
+
messages_redis.del cmd
|
51
52
|
response.reply ":ok_woman:"
|
52
53
|
end
|
53
54
|
|
@@ -64,13 +65,17 @@ module Lita
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def send_command(command)
|
67
|
-
return false unless message =
|
68
|
+
return false unless message = messages_redis[command]
|
68
69
|
|
69
70
|
irkit_api.post('messages', clientkey: config.clientkey, deviceid: config.deviceid, message: message)
|
70
71
|
end
|
71
72
|
|
72
73
|
private
|
73
74
|
|
75
|
+
def messages_redis
|
76
|
+
@messages_redis ||= ::Redis::Namespace.new(:messages, redis: redis)
|
77
|
+
end
|
78
|
+
|
74
79
|
def irkit_api
|
75
80
|
@conn ||= Faraday.new(url: 'https://api.getirkit.com/1') do |faraday|
|
76
81
|
faraday.request :url_encoded # form-encode POST params
|
data/lita-irkit.gemspec
CHANGED
@@ -1,4 +1,126 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lita::Handlers::Irkit, lita_handler: true do
|
4
|
+
let(:irkit_api_stub) { Faraday::Adapter::Test::Stubs.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
conn = Faraday.new do |faraday|
|
8
|
+
faraday.adapter :test, irkit_api_stub
|
9
|
+
end
|
10
|
+
|
11
|
+
allow_any_instance_of(described_class).to receive(:irkit_api).and_return(conn)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'ir list' do
|
15
|
+
before do
|
16
|
+
Lita.redis['handlers:irkit:messages:foo'] = 'FOO'
|
17
|
+
Lita.redis['handlers:irkit:messages:bar'] = 'BAR'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'list irkit command names' do
|
21
|
+
send_message 'ir list'
|
22
|
+
|
23
|
+
expect(replies.last).to eq('bar, foo')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'ir send' do
|
28
|
+
before do
|
29
|
+
Lita.redis['handlers:irkit:messages:foo'] = 'FOO'
|
30
|
+
|
31
|
+
irkit_api_stub.post('messages', message: 'FOO', deviceid: nil, clientkey: nil) { [200, {}, ''] }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'happy case' do
|
35
|
+
it 'send irkit command' do
|
36
|
+
send_message 'ir send foo'
|
37
|
+
|
38
|
+
expect(replies.last).to eq(':ok_woman:')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'command not found' do
|
43
|
+
it 'do nothing' do
|
44
|
+
send_message 'ir send bar'
|
45
|
+
|
46
|
+
expect(replies.last).to eq('ir data not found')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'ir all off' do
|
52
|
+
before do
|
53
|
+
Lita.redis['handlers:irkit:messages:foo off'] = 'FOO'
|
54
|
+
Lita.redis['handlers:irkit:messages:bar_off'] = 'BAR'
|
55
|
+
Lita.redis['handlers:irkit:messages:baz'] = 'BAZ'
|
56
|
+
|
57
|
+
expect_any_instance_of(described_class).to receive(:send_command).with('foo off')
|
58
|
+
expect_any_instance_of(described_class).to receive(:send_command).with('bar_off')
|
59
|
+
expect_any_instance_of(described_class).to_not receive(:send_command).with('baz')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "send ir commands which end with 'off'" do
|
63
|
+
send_message 'ir all off'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'ir register' do
|
68
|
+
context 'happy case' do
|
69
|
+
before do
|
70
|
+
irkit_api_stub.get('messages') { [200, {}, {message: {foo: 'bar'}}.to_json] }
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'register irkit command' do
|
74
|
+
send_command 'ir register foo'
|
75
|
+
|
76
|
+
expect(replies.last).to eq(':ok_woman:')
|
77
|
+
expect(Lita.redis['handlers:irkit:messages:foo']).to eq({foo: 'bar'}.to_json)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'timeout' do
|
82
|
+
before do
|
83
|
+
irkit_api_stub.get('messages') { [200, {}, ''] }
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'say ng' do
|
87
|
+
send_command 'ir register foo'
|
88
|
+
|
89
|
+
expect(replies.last).to eq('ir data not found')
|
90
|
+
expect(Lita.redis['handlers:irkit:messages:foo']).to be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'ir unregister' do
|
96
|
+
before do
|
97
|
+
Lita.redis['handlers:irkit:messages:foo'] = 'FOO'
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'unregister irkit command' do
|
101
|
+
send_command 'ir unregister foo'
|
102
|
+
|
103
|
+
expect(replies.last).to eq(':ok_woman:')
|
104
|
+
expect(Lita.redis['handlers:irkit:messages:foo']).to be_nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'ir migrate' do
|
109
|
+
before do
|
110
|
+
Lita.redis['irkit:messages:foo'] = 'FOO'
|
111
|
+
Lita.redis['irkit:messages:bar'] = 'BAR'
|
112
|
+
Lita.redis['baz'] = 'BAZ'
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'migrate to new namespace' do
|
116
|
+
send_command 'ir migrate'
|
117
|
+
|
118
|
+
expect(replies.last).to eq(':ok_woman: 2 keys are migrated.')
|
119
|
+
|
120
|
+
expect(Lita.redis.keys('handlers:irkit:*')).to match_array([
|
121
|
+
'handlers:irkit:messages:foo',
|
122
|
+
'handlers:irkit:messages:bar'
|
123
|
+
])
|
124
|
+
end
|
125
|
+
end
|
4
126
|
end
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fukayatsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|