Skip to content

Commit 0d3509b

Browse files
authored
Support get follower IDs api (#682)
Close #621
1 parent 8868328 commit 0d3509b

File tree

6 files changed

+160
-0
lines changed

6 files changed

+160
-0
lines changed

line-bot-api-client/src/main/java/com/linecorp/bot/client/LineMessagingClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
import com.linecorp.bot.model.group.GroupSummaryResponse;
3131
import com.linecorp.bot.model.profile.MembersIdsResponse;
3232
import com.linecorp.bot.model.profile.UserProfileResponse;
33+
import com.linecorp.bot.model.request.GetFollowersRequest;
3334
import com.linecorp.bot.model.request.SetWebhookEndpointRequest;
3435
import com.linecorp.bot.model.request.TestWebhookEndpointRequest;
3536
import com.linecorp.bot.model.response.BotApiResponse;
3637
import com.linecorp.bot.model.response.BotInfoResponse;
3738
import com.linecorp.bot.model.response.GetAggregationUnitNameListResponse;
3839
import com.linecorp.bot.model.response.GetAggregationUnitUsageResponse;
40+
import com.linecorp.bot.model.response.GetFollowersResponse;
3941
import com.linecorp.bot.model.response.GetMessageEventResponse;
4042
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
4143
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
@@ -402,6 +404,11 @@ CompletableFuture<BotApiResponse> updateRichMenuAlias(String richMenuAliasId,
402404
*/
403405
CompletableFuture<GetNumberOfFollowersResponse> getNumberOfFollowers(String date);
404406

407+
/**
408+
* Get a list of users who added your LINE Official Account as a friend.
409+
*/
410+
CompletableFuture<GetFollowersResponse> getFollowers(GetFollowersRequest request);
411+
405412
/**
406413
* Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your
407414
* LINE Official Account.

line-bot-api-client/src/main/java/com/linecorp/bot/client/LineMessagingClientImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
import com.linecorp.bot.model.group.GroupSummaryResponse;
3232
import com.linecorp.bot.model.profile.MembersIdsResponse;
3333
import com.linecorp.bot.model.profile.UserProfileResponse;
34+
import com.linecorp.bot.model.request.GetFollowersRequest;
3435
import com.linecorp.bot.model.request.SetWebhookEndpointRequest;
3536
import com.linecorp.bot.model.request.TestWebhookEndpointRequest;
3637
import com.linecorp.bot.model.response.BotApiResponse;
3738
import com.linecorp.bot.model.response.BotInfoResponse;
3839
import com.linecorp.bot.model.response.GetAggregationUnitNameListResponse;
3940
import com.linecorp.bot.model.response.GetAggregationUnitUsageResponse;
41+
import com.linecorp.bot.model.response.GetFollowersResponse;
4042
import com.linecorp.bot.model.response.GetMessageEventResponse;
4143
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
4244
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
@@ -314,6 +316,11 @@ public CompletableFuture<GetNumberOfFollowersResponse> getNumberOfFollowers(Stri
314316
return toFuture(retrofitImpl.getNumberOfFollowers(date));
315317
}
316318

319+
@Override
320+
public CompletableFuture<GetFollowersResponse> getFollowers(GetFollowersRequest request) {
321+
return toFuture(retrofitImpl.getFollowers(request.getNext()));
322+
}
323+
317324
@Override
318325
public CompletableFuture<GetMessageEventResponse> getMessageEvent(String requestId) {
319326
return toFuture(retrofitImpl.getMessageEvent(requestId));

line-bot-api-client/src/main/java/com/linecorp/bot/client/LineMessagingService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.linecorp.bot.model.response.BotInfoResponse;
3333
import com.linecorp.bot.model.response.GetAggregationUnitNameListResponse;
3434
import com.linecorp.bot.model.response.GetAggregationUnitUsageResponse;
35+
import com.linecorp.bot.model.response.GetFollowersResponse;
3536
import com.linecorp.bot.model.response.GetMessageEventResponse;
3637
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
3738
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
@@ -379,6 +380,12 @@ Call<Void> linkRichMenuToUser(
379380
@GET("v2/bot/insight/followers")
380381
Call<GetNumberOfFollowersResponse> getNumberOfFollowers(@Query("date") String date);
381382

383+
/**
384+
* Get a list of users who added your LINE Official Account as a friend.
385+
*/
386+
@GET("v2/bot/followers/ids")
387+
Call<GetFollowersResponse> getFollowers(@Query("start") String next);
388+
382389
/**
383390
* Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your
384391
* LINE Official Account.

line-bot-api-client/src/test/java/com/linecorp/bot/client/LineMessagingClientImplTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.assertj.core.api.Assertions.assertThat;
2424
import static org.mockito.ArgumentMatchers.any;
2525
import static org.mockito.ArgumentMatchers.isNull;
26+
import static org.mockito.ArgumentMatchers.nullable;
2627
import static org.mockito.Mockito.only;
2728
import static org.mockito.Mockito.verify;
2829
import static org.mockito.Mockito.when;
@@ -41,6 +42,8 @@
4142
import org.mockito.junit.MockitoRule;
4243
import org.mockito.stubbing.OngoingStubbing;
4344

45+
import com.google.common.collect.ImmutableList;
46+
4447
import com.linecorp.bot.model.Broadcast;
4548
import com.linecorp.bot.model.Multicast;
4649
import com.linecorp.bot.model.Narrowcast;
@@ -55,12 +58,14 @@
5558
import com.linecorp.bot.model.narrowcast.filter.GenderDemographicFilter.Gender;
5659
import com.linecorp.bot.model.profile.MembersIdsResponse;
5760
import com.linecorp.bot.model.profile.UserProfileResponse;
61+
import com.linecorp.bot.model.request.GetFollowersRequest;
5862
import com.linecorp.bot.model.request.SetWebhookEndpointRequest;
5963
import com.linecorp.bot.model.request.TestWebhookEndpointRequest;
6064
import com.linecorp.bot.model.response.BotApiResponse;
6165
import com.linecorp.bot.model.response.BotInfoResponse;
6266
import com.linecorp.bot.model.response.GetAggregationUnitNameListResponse;
6367
import com.linecorp.bot.model.response.GetAggregationUnitUsageResponse;
68+
import com.linecorp.bot.model.response.GetFollowersResponse;
6469
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
6570
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
6671
import com.linecorp.bot.model.response.GetStatisticsPerUnitResponse;
@@ -864,6 +869,18 @@ public void getAggregationUnitNameListTest() throws Exception {
864869
assertThat(actual).isEqualTo(response);
865870
}
866871

872+
@Test
873+
public void getFollowers() throws Exception {
874+
final GetFollowersResponse response = GetFollowersResponse
875+
.builder()
876+
.userIds(ImmutableList.of("U1234"))
877+
.build();
878+
whenCall(retrofitMock.getFollowers(nullable(String.class)), response);
879+
final GetFollowersResponse actual = target.getFollowers(GetFollowersRequest.builder().build()).get();
880+
verify(retrofitMock, only()).getFollowers(null);
881+
assertThat(actual).isEqualTo(response);
882+
}
883+
867884
// Utility methods
868885

869886
private static <T> void whenCall(Call<T> call, T value) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2021 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.bot.model.request;
18+
19+
import javax.annotation.Nullable;
20+
21+
import com.linecorp.bot.model.response.GetFollowersResponse;
22+
23+
import lombok.Builder;
24+
import lombok.Value;
25+
26+
/**
27+
* A request object to retrieve followers. If you want to retrieve your followers from the beginning, you need
28+
* to call getFollowers as follows.
29+
* <pre>
30+
* {@code
31+
* final LineMessagingClient client = ...;
32+
* final GetFollowersResponse response = client.getFollowers(GetFollowersRequest.builder().build()).join();
33+
* }</pre>
34+
* Or if you want to retrieve all followers, you need to call getFollowers API as follows.
35+
* <pre>
36+
* {@code
37+
* final LineMessagingClient client = ...;
38+
* GetFollowersRequest request = GetFollowersRequest.builder().build();
39+
* while (true) {
40+
* final GetFollowersResponse response = client.getFollowers(request).join();
41+
* final List<String> userIds = response.getUserIds();
42+
* if (response.getNext() == null) { // No remaining user IDs anymore.
43+
* break;
44+
* }
45+
* // You have remaining user IDs. You can retrieve rest of them using following request object.
46+
* request = GetFollowersRequest .fromResponse(response).build();
47+
* }
48+
* }</pre>
49+
*/
50+
@Value
51+
@Builder
52+
public class GetFollowersRequest {
53+
/**
54+
* Value of the continuation token found in the next property of the JSON object returned in the response.
55+
* Include this parameter to get the next array of user IDs.
56+
*/
57+
@Nullable
58+
String next;
59+
60+
public static GetFollowersRequestBuilder fromResponse(GetFollowersResponse response) {
61+
return builder().next(response.getNext());
62+
}
63+
64+
public static class GetFollowersRequestBuilder {
65+
// Filled by lombok.
66+
}
67+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2021 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.bot.model.response;
18+
19+
import java.util.List;
20+
21+
import javax.annotation.Nullable;
22+
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
25+
26+
import com.linecorp.bot.model.response.GetFollowersResponse.GetFollowersResponseBuilder;
27+
28+
import lombok.Builder;
29+
import lombok.Value;
30+
31+
@Value
32+
@Builder
33+
@JsonDeserialize(builder = GetFollowersResponseBuilder.class)
34+
public class GetFollowersResponse {
35+
/**
36+
* List of user IDs of users that have added the LINE Official Account as a friend. Only users of LINE for
37+
* iOS and LINE for Android are included in userIds. For more information, see
38+
* <a href="https://developers.line.biz/en/docs/messaging-api/user-consent/">Consent on getting user
39+
* profile information</a>. Max: 300 user IDs
40+
*/
41+
List<String> userIds;
42+
43+
/**
44+
* A continuation token to get the next array of user IDs. Returned only when there are remaining user IDs
45+
* that were not returned in userIds in the original request. The number of user IDs in the userIds element
46+
* does not have to reach 300 for the next property to be included in the response.
47+
*/
48+
@Nullable
49+
String next;
50+
51+
@JsonPOJOBuilder(withPrefix = "")
52+
public static class GetFollowersResponseBuilder {
53+
// Filled by lombok
54+
}
55+
}

0 commit comments

Comments
 (0)