lita-irkit 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc4e1799d85b776ce4bb87623d8aa3d567a3a17b
4
- data.tar.gz: 5dc5038f08b66dee9a7386832d1dbbc210ea9487
3
+ metadata.gz: dc5a5b5fcf056ff95bf9aba7e0db50dcd547a8f8
4
+ data.tar.gz: 3bae0c2d114dc0948a31cc5a2f27f0c564e87842
5
5
  SHA512:
6
- metadata.gz: 4b6add3d4a8d6094c851bf615f1acc1c8e22e3e33d03346ec66c190056497f15aa25b41fc790a182790e07222b63dea8f65335766e4e9f48cba8932bc1b3435d
7
- data.tar.gz: 3f097080c6bf1fed561970bf852c6f7e50b1746b5555367bc9564b30163931bbc64f275ee9c16325388f0f00d833a48cec176051e62954529070d21ff216cde9
6
+ metadata.gz: 259034c30629ce1b175f43660d034a13178d8b0586f00e0d4bbcd143320f59a842a57f60af2f7c8447a273caf7f57fe6fdcf8b49d6ec165f19f1c228f9c679d9
7
+ data.tar.gz: 97abd33ca4bc3c4cafbd83a4bd6d428c0f794f6676bfeecd4dadc8f99944b56de1d531477d952450c685abddf2af13216a9a80daa8cc09d3f58dd3f38768bf50
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1
4
+ - 2.2
4
5
  script: bundle exec rake
5
6
  before_install:
6
7
  - gem update --system
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Use IRKit on Lita
4
4
 
5
+ [![Build Status](https://travis-ci.org/fukayatsu/lita-irkit.svg?branch=master)](https://travis-ci.org/fukayatsu/lita-irkit)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add lita-irkit to your Lita instance's Gemfile:
@@ -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 redis.keys.map{ |key| key.sub(/^messages:/, '') }.join(', ')
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
- ir_data = irkit_api.get('messages', clientkey: config.clientkey).body
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
- redis["messages:#{cmd}"] = JSON.parse(ir_data)['message'].to_json
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' unless message
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 = redis.keys('messages:*off').map{ |key| key.sub(/^messages:/, '') }
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
- redis.del "messages:#{cmd}"
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 = redis["messages:#{command}"]
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,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-irkit"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.1.1"
4
4
  spec.authors = ["fukayatsu"]
5
5
  spec.email = ["fukayatsu@gmail.com"]
6
6
  spec.description = %q{Use IRKit on Lita}
@@ -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.0
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-04-25 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita