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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f9374e8bd6b531e066c64258a5ccbbb2d1ee9a7
4
- data.tar.gz: 209ef8ece76ad641cf2cf813f097e7270cd5cb8a
3
+ metadata.gz: fc4e1799d85b776ce4bb87623d8aa3d567a3a17b
4
+ data.tar.gz: 5dc5038f08b66dee9a7386832d1dbbc210ea9487
5
5
  SHA512:
6
- metadata.gz: 1acdf7852b8c3b980ef37dec6998250ebb9b34d4e139d9ab9badc07e6821bea6f50196eb8020662fe3f00ecd6201645442d2cbf21a8aac5c3391903f915fa40a
7
- data.tar.gz: f0adb68a7aa27ef1cea92df57c12476aa72bc46846d1231fd4c0bea33b18f9b2c0c963d61e28b17aad1c7c0c54186de49a7a4d5886352bd28bf43f18cbde14a3
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/, :ir_list, command: true, help: { "ir list" => "list irkit command names" }
25
- route /^ir save (.+)/, :ir_save, command: true, help: { "ir save [command_name]" => "save irkit command as name" }
26
- route /^ir send (.+)/, :ir_send, command: true, help: { "ir send [command_name]" => "send irkit command" }
27
- route /^ir remove (.+)/, :ir_remove, command: true, help: { "ir remove [command_name]" => "remove irkit command" }
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
@@ -4,74 +4,75 @@ require 'json'
4
4
  module Lita
5
5
  module Handlers
6
6
  class Irkit < Handler
7
- def self.default_config(handler_config)
8
- handler_config.deviceid = ENV['IRKIT_DEVICEID']
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 Lita.redis.keys('irkit:messages:*').map{|key| key.gsub(/^irkit:messages:/, '')}.join(', ')
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('/1/messages', clientkey: config.clientkey).body
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
- Lita.redis[key_for_cmd(cmd)] = JSON.parse(ir_data)['message'].to_json
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
- send_message(message)
37
- response.reply ":ok_woman:"
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
- keys = Lita.redis.keys(key_for_all_off_cmd)
42
- keys.each do |key|
43
- message = Lita.redis[key]
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
- Lita.redis.del key_for_cmd(cmd)
50
+ redis.del "messages:#{cmd}"
52
51
  response.reply ":ok_woman:"
53
52
  end
54
53
 
55
- private
54
+ def ir_migrate(response)
55
+ keys = Lita.redis.keys('irkit:messages:*')
56
56
 
57
- def key_for_cmd(cmd)
58
- "irkit:messages:#{cmd}"
59
- end
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
- def key_for_all_off_cmd
62
- "irkit:messages:*off"
63
+ response.reply ":ok_woman: #{keys.size} keys are migrated."
63
64
  end
64
65
 
65
- def send_message(message)
66
- irkit_api.post('/1/messages', clientkey: config.clientkey, deviceid: config.deviceid, message: message)
67
- end
66
+ def send_command(command)
67
+ return false unless message = redis["messages:#{command}"]
68
68
 
69
- def config
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-irkit"
3
- spec.version = "0.0.5"
3
+ spec.version = "0.1.0"
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.5
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: 2014-11-16 00:00:00.000000000 Z
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.2.2
151
+ rubygems_version: 2.4.5
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Use IRKit on Lita