Skip to content

Commit 5fe6cac

Browse files
committed
Add an API that gets the target limit for additional messages
1 parent e1f5664 commit 5fe6cac

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.linecorp.bot.model.profile.UserProfileResponse;
2929
import com.linecorp.bot.model.response.BotApiResponse;
3030
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
31+
import com.linecorp.bot.model.response.MessageQuotaResponse;
3132
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
3233
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
3334
import com.linecorp.bot.model.richmenu.RichMenu;
@@ -81,6 +82,15 @@ public interface LineMessagingClient {
8182
*/
8283
CompletableFuture<MessageContentResponse> getMessageContent(String messageId);
8384

85+
/**
86+
* Gets the target limit for additional messages in the current month. The number of messages retrieved by
87+
* this operation includes the number of messages sent from LINE Official Account Manager.
88+
* Set a target limit with LINE Official Account Manager. For the procedures, refer to the LINE Official
89+
* Account Manager manual.
90+
* Note: LINE@ accounts cannot call this API endpoint.
91+
*/
92+
CompletableFuture<MessageQuotaResponse> getMessageQuota();
93+
8494
/**
8595
* Gets the number of messages sent in the current month. The number of messages retrieved by this
8696
* operation includes the number of messages sent from LINE Official Account Manager. The number of

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.linecorp.bot.model.profile.UserProfileResponse;
3131
import com.linecorp.bot.model.response.BotApiResponse;
3232
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
33+
import com.linecorp.bot.model.response.MessageQuotaResponse;
3334
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
3435
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
3536
import com.linecorp.bot.model.richmenu.RichMenu;
@@ -83,6 +84,11 @@ public CompletableFuture<MessageContentResponse> getMessageContent(final String
8384
return toMessageContentResponseFuture(retrofitImpl.getMessageContent(messageId));
8485
}
8586

87+
@Override
88+
public CompletableFuture<MessageQuotaResponse> getMessageQuota() {
89+
return toFuture(retrofitImpl.getMessageQuota());
90+
}
91+
8692
@Override
8793
public CompletableFuture<QuotaConsumptionResponse> getMessageQuotaConsumption() {
8894
return toFuture(retrofitImpl.getMessageQuotaConsumption());

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.linecorp.bot.model.profile.UserProfileResponse;
2626
import com.linecorp.bot.model.response.BotApiResponse;
2727
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
28+
import com.linecorp.bot.model.response.MessageQuotaResponse;
2829
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
2930
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
3031
import com.linecorp.bot.model.richmenu.RichMenu;
@@ -83,6 +84,16 @@ interface LineMessagingService {
8384
@GET("v2/bot/message/{messageId}/content")
8485
Call<ResponseBody> getMessageContent(@Path("messageId") String messageId);
8586

87+
/**
88+
* Gets the target limit for additional messages in the current month. The number of messages retrieved by
89+
* this operation includes the number of messages sent from LINE Official Account Manager.
90+
* Set a target limit with LINE Official Account Manager. For the procedures, refer to the LINE Official
91+
* Account Manager manual.
92+
* Note: LINE@ accounts cannot call this API endpoint.
93+
*/
94+
@GET("v2/bot/message/quota")
95+
Call<MessageQuotaResponse> getMessageQuota();
96+
8697
/**
8798
* Gets the number of messages sent in the current month. The number of messages retrieved by this
8899
* operation includes the number of messages sent from LINE Official Account Manager. The number of

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import com.linecorp.bot.model.profile.UserProfileResponse;
4646
import com.linecorp.bot.model.response.BotApiResponse;
4747
import com.linecorp.bot.model.response.IssueLinkTokenResponse;
48+
import com.linecorp.bot.model.response.MessageQuotaResponse;
49+
import com.linecorp.bot.model.response.MessageQuotaResponse.QuotaType;
4850
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
4951
import com.linecorp.bot.model.response.NumberOfMessagesResponse.Status;
5052
import com.linecorp.bot.model.response.QuotaConsumptionResponse;
@@ -138,6 +140,32 @@ public void getMessageContentTest() throws Exception {
138140
assertThat(contentResponse.getMimeType()).isEqualTo("image/jpeg");
139141
}
140142

143+
@Test
144+
public void getMessageQuota() {
145+
whenCall(retrofitMock.getMessageQuota(),
146+
MessageQuotaResponse.builder()
147+
.type(QuotaType.none)
148+
.build());
149+
150+
MessageQuotaResponse response = target.getMessageQuota().join();
151+
verify(retrofitMock, only()).getMessageQuota();
152+
assertThat(response.getType()).isEqualTo(QuotaType.none);
153+
}
154+
155+
@Test
156+
public void getMessageQuota_limited() {
157+
whenCall(retrofitMock.getMessageQuota(),
158+
MessageQuotaResponse.builder()
159+
.type(QuotaType.limited)
160+
.value(100)
161+
.build());
162+
163+
MessageQuotaResponse response = target.getMessageQuota().join();
164+
verify(retrofitMock, only()).getMessageQuota();
165+
assertThat(response.getType()).isEqualTo(QuotaType.limited);
166+
assertThat(response.getValue()).isEqualTo(100);
167+
}
168+
141169
@Test
142170
public void getMessageQuotaConsumption() {
143171
whenCall(retrofitMock.getMessageQuotaConsumption(),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.response;
18+
19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20+
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
21+
22+
import com.linecorp.bot.model.response.MessageQuotaResponse.MessageQuotaResponseBuilder;
23+
24+
import lombok.Builder;
25+
import lombok.Value;
26+
27+
@Value
28+
@Builder
29+
@JsonDeserialize(builder = MessageQuotaResponseBuilder.class)
30+
public class MessageQuotaResponse {
31+
/**
32+
* Indicates whether a target limit is set or not.
33+
*/
34+
QuotaType type;
35+
36+
/**
37+
* The target limit for additional messages in the current month. This property is set when the type
38+
* property has a value of limited.
39+
*/
40+
long value;
41+
42+
public enum QuotaType {
43+
/**
44+
* Indicates that a target limit is not set.
45+
*/
46+
none,
47+
48+
/**
49+
* Indicates that a target limit is set.
50+
*/
51+
limited
52+
}
53+
54+
@JsonPOJOBuilder(withPrefix = "")
55+
public static class MessageQuotaResponseBuilder {
56+
}
57+
}

0 commit comments

Comments
 (0)