Skip to content

Commit b79d0c1

Browse files
authored
Merge pull request #217 from chocoby/issue216-follower-ids-api
Support follower IDs API
2 parents ad807eb + 8261180 commit b79d0c1

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
def dummy_config
28+
{
29+
channel_token: 'access token',
30+
}
31+
end
32+
33+
def generate_client
34+
client = Line::Bot::Client.new do |config|
35+
config.channel_token = dummy_config[:channel_token]
36+
end
37+
38+
client
39+
end
40+
41+
it 'gets follower ids' do
42+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids'
43+
stub_request(:get, uri_template).to_return { |request| {body: USER_ID_CONTENT, status: 200} }
44+
45+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids?start={continuationToken}'
46+
stub_request(:get, uri_template).to_return { |request| {body: NEXT_USER_ID_CONTENT, status: 200} }
47+
48+
client = generate_client
49+
50+
# first page
51+
response = client.get_follower_ids
52+
53+
expect(response).to be_a(Net::HTTPOK)
54+
result = JSON.parse(response.body)
55+
expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx1", "Uxxxxxxxxxxxxxx2", "Uxxxxxxxxxxxxxx3"]
56+
expect(result['next']).to eq "jxEWCEEP"
57+
58+
# second page
59+
response = client.get_follower_ids(result['next'])
60+
61+
expect(response).to be_a(Net::HTTPOK)
62+
result = JSON.parse(response.body)
63+
expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx4", "Uxxxxxxxxxxxxxx5", "Uxxxxxxxxxxxxxx6"]
64+
expect(result['next']).to be nil
65+
end
66+
end

0 commit comments

Comments
 (0)