File tree Expand file tree Collapse file tree 4 files changed +53
-1
lines changed Expand file tree Collapse file tree 4 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -466,7 +466,7 @@ def parse_events_from(request_body)
466
466
467
467
json [ 'events' ] . map { |item |
468
468
begin
469
- klass = Line ::Bot ::Event . const_get ( item [ 'type' ] . capitalize )
469
+ klass = Line ::Bot ::Event . const_get ( camelize ( item [ 'type' ] ) )
470
470
klass . new ( item )
471
471
rescue NameError => e
472
472
Line ::Bot ::Event ::Base . new ( item )
@@ -510,6 +510,11 @@ def secure_compare(a, b)
510
510
b . each_byte { |byte | res |= byte ^ l . shift }
511
511
res == 0
512
512
end
513
+
514
+ # @return [String]
515
+ def camelize ( string )
516
+ string . split ( /_|(?=[A-Z])/ ) . map ( &:capitalize ) . join
517
+ end
513
518
end
514
519
end
515
520
end
Original file line number Diff line number Diff line change 13
13
# under the License.
14
14
15
15
require 'line/bot/event/base'
16
+ require 'line/bot/event/account_link'
16
17
require 'line/bot/event/beacon'
17
18
require 'line/bot/event/follow'
18
19
require 'line/bot/event/join'
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 145
145
"type": "enter",
146
146
"dm": "1234567890abcdef"
147
147
}
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
+ }
148
161
}
149
162
]
150
163
}
@@ -251,6 +264,10 @@ def generate_client
251
264
expect ( events [ 11 ] . type ) . to eq ( "enter" )
252
265
expect ( events [ 11 ] [ 'beacon' ] [ 'dm' ] ) . to eq ( "1234567890abcdef" )
253
266
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" )
254
271
end
255
272
256
273
it 'parses unknown event' do
You can’t perform that action at this time.
0 commit comments