Skip to content

Commit 4fedc23

Browse files
committed
Support accountLink event
1 parent 107f361 commit 4fedc23

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

lib/line/bot/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require 'base64'
1818
require 'net/http'
1919
require 'openssl'
20+
require 'active_support/core_ext/string/inflections'
2021

2122
module Line
2223
module Bot
@@ -418,7 +419,7 @@ def parse_events_from(request_body)
418419

419420
json['events'].map { |item|
420421
begin
421-
klass = Line::Bot::Event.const_get(item['type'].capitalize)
422+
klass = Line::Bot::Event.const_get(item['type'].camelize)
422423
klass.new(item)
423424
rescue NameError => e
424425
Line::Bot::Event::Base.new(item)

lib/line/bot/event.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# under the License.
1414

1515
require 'line/bot/event/base'
16+
require 'line/bot/event/account_link'
1617
require 'line/bot/event/beacon'
1718
require 'line/bot/event/follow'
1819
require 'line/bot/event/join'

lib/line/bot/event/account_link.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2016 LINE
2+
#
3+
# LINE Corporation licenses this file to you under the Apache License,
4+
# version 2.0 (the "License"); you may not use this file except in compliance
5+
# with the License. You may obtain a copy of the License at:
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
module Line
16+
module Bot
17+
module Event
18+
class AccountLink < Base
19+
def result
20+
@src['link']['result']
21+
end
22+
23+
def nonce
24+
@src['link']['nonce']
25+
end
26+
end
27+
end
28+
end
29+
end

line-bot-api.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
1919

2020
spec.required_ruby_version = '>= 2.0.0'
2121

22+
spec.add_runtime_dependency "activesupport"
23+
2224
spec.add_development_dependency "addressable", "~> 2.3"
2325
spec.add_development_dependency "bundler", "~> 1.11"
2426
spec.add_development_dependency 'rake', "~> 10.4"

spec/line/bot/client_parse_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@
145145
"type": "enter",
146146
"dm": "1234567890abcdef"
147147
}
148+
},
149+
{
150+
"type": "accountLink",
151+
"replyToken": "replyToken",
152+
"source": {
153+
"type": "user",
154+
"userId": "userid"
155+
},
156+
"timestamp": 12345678901234,
157+
"link": {
158+
"result": "ok",
159+
"nonce": "nonce"
160+
}
148161
}
149162
]
150163
}
@@ -251,6 +264,10 @@ def generate_client
251264
expect(events[11].type).to eq("enter")
252265
expect(events[11]['beacon']['dm']).to eq("1234567890abcdef")
253266
expect(events[11].deviceMessage).to eq("\x12\x34\x56\x78\x90\xab\xcd\xef".b)
267+
268+
expect(events[12]).to be_a(Line::Bot::Event::AccountLink)
269+
expect(events[12].result).to eq("ok")
270+
expect(events[12].nonce).to eq("nonce")
254271
end
255272

256273
it 'parses unknown event' do

0 commit comments

Comments
 (0)