lita-line 0.6.1 → 1.0.0.nightly.40
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 +4 -4
- data/.codeclimate.yml +16 -0
- data/.rubocop.yml +1156 -0
- data/.travis.yml +14 -3
- data/README.md +7 -1
- data/lib/lita/adapters/line.rb +1 -1
- data/lib/lita/adapters/line/client.rb +1 -1
- data/lib/lita/handlers/webhook.rb +9 -5
- data/lita-line.gemspec +3 -1
- data/spec/lita/adapters/line/client_spec.rb +2 -2
- data/spec/lita/adapters/line_spec.rb +35 -35
- data/spec/lita/handlers/webhook_spec.rb +52 -16
- metadata +21 -5
data/.travis.yml
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
|
4
|
+
- 2.3.1
|
5
5
|
script: bundle exec rake
|
6
6
|
before_install:
|
7
|
-
|
7
|
+
- gem update --system
|
8
8
|
services:
|
9
|
-
|
9
|
+
- redis-server
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: b3WMkStlgn09VthZit4RpetLVW/mIRL+mC+zVE37kf3jcvSmfRn0wbmdyZ1+71OB0nsYTwKUe4vZOScRfeu1/ME3QeFNLsjfY3JbwpBhihLSSTBmEfcwob4D/qS18GGcUqbjxHcxYydCA3yDxie6pTDsxwhxMzxrFUecyxCYxs94eiyytssm+TlAy/gsN55zudzU44HMpOOxiEuZUFDj1irkGli16/bJCNXMFvOD6R099FYKJ63rZJ2+H0b0YTHvr7p72wwktge5z51lgLNlFcWDjYuUfCRogO8LkmRd3kGyFrj+7RkHU3OWvqg/bESgDqzOsnH0baUQZrdsh9IxlaPdbhvdC9mB79V78E15NhLJ4aAYCiaZpJSOFQCN0pgEmX97YZ0zJVDnOarh1h1HiJM5Cs2vJ2QOD4qf1DlEIRlyxJyOUstZdQv+j7tYpkZOBlHbosbZ+7zTRBiIeCGqeAKTBrKwgJ2qCCwARe6G4WkvRNJSVZ83uvHQ25XJnQlO3io8PZhQhODtOnz0WfHtjY95eL66IYywnWxoUED5tjJlYuEmvRvw2ZeNcUnajaVL1dVVTdd/+nOy7JV4k7kdRRDvI+h0KapjA980BTByueUKV93yHN7c4q7u+ah67CaCGLSwSRU9BE9gdWstgdj97loiEvAJT7clsfijNVqOEYY=
|
14
|
+
gem: lita-line
|
15
|
+
on:
|
16
|
+
repo: aar0nTw/lita-line
|
17
|
+
addons:
|
18
|
+
code_climate:
|
19
|
+
repo_token:
|
20
|
+
secure: xsmLBjL5tg2SkdbBAEmQ01zd3sASOAOHoiGBdBYYRZF4NNaMrVDNz1Tvi+4Pv0KpCCbg5TALh1ougaZrlg33fEw8DYbQoVLTmzTbZTErXxb5k6kvB/Wjs2rDJ8zWz0CAT3w64xyLm/XmledB7oZa+dzZznW8P6H83Ibw8Qa+nlyPePyB/UoDv6oAKO4b76WjeNz8wSVGawqf0yQas+BbD966B7NnNtogV3AhHiGec/X9HDqJuV2Z6bBCRX/1Hs/YDOaieyoOIn6XU7nLghymTezNEPyk6DttZpRpdBR0n6KgLuhPfcTd6TtyGDnPhnlk/rLg3/tRjKGwHj3PNjJ0ser4VFO0dpmumt60htMAKUQC3tInmuGlI4Uumpo8Ra4IsaU20/jtJKdI75PYRolqyETnR5c+Z++tZOw/l7VskLBdVKow+9ZGrePGFuumEdXG/JsFbVAilgYUubU3opCXvQ20QtlE7iSL/rwZEZEDrx/8yvjmSsqnGF5PdBrrNs4ZUxEizp5KqzyAnLLXQVEI+IDDH3uLKdSrKfiUbK2SNkULJq+eUivwgpnmDybhmjGgTsnZzWwB1NROB0JQgH5Yd+Wb9pIkmmrSu+BTNjQ+Ywo4SQkA+XYS2aP1HrZJGHMqROsZXY3EybqlTFTZ1K0apj/b4Bw7CaNH9FdKhFQBv0w=
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# lita-line
|
2
2
|
[](https://rubygems.org/gems/lita-line)
|
3
3
|
[](https://rubygems.org/gems/lita-line)
|
4
|
+
[](https://gemnasium.com/github.com/aar0nTw/lita-line)
|
4
5
|
[](https://travis-ci.org/aar0nTw/lita-line)
|
6
|
+
[](https://codeclimate.com/github/aar0nTw/lita-line)
|
5
7
|
[](https://coveralls.io/github/aar0nTw/lita-line?branch=master)
|
6
8
|
|
7
|
-
|
9
|
+
LINE messaging webhook adapter for [Lita](https://github.com/litaio/lita)
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
@@ -40,6 +42,10 @@ Create a line bot at https://business.line.me/ and get it's secret and token in
|
|
40
42
|
|
41
43
|
The API documentation, useful for plugin authors, can be found for the latest gem release on [RubyDoc.info](http://www.rubydoc.info/gems/lita-line)
|
42
44
|
|
45
|
+
## Example
|
46
|
+
|
47
|
+
- [Lita-line-bot](https://github.com/aar0nTw/lita-line-bot) | A simple LINE messaging bot use Lita
|
48
|
+
|
43
49
|
## License
|
44
50
|
|
45
51
|
[MIT](http://opensource.org/licenses/MIT)
|
data/lib/lita/adapters/line.rb
CHANGED
@@ -27,11 +27,8 @@ module Lita
|
|
27
27
|
when ::Line::Bot::Event::Message
|
28
28
|
case event.type
|
29
29
|
when ::Line::Bot::Event::MessageType::Text
|
30
|
-
log.info "Webhook: #{DateTime.strptime(event['timestamp'].to_s, '%Q')
|
31
|
-
|
32
|
-
user = Lita::User.create('guest', {
|
33
|
-
name: 'Guest'
|
34
|
-
})
|
30
|
+
log.info "Webhook: #{DateTime.strptime(event['timestamp'].to_s, '%Q')}[#{event.message['id']}##{event.message['type']}]: #{event.message['text']} "
|
31
|
+
user = create_user event['source']
|
35
32
|
source = Lita::Source.new(user: user, room: event['replyToken'])
|
36
33
|
message = Lita::Message.new(robot, event.message['text'], source)
|
37
34
|
robot.receive(message)
|
@@ -42,6 +39,13 @@ module Lita
|
|
42
39
|
response.finish
|
43
40
|
end
|
44
41
|
|
42
|
+
def create_user(event_source)
|
43
|
+
source_type = event_source['type']
|
44
|
+
user = Lita::User.create(event_source["#{source_type}Id"], { type: source_type })
|
45
|
+
log.info "Create User: #{user.id} - #{user.metadata}"
|
46
|
+
user
|
47
|
+
end
|
48
|
+
|
45
49
|
http.post "/callback", :callback
|
46
50
|
|
47
51
|
Lita.register_handler(self)
|
data/lita-line.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-line"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.version = "#{spec.version}.nightly.#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
|
4
5
|
spec.authors = ["Aaron Huang"]
|
5
6
|
spec.email = ["aaroms9733@gmail.com"]
|
6
7
|
spec.description = "A line adapter for lita bot"
|
@@ -24,5 +25,6 @@ Gem::Specification.new do |spec|
|
|
24
25
|
spec.add_development_dependency "rack-test"
|
25
26
|
spec.add_development_dependency "rspec", ">= 3.0.0"
|
26
27
|
spec.add_development_dependency "simplecov"
|
28
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
|
27
29
|
spec.add_development_dependency "coveralls"
|
28
30
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'line/bot'
|
3
3
|
|
4
4
|
describe Lita::Adapters::Line::Client, lita: true do
|
5
|
-
subject { described_class.new(
|
5
|
+
subject { described_class.new(config) }
|
6
6
|
let(:robot) { Lita::Robot.new(registry) }
|
7
7
|
let(:line_client) {instance_double("Line::Bot::Client")}
|
8
8
|
let(:reply_token) { "reply_token" }
|
@@ -22,7 +22,7 @@ describe Lita::Adapters::Line::Client, lita: true do
|
|
22
22
|
it 'LineBotClien init' do
|
23
23
|
expect(config).to receive(:channel_secret)
|
24
24
|
expect(config).to receive(:channel_token)
|
25
|
-
described_class.new(
|
25
|
+
described_class.new(config)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'run should use EventMachine' do
|
@@ -5,6 +5,7 @@ describe Lita::Adapters::Line, lita: true do
|
|
5
5
|
|
6
6
|
let(:robot) { Lita::Robot.new(registry) }
|
7
7
|
let(:secret) { 'channel-secret' }
|
8
|
+
let(:client_type) { described_class::Client }
|
8
9
|
let(:client) { instance_double("#{described_class}::Client") }
|
9
10
|
let(:token) { 'channel-token' }
|
10
11
|
|
@@ -14,9 +15,6 @@ describe Lita::Adapters::Line, lita: true do
|
|
14
15
|
registry.config.adapters.line.channel_token = token
|
15
16
|
robot.config.robot.adapter = :line
|
16
17
|
|
17
|
-
allow(
|
18
|
-
described_class::Client
|
19
|
-
).to receive(:new).with(robot, subject.config).and_return(client)
|
20
18
|
allow(client).to receive(:run)
|
21
19
|
end
|
22
20
|
|
@@ -25,47 +23,49 @@ describe Lita::Adapters::Line, lita: true do
|
|
25
23
|
end
|
26
24
|
|
27
25
|
it 'running' do
|
26
|
+
described_class::Client.any_instance.stub(:run)
|
28
27
|
subject.run
|
29
|
-
expect(subject.client).to
|
28
|
+
expect(subject.client).to be_a client_type
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
it 'Chat service' do
|
44
|
-
subject.run
|
45
|
-
expect(subject.chat_service).to eq(client)
|
46
|
-
end
|
31
|
+
describe "Client#run" do
|
32
|
+
before do
|
33
|
+
allow(
|
34
|
+
described_class::Client
|
35
|
+
).to receive(:new).with(subject.config).and_return(client)
|
36
|
+
end
|
37
|
+
it 'client will run when adapter run' do
|
38
|
+
expect(client).to receive(:run)
|
39
|
+
subject.run
|
40
|
+
end
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
it 'Only run once' do
|
43
|
+
expect(client).to receive(:run).once
|
44
|
+
subject.run
|
45
|
+
subject.run
|
46
|
+
end
|
53
47
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
let(:client) {instance_double('Lita::Adapters::Line::Client')}
|
58
|
-
before do
|
59
|
-
allow(described_class::Client).to receive(:new).with(robot, subject.config).and_return(client)
|
60
|
-
allow(client).to receive(:send_messages).with(room_source.room, messages)
|
48
|
+
it 'Chat service' do
|
49
|
+
subject.run
|
50
|
+
expect(subject.chat_service).to eq(client)
|
61
51
|
end
|
62
52
|
|
63
|
-
it
|
64
|
-
expect(client).to receive(:
|
53
|
+
it 'Shut down will call client.stop' do
|
54
|
+
expect(client).to receive(:stop)
|
65
55
|
subject.run
|
66
|
-
subject.
|
56
|
+
subject.shut_down
|
67
57
|
end
|
68
|
-
end
|
69
58
|
|
59
|
+
describe 'Client#send_messages' do
|
60
|
+
let(:room_source) {Lita::Source.new(room: "reply_token")}
|
61
|
+
let(:messages) {["Hello world"]}
|
62
|
+
|
63
|
+
it "Send messages by client" do
|
64
|
+
expect(client).to receive(:send_messages).with(room_source.room, messages)
|
65
|
+
subject.run
|
66
|
+
subject.send_messages(room_source, messages)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
70
|
end
|
71
71
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
describe Lita::Handlers::Webhook, lita_handler: true do
|
4
5
|
|
@@ -28,24 +29,24 @@ describe Lita::Handlers::Webhook, lita_handler: true do
|
|
28
29
|
let(:response) { double }
|
29
30
|
let(:config) { double }
|
30
31
|
let(:body) { <<EOS
|
31
|
-
{
|
32
|
-
"events": [
|
33
32
|
{
|
34
|
-
"
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
"events": [
|
34
|
+
{
|
35
|
+
"replyToken": "reply_token",
|
36
|
+
"type": "message",
|
37
|
+
"timestamp": 1462629479859,
|
38
|
+
"source": {
|
39
|
+
"type": "user",
|
40
|
+
"userId": "U206d25c2ea6bd87c17655609a1c37cb8"
|
41
|
+
},
|
42
|
+
"message": {
|
43
|
+
"id": "325708",
|
44
|
+
"type": "text",
|
45
|
+
"text": "Hello, world"
|
46
|
+
}
|
45
47
|
}
|
48
|
+
]
|
46
49
|
}
|
47
|
-
]
|
48
|
-
}
|
49
50
|
EOS
|
50
51
|
}
|
51
52
|
let(:signature) { double }
|
@@ -59,7 +60,7 @@ EOS
|
|
59
60
|
request.stub(:env).and_return env
|
60
61
|
config.stub(:channel_secret).and_return 'secret'
|
61
62
|
config.stub(:channel_token).and_return 'token'
|
62
|
-
robot.stub_chain(:chat_service, :client).and_return(Lita::Adapters::Line::Client.new(
|
63
|
+
robot.stub_chain(:chat_service, :client).and_return(Lita::Adapters::Line::Client.new(config).client)
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'HTTP 401 when Line signature unvalidated' do
|
@@ -74,6 +75,41 @@ EOS
|
|
74
75
|
expect(response).to receive(:status=).with(200)
|
75
76
|
subject.callback(request, response)
|
76
77
|
end
|
78
|
+
|
79
|
+
it "Callback Should call @create_user function" do
|
80
|
+
Line::Bot::Client.any_instance.stub(:validate_signature => true)
|
81
|
+
allow(response).to receive(:status=).with(200)
|
82
|
+
expect(subject).to receive :create_user
|
83
|
+
subject.callback(request, response)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'Create User' do
|
88
|
+
let(:id) {'U206d25c2ea6bd87c17655609a1c37cb8'}
|
89
|
+
let(:event_source_json) { <<EOS
|
90
|
+
{
|
91
|
+
"type": "user",
|
92
|
+
"userId": "#{id}"
|
93
|
+
}
|
94
|
+
EOS
|
95
|
+
}
|
96
|
+
let(:event_source) { JSON.parse event_source_json }
|
97
|
+
|
98
|
+
it 'create_user should return a source instance' do
|
99
|
+
expect(subject.create_user event_source).to be_a Lita::User
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'create_user should return right metadata' do
|
103
|
+
event_source['type'] = 'group'
|
104
|
+
user = subject.create_user event_source
|
105
|
+
expect(user.metadata['type']).to eq 'group'
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'user object should have correct id' do
|
109
|
+
user = subject.create_user event_source
|
110
|
+
expect(user.id).to eq id
|
111
|
+
end
|
112
|
+
|
77
113
|
end
|
78
114
|
end
|
79
115
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-line
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.nightly.40
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: codeclimate-test-reporter
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.0.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.0.0
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: coveralls
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,8 +171,10 @@ executables: []
|
|
157
171
|
extensions: []
|
158
172
|
extra_rdoc_files: []
|
159
173
|
files:
|
174
|
+
- ".codeclimate.yml"
|
160
175
|
- ".gitignore"
|
161
176
|
- ".rspec"
|
177
|
+
- ".rubocop.yml"
|
162
178
|
- ".travis.yml"
|
163
179
|
- Gemfile
|
164
180
|
- LICENSE
|
@@ -190,12 +206,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
206
|
version: '0'
|
191
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
208
|
requirements:
|
193
|
-
- - "
|
209
|
+
- - ">"
|
194
210
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
211
|
+
version: 1.3.1
|
196
212
|
requirements: []
|
197
213
|
rubyforge_project:
|
198
|
-
rubygems_version: 2.
|
214
|
+
rubygems_version: 2.4.5
|
199
215
|
signing_key:
|
200
216
|
specification_version: 4
|
201
217
|
summary: ''
|