Skip to content

Commit 9d9caab

Browse files
author
Junpei Koyama
authored
Merge pull request #325 from imasahiro/issue324
Supports Link/Unlink rich menu to/from multiple users
2 parents c231c7e + 99fbcc9 commit 9d9caab

File tree

6 files changed

+150
-2
lines changed

6 files changed

+150
-2
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.linecorp.bot.client;
1818

19+
import java.util.List;
1920
import java.util.concurrent.CompletableFuture;
2021

2122
import com.linecorp.bot.model.Multicast;
@@ -208,13 +209,29 @@ CompletableFuture<MembersIdsResponse> getRoomMembersIds(
208209
*/
209210
CompletableFuture<BotApiResponse> linkRichMenuIdToUser(String userId, String richMenuId);
210211

212+
/**
213+
* Link rich menu to users.
214+
*
215+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#link-rich-menu-to-users">
216+
* Link rich menu to multiple users</a>
217+
*/
218+
CompletableFuture<BotApiResponse> linkRichMenuIdToUsers(List<String> userIds, String richMenuId);
219+
211220
/**
212221
* Unlink rich menu from user.
213222
*
214223
* @see <a href="https://developers.line.me/en/docs/messaging-api/reference/#unlink-rich-menu-from-user">//developers.line.me/en/docs/messaging-api/reference/#unlink-rich-menu-from-user</a>
215224
*/
216225
CompletableFuture<BotApiResponse> unlinkRichMenuIdFromUser(String userId);
217226

227+
/**
228+
* Unlink rich menu from users.
229+
*
230+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#unlink-rich-menu-from-users">
231+
* Unlink rich menu to multiple users</a>
232+
*/
233+
CompletableFuture<BotApiResponse> unlinkRichMenuIdFromUsers(List<String> userIds);
234+
218235
/**
219236
* Download rich menu image.
220237
*

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static java.util.Collections.emptyList;
2020

21+
import java.util.List;
2122
import java.util.concurrent.CompletableFuture;
2223
import java.util.function.Function;
2324

@@ -31,6 +32,8 @@
3132
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
3233
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
3334
import com.linecorp.bot.model.richmenu.RichMenu;
35+
import com.linecorp.bot.model.richmenu.RichMenuBlukLinkRequest;
36+
import com.linecorp.bot.model.richmenu.RichMenuBlukUnlinkRequest;
3437
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
3538
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
3639
import com.linecorp.bot.model.richmenu.RichMenuResponse;
@@ -159,11 +162,26 @@ public CompletableFuture<BotApiResponse> linkRichMenuIdToUser(
159162
return toBotApiFuture(retrofitImpl.linkRichMenuToUser(userId, richMenuId));
160163
}
161164

165+
@Override
166+
public CompletableFuture<BotApiResponse> linkRichMenuIdToUsers(List<String> userIds, String richMenuId) {
167+
return toBotApiFuture(retrofitImpl.linkRichMenuToUsers(RichMenuBlukLinkRequest.builder()
168+
.richMenuId(richMenuId)
169+
.userIds(userIds)
170+
.build()));
171+
}
172+
162173
@Override
163174
public CompletableFuture<BotApiResponse> unlinkRichMenuIdFromUser(final String userId) {
164175
return toBotApiFuture(retrofitImpl.unlinkRichMenuIdFromUser(userId));
165176
}
166177

178+
@Override
179+
public CompletableFuture<BotApiResponse> unlinkRichMenuIdFromUsers(List<String> userIds) {
180+
return toBotApiFuture(retrofitImpl.unlinkRichMenuIdFromUsers(RichMenuBlukUnlinkRequest.builder()
181+
.userIds(userIds)
182+
.build()));
183+
}
184+
167185
@Override
168186
public CompletableFuture<MessageContentResponse> getRichMenuImage(final String richMenuId) {
169187
return toMessageContentResponseFuture(retrofitImpl.getRichMenuImage(richMenuId));

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.linecorp.bot.client;
1818

19+
import java.util.List;
20+
1921
import com.linecorp.bot.model.Multicast;
2022
import com.linecorp.bot.model.PushMessage;
2123
import com.linecorp.bot.model.ReplyMessage;
@@ -25,6 +27,8 @@
2527
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
2628
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
2729
import com.linecorp.bot.model.richmenu.RichMenu;
30+
import com.linecorp.bot.model.richmenu.RichMenuBlukLinkRequest;
31+
import com.linecorp.bot.model.richmenu.RichMenuBlukUnlinkRequest;
2832
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
2933
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
3034
import com.linecorp.bot.model.richmenu.RichMenuResponse;
@@ -198,6 +202,14 @@ Call<Void> linkRichMenuToUser(
198202
@Path("userId") String userId,
199203
@Path("richMenuId") String richMenuId);
200204

205+
/**
206+
* Method for Retrofit.
207+
*
208+
* @see LineMessagingClient#linkRichMenuIdToUsers(List, String)
209+
*/
210+
@POST("v2/bot/richmenu/bulk/link")
211+
Call<Void> linkRichMenuToUsers(@Body RichMenuBlukLinkRequest request);
212+
201213
/**
202214
* Method for Retrofit.
203215
*
@@ -206,6 +218,14 @@ Call<Void> linkRichMenuToUser(
206218
@DELETE("v2/bot/user/{userId}/richmenu")
207219
Call<Void> unlinkRichMenuIdFromUser(@Path("userId") String userId);
208220

221+
/**
222+
* Method for Retrofit.
223+
*
224+
* @see LineMessagingClient#unlinkRichMenuIdFromUser(String)
225+
*/
226+
@DELETE("v2/bot/richmenu/bulk/unlink")
227+
Call<Void> unlinkRichMenuIdFromUsers(@Body RichMenuBlukUnlinkRequest request);
228+
209229
/**
210230
* Method for Retrofit.
211231
*

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.mockito.Mockito.when;
2727

2828
import java.io.IOException;
29+
import java.util.Collections;
2930

3031
import org.junit.Rule;
3132
import org.junit.Test;
@@ -47,6 +48,8 @@
4748
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
4849
import com.linecorp.bot.model.response.NumberOfMessagesResponse.Status;
4950
import com.linecorp.bot.model.richmenu.RichMenu;
51+
import com.linecorp.bot.model.richmenu.RichMenuBlukLinkRequest;
52+
import com.linecorp.bot.model.richmenu.RichMenuBlukUnlinkRequest;
5053
import com.linecorp.bot.model.richmenu.RichMenuIdResponse;
5154
import com.linecorp.bot.model.richmenu.RichMenuListResponse;
5255
import com.linecorp.bot.model.richmenu.RichMenuResponse;
@@ -299,7 +302,6 @@ public void getRichMenuIdOfUserTest() throws Exception {
299302
// Verify
300303
verify(retrofitMock, only()).getRichMenuIdOfUser("ID");
301304
assertThat(richMenuIdResponse).isEqualTo(RICH_MENU_ID_RESPONSE);
302-
303305
}
304306

305307
@Test
@@ -313,11 +315,27 @@ public void linkRichMenuToUserTest() throws Exception {
313315
// Verify
314316
verify(retrofitMock, only()).linkRichMenuToUser("USER_ID", "RICH_MENU_ID");
315317
assertThat(botApiResponse).isEqualTo(BOT_API_SUCCESS_RESPONSE);
318+
}
319+
320+
@Test
321+
public void linkRichMenuToUsers() {
322+
whenCall(retrofitMock.linkRichMenuToUsers(any()), null);
316323

324+
// Do
325+
final BotApiResponse botApiResponse = target.linkRichMenuIdToUsers(Collections.singletonList("USER_ID"),
326+
"RICH_MENU_ID")
327+
.join();
328+
329+
// Verify
330+
verify(retrofitMock, only()).linkRichMenuToUsers(RichMenuBlukLinkRequest.builder()
331+
.richMenuId("RICH_MENU_ID")
332+
.userId("USER_ID")
333+
.build());
334+
assertThat(botApiResponse).isEqualTo(BOT_API_SUCCESS_RESPONSE);
317335
}
318336

319337
@Test
320-
public void unlinkRichMenuIdToUserTest() throws Exception {
338+
public void unlinkRichMenuIdFromUser() throws Exception {
321339
whenCall(retrofitMock.unlinkRichMenuIdFromUser(any()),
322340
null);
323341

@@ -327,7 +345,21 @@ public void unlinkRichMenuIdToUserTest() throws Exception {
327345
// Verify
328346
verify(retrofitMock, only()).unlinkRichMenuIdFromUser("ID");
329347
assertThat(botApiResponse).isEqualTo(BOT_API_SUCCESS_RESPONSE);
348+
}
349+
350+
@Test
351+
public void unlinkRichMenuIdFromUsers() throws Exception {
352+
whenCall(retrofitMock.unlinkRichMenuIdFromUsers(any()),
353+
null);
330354

355+
// Do
356+
final BotApiResponse botApiResponse = target.unlinkRichMenuIdFromUsers(Collections.singletonList("ID"))
357+
.join();
358+
359+
// Verify
360+
verify(retrofitMock, only()).unlinkRichMenuIdFromUsers(
361+
RichMenuBlukUnlinkRequest.builder().userId("ID").build());
362+
assertThat(botApiResponse).isEqualTo(BOT_API_SUCCESS_RESPONSE);
331363
}
332364

333365
@Test
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2019 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.richmenu;
18+
19+
import java.util.List;
20+
21+
import lombok.Builder;
22+
import lombok.Singular;
23+
import lombok.Value;
24+
25+
@Value
26+
@Builder
27+
public class RichMenuBlukLinkRequest {
28+
String richMenuId;
29+
@Singular
30+
List<String> userIds;
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2019 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.richmenu;
18+
19+
import java.util.List;
20+
21+
import lombok.Builder;
22+
import lombok.Singular;
23+
import lombok.Value;
24+
25+
@Value
26+
@Builder
27+
public class RichMenuBlukUnlinkRequest {
28+
@Singular
29+
List<String> userIds;
30+
}

0 commit comments

Comments
 (0)