Skip to content

Commit 4aba34d

Browse files
authored
Merge pull request #92 from a2ikm/feature/link_token
Support link token
2 parents 107f361 + ac18e06 commit 4aba34d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/line/bot/client.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ def create_rich_menu_image(rich_menu_id, file)
353353
request.post
354354
end
355355

356+
# Issue a link token to a user
357+
#
358+
# @param user_id [String] ID of the user
359+
#
360+
# @return [Net::HTTPResponse]
361+
def create_link_token(user_id)
362+
endpoint_path = "/bot/user/#{user_id}/linkToken"
363+
post(endpoint_path)
364+
end
365+
356366
# Fetch data, get content of specified URL.
357367
#
358368
# @param endpoint_path [String]

spec/line/bot/link_token_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'spec_helper'
2+
require 'webmock/rspec'
3+
require 'json'
4+
5+
LINK_TOKEN_CONTENT = <<"EOS"
6+
{
7+
"linkToken":"abcdefg0123456789"
8+
}
9+
EOS
10+
11+
WebMock.allow_net_connect!
12+
13+
describe Line::Bot::Client do
14+
let(:client) {
15+
dummy_config = {
16+
channel_token: 'access token',
17+
}
18+
Line::Bot::Client.new do |config|
19+
config.channel_token = dummy_config[:channel_token]
20+
end
21+
}
22+
23+
it 'issues a link token' do
24+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/user/{user_id}/linkToken'
25+
stub_request(:post, uri_template).to_return(body: LINK_TOKEN_CONTENT, status: 200)
26+
27+
response = client.create_link_token('user_id')
28+
expect(WebMock).to have_requested(:post, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/user/user_id/linkToken')
29+
expect(response.body).to eq LINK_TOKEN_CONTENT
30+
end
31+
end

0 commit comments

Comments
 (0)