Skip to content

Commit 810cf61

Browse files
committed
Support follower IDs API
1 parent ad807eb commit 810cf61

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

lib/line/bot/client.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,20 @@ def get_room_member_profile(room_id, user_id)
274274
get(endpoint, endpoint_path, credentials)
275275
end
276276

277+
# Get user IDs of who added your LINE Official Account as a friend
278+
#
279+
# @param continuation_token [String] Identifier to return next page
280+
# (next property to be included in the response)
281+
#
282+
# @return [Net::HTTPResponse]
283+
def get_follower_ids(continuation_token = nil)
284+
channel_token_required
285+
286+
endpoint_path = "/bot/followers/ids"
287+
endpoint_path += "?start=#{continuation_token}" if continuation_token
288+
get(endpoint, endpoint_path, credentials)
289+
end
290+
277291
# Get user IDs of a group
278292
#
279293
# @param group_id [String] Group's identifier
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
require 'spec_helper'
2+
require 'webmock/rspec'
3+
require 'json'
4+
5+
USER_ID_CONTENT = <<"EOS"
6+
{
7+
"userIds": [
8+
"Uxxxxxxxxxxxxxx1",
9+
"Uxxxxxxxxxxxxxx2",
10+
"Uxxxxxxxxxxxxxx3"
11+
],
12+
"next": "jxEWCEEP"
13+
}
14+
EOS
15+
16+
NEXT_USER_ID_CONTENT = <<"EOS"
17+
{
18+
"userIds": [
19+
"Uxxxxxxxxxxxxxx4",
20+
"Uxxxxxxxxxxxxxx5",
21+
"Uxxxxxxxxxxxxxx6"
22+
]
23+
}
24+
EOS
25+
26+
describe Line::Bot::Client do
27+
before do
28+
end
29+
30+
def dummy_config
31+
{
32+
channel_token: 'access token',
33+
}
34+
end
35+
36+
def generate_client
37+
client = Line::Bot::Client.new do |config|
38+
config.channel_token = dummy_config[:channel_token]
39+
end
40+
41+
client
42+
end
43+
44+
it 'gets follower ids' do
45+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids'
46+
stub_request(:get, uri_template).to_return { |request| {body: USER_ID_CONTENT, status: 200} }
47+
48+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids?start={continuationToken}'
49+
stub_request(:get, uri_template).to_return { |request| {body: NEXT_USER_ID_CONTENT, status: 200} }
50+
51+
client = generate_client
52+
53+
# first page
54+
response = client.get_follower_ids
55+
56+
expect(response).to be_a(Net::HTTPOK)
57+
result = JSON.parse(response.body)
58+
expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx1", "Uxxxxxxxxxxxxxx2", "Uxxxxxxxxxxxxxx3"]
59+
expect(result['next']).to eq "jxEWCEEP"
60+
61+
# second page
62+
response = client.get_follower_ids(result['next'])
63+
64+
expect(response).to be_a(Net::HTTPOK)
65+
result = JSON.parse(response.body)
66+
expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx4", "Uxxxxxxxxxxxxxx5", "Uxxxxxxxxxxxxxx6"]
67+
expect(result['next']).to be nil
68+
end
69+
end

0 commit comments

Comments
 (0)