Skip to content

Commit 78d70d9

Browse files
committed
Get the follower ids with a limit
1 parent d530254 commit 78d70d9

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

lib/line/bot/client.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,18 @@ def get_room_member_profile(room_id, user_id)
333333

334334
# Get user IDs of who added your LINE Official Account as a friend
335335
#
336-
# @param continuation_token [String] Identifier to return next page
337-
# (next property to be included in the response)
336+
# @param start [String] Identifier to return next page (next property to be included in the response)
337+
# @param limit [Integer] The maximum number of user IDs to retrieve in a single request
338338
#
339339
# @return [Net::HTTPResponse]
340-
def get_follower_ids(continuation_token = nil)
340+
def get_follower_ids(start: nil, limit: nil)
341341
channel_token_required
342342

343+
params = { start: start, limit: limit }.compact
344+
343345
endpoint_path = "/bot/followers/ids"
344-
endpoint_path += "?start=#{continuation_token}" if continuation_token
346+
endpoint_path += "?" unless params.empty?
347+
endpoint_path += params.map { |key, value| "#{key}=#{value}" }.join("&")
345348
get(endpoint, endpoint_path, credentials)
346349
end
347350

spec/line/bot/client_get_follower_spec.rb

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
}
2424
EOS
2525

26+
LIMITED_USER_ID_CONTENT = <<"EOS"
27+
{
28+
"userIds": [
29+
"Uxxxxxxxxxxxxxx1",
30+
"Uxxxxxxxxxxxxxx2"
31+
]
32+
}
33+
EOS
34+
2635
describe Line::Bot::Client do
2736
def dummy_config
2837
{
@@ -42,7 +51,7 @@ def generate_client
4251
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids'
4352
stub_request(:get, uri_template).to_return { |request| {body: USER_ID_CONTENT, status: 200} }
4453

45-
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids?start={continuationToken}'
54+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids?start={start}'
4655
stub_request(:get, uri_template).to_return { |request| {body: NEXT_USER_ID_CONTENT, status: 200} }
4756

4857
client = generate_client
@@ -56,11 +65,35 @@ def generate_client
5665
expect(result['next']).to eq "jxEWCEEP"
5766

5867
# second page
59-
response = client.get_follower_ids(result['next'])
68+
response = client.get_follower_ids(start: result['next'])
6069

6170
expect(response).to be_a(Net::HTTPOK)
6271
result = JSON.parse(response.body)
6372
expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx4", "Uxxxxxxxxxxxxxx5", "Uxxxxxxxxxxxxxx6"]
6473
expect(result['next']).to be nil
6574
end
75+
76+
it 'gets limited number of follower ids' do
77+
# without any other conditions
78+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids?limit={limit}'
79+
stub_request(:get, uri_template).to_return { |request| {body: LIMITED_USER_ID_CONTENT, status: 200} }
80+
81+
# with other conditions
82+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids?limit={limit}&start={start}'
83+
stub_request(:get, uri_template).to_return { |request| {body: LIMITED_USER_ID_CONTENT, status: 200} }
84+
85+
client = generate_client
86+
87+
# without any other conditions
88+
response = client.get_follower_ids(limit: 2)
89+
result = JSON.parse(response.body)
90+
expect(response).to be_a(Net::HTTPOK)
91+
expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx1", "Uxxxxxxxxxxxxxx2"]
92+
93+
# with other conditions
94+
response = client.get_follower_ids(start: 'foo', limit: 2)
95+
result = JSON.parse(response.body)
96+
expect(response).to be_a(Net::HTTPOK)
97+
expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx1", "Uxxxxxxxxxxxxxx2"]
98+
end
6699
end

0 commit comments

Comments
 (0)