Skip to content

Commit c1432e6

Browse files
committed
Fix getNumberOfFollowers, getNumberOfMessageDeliveries
* Fix enum definition. (lower case wire value) * rename method s/getNumberOfFollowersResponse/getNumberOfFollowers/;
1 parent ef710e5 commit c1432e6

File tree

10 files changed

+121
-25
lines changed

10 files changed

+121
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ local.properties
5353

5454
# PDT-specific
5555
.buildpath
56+
integration_test_settings.yml

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ subprojects {
127127
testCompile 'org.hibernate.validator:hibernate-validator'
128128
testCompile 'org.springframework.boot:spring-boot-starter-test' // MockHttpServletRequest
129129
testCompile 'org.springframework.boot:spring-boot-starter-logging'
130+
testCompile 'org.yaml:snakeyaml'
130131
}
131132

132133
compileJava.dependsOn(processResources)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ CompletableFuture<BotApiResponse> setRichMenuImage(
334334
/**
335335
* Gets the number of users who have added the bot on or before a specified date.
336336
*/
337-
CompletableFuture<GetNumberOfFollowersResponse> getNumberOfFollowersResponse(String date);
337+
CompletableFuture<GetNumberOfFollowersResponse> getNumberOfFollowers(String date);
338338

339339
/**
340340
* Retrieves the demographic attributes for a bot's friends.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public CompletableFuture<GetNumberOfMessageDeliveriesResponse> getNumberOfMessag
254254
}
255255

256256
@Override
257-
public CompletableFuture<GetNumberOfFollowersResponse> getNumberOfFollowersResponse(String date) {
257+
public CompletableFuture<GetNumberOfFollowersResponse> getNumberOfFollowers(String date) {
258258
return toFuture(retrofitImpl.getNumberOfFollowers(date));
259259
}
260260

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ interface LineMessagingService {
155155
* {@literal "20191231"}) and the timezone should be UTC+9.
156156
*/
157157
@GET("v2/bot/message/delivery/broadcast")
158-
Call<NumberOfMessagesResponse> getNumberOfSentBroadcastMessages(String date);
158+
Call<NumberOfMessagesResponse> getNumberOfSentBroadcastMessages(@Query("date") String date);
159159

160160
/**
161161
* Method for Retrofit.
@@ -341,14 +341,14 @@ Call<Void> uploadRichMenuImage(
341341
* @param date Date for which to retrieve number of sent messages. The format should be {@code yyyyMMdd}.
342342
* For example: {@literal "20191231"}) and the timezone should be UTC+9.
343343
*/
344-
@GET("v2/bot/insight/message/delivery?date={date}")
344+
@GET("v2/bot/insight/message/delivery")
345345
Call<GetNumberOfMessageDeliveriesResponse> getNumberOfMessageDeliveries(@Query("date") String date);
346346

347347
/**
348348
* Returns the number of users who have added the bot on or before a specified date.
349349
* @param date Date for which to retrieve the number of followers. The format should be {@code yyyyMMdd}.
350350
* For example: {@literal "20191231"}) and the timezone should be UTC+9.
351351
*/
352-
@GET("v2/bot/insight/followers?date={date}")
352+
@GET("v2/bot/insight/followers")
353353
Call<GetNumberOfFollowersResponse> getNumberOfFollowers(@Query("date") String date);
354354
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.client;
18+
19+
import java.io.IOException;
20+
import java.net.URL;
21+
import java.util.Map;
22+
23+
import org.junit.Assume;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
import org.yaml.snakeyaml.Yaml;
27+
28+
import com.fasterxml.jackson.databind.ObjectMapper;
29+
30+
import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
31+
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
32+
import com.linecorp.bot.model.response.NumberOfMessagesResponse;
33+
34+
import lombok.extern.slf4j.Slf4j;
35+
36+
/**
37+
* Integration test of {@link LineMessagingClient}.
38+
*
39+
* <p>To run this test, please put config file resources/integration_test_settings.yml.
40+
*/
41+
@Slf4j
42+
public class LineMessagingClientImplIntegrationTest {
43+
public static final URL TEST_RESOURCE = ClassLoader.getSystemResource("integration_test_settings.yml");
44+
private LineMessagingClient target;
45+
46+
@Before
47+
public void setUp() throws IOException {
48+
Assume.assumeTrue(TEST_RESOURCE != null);
49+
50+
final Map<?, ?> map = new ObjectMapper()
51+
.convertValue(new Yaml().load(TEST_RESOURCE.openStream()), Map.class);
52+
53+
target = LineMessagingClient
54+
.builder((String) map.get("token"))
55+
.apiEndPoint((String) map.get("endpoint"))
56+
.build();
57+
}
58+
59+
@Test
60+
public void getNumberOfMessageDeliveries() throws Exception {
61+
final GetNumberOfMessageDeliveriesResponse getNumberOfMessageDeliveriesResponse =
62+
target.getNumberOfMessageDeliveries("20191231").get();
63+
64+
log.info(getNumberOfMessageDeliveriesResponse.toString());
65+
}
66+
67+
@Test
68+
public void getNumberOfSentBroadcastMessages() throws Exception {
69+
final NumberOfMessagesResponse getNumberOfSentBroadcastMessages =
70+
target.getNumberOfSentBroadcastMessages("20191231").get();
71+
72+
log.info(getNumberOfSentBroadcastMessages.toString());
73+
}
74+
75+
@Test
76+
public void getNumberOfFollowers() throws Exception {
77+
final GetNumberOfFollowersResponse getNumberOfFollowersResponse =
78+
target.getNumberOfFollowers("20191231").get();
79+
80+
log.info(getNumberOfFollowersResponse.toString());
81+
}
82+
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,44 +198,44 @@ public void getMessageQuotaConsumption() {
198198
@Test
199199
public void getNumberOfSentReplyMessages() {
200200
whenCall(retrofitMock.getNumberOfSentReplyMessages(any()),
201-
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.Ready, 1024));
201+
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.READY, 1024));
202202

203203
NumberOfMessagesResponse response = target.getNumberOfSentReplyMessages("20181231").join();
204204
verify(retrofitMock, only()).getNumberOfSentReplyMessages("20181231");
205-
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.Ready);
205+
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.READY);
206206
assertThat(response.getSuccess()).isEqualTo(1024);
207207
}
208208

209209
@Test
210210
public void getNumberOfSentPushMessages() {
211211
whenCall(retrofitMock.getNumberOfSentPushMessages(any()),
212-
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.Ready, 1024));
212+
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.READY, 1024));
213213

214214
NumberOfMessagesResponse response = target.getNumberOfSentPushMessages("20181231").join();
215215
verify(retrofitMock, only()).getNumberOfSentPushMessages("20181231");
216-
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.Ready);
216+
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.READY);
217217
assertThat(response.getSuccess()).isEqualTo(1024);
218218
}
219219

220220
@Test
221221
public void getNumberOfSentMulticastMessages() {
222222
whenCall(retrofitMock.getNumberOfSentMulticastMessages(any()),
223-
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.Ready, 1024));
223+
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.READY, 1024));
224224

225225
NumberOfMessagesResponse response = target.getNumberOfSentMulticastMessages("20181231").join();
226226
verify(retrofitMock, only()).getNumberOfSentMulticastMessages("20181231");
227-
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.Ready);
227+
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.READY);
228228
assertThat(response.getSuccess()).isEqualTo(1024);
229229
}
230230

231231
@Test
232232
public void getNumberOfSentBroadcastMessages() {
233233
whenCall(retrofitMock.getNumberOfSentBroadcastMessages(any()),
234-
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.Ready, 1024));
234+
new NumberOfMessagesResponse(NumberOfMessagesResponse.Status.READY, 1024));
235235

236236
NumberOfMessagesResponse response = target.getNumberOfSentBroadcastMessages("20181231").join();
237237
verify(retrofitMock, only()).getNumberOfSentBroadcastMessages("20181231");
238-
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.Ready);
238+
assertThat(response.getStatus()).isEqualTo(NumberOfMessagesResponse.Status.READY);
239239
assertThat(response.getSuccess()).isEqualTo(1024);
240240
}
241241

@@ -527,7 +527,7 @@ public void issueLinkToken() throws Exception {
527527
public void getNumberOfMessageDeliveries() throws Exception {
528528
final GetNumberOfMessageDeliveriesResponse response = GetNumberOfMessageDeliveriesResponse
529529
.builder()
530-
.status(GetNumberOfMessageDeliveriesResponse.Status.Ready)
530+
.status(GetNumberOfMessageDeliveriesResponse.Status.READY)
531531
.apiBroadcast(1L)
532532
.build();
533533
whenCall(retrofitMock.getNumberOfMessageDeliveries(any()), response);
@@ -541,14 +541,14 @@ public void getNumberOfMessageDeliveries() throws Exception {
541541
public void getNumberOfFollowers() throws Exception {
542542
final GetNumberOfFollowersResponse response = GetNumberOfFollowersResponse
543543
.builder()
544-
.status(GetNumberOfFollowersResponse.Status.Ready)
544+
.status(GetNumberOfFollowersResponse.Status.READY)
545545
.followers(3L)
546546
.targetedReaches(2L)
547547
.blocks(1L)
548548
.build();
549549
whenCall(retrofitMock.getNumberOfFollowers(any()), response);
550550
final GetNumberOfFollowersResponse actual =
551-
target.getNumberOfFollowersResponse("20190805").get();
551+
target.getNumberOfFollowers("20190805").get();
552552
verify(retrofitMock, only()).getNumberOfFollowers("20190805");
553553
assertThat(actual).isEqualTo(response);
554554
}

line-bot-model/src/main/java/com/linecorp/bot/model/response/GetNumberOfFollowersResponse.java

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

1717
package com.linecorp.bot.model.response;
1818

19+
import com.fasterxml.jackson.annotation.JsonProperty;
1920
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2021
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
2122

@@ -35,17 +36,20 @@ public enum Status {
3536
/**
3637
* Calculation has finished; the numbers are up-to-date.
3738
*/
38-
Ready,
39+
@JsonProperty("ready")
40+
READY,
3941
/**
4042
* We haven't finished calculating the number of sent messages for the specified date. Calculation
4143
* usually takes about a day. Please try again later.
4244
*/
43-
Unready,
45+
@JsonProperty("unready")
46+
UNREADY,
4447
/**
4548
* The specified date is earlier than the date on which we first started calculating followers
4649
* (November 1, 2016).
4750
*/
48-
OutOfService
51+
@JsonProperty("out_of_service")
52+
OUT_OF_SERVICE
4953
}
5054

5155
/**

line-bot-model/src/main/java/com/linecorp/bot/model/response/GetNumberOfMessageDeliveriesResponse.java

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

1717
package com.linecorp.bot.model.response;
1818

19+
import com.fasterxml.jackson.annotation.JsonProperty;
1920
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2021
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
2122

@@ -35,17 +36,20 @@ public enum Status {
3536
/**
3637
* Calculation has finished; the numbers are up-to-date.
3738
*/
38-
Ready,
39+
@JsonProperty("ready")
40+
READY,
3941
/**
4042
* We haven't finished calculating the number of sent messages for the specified date. Calculation
4143
* usually takes about a day. Please try again later.
4244
*/
43-
Unready,
45+
@JsonProperty("unready")
46+
UNREADY,
4447
/**
4548
* The specified date is earlier than the date on which we first started calculating sent messages
4649
* (March 1, 2017).
4750
*/
48-
OutOfService
51+
@JsonProperty("out_of_service")
52+
OUT_OF_SERVICE
4953
}
5054

5155
/**

line-bot-model/src/main/java/com/linecorp/bot/model/response/NumberOfMessagesResponse.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.linecorp.bot.model.response;
1818

1919
import com.fasterxml.jackson.annotation.JsonCreator;
20+
import com.fasterxml.jackson.annotation.JsonProperty;
2021

2122
import lombok.AllArgsConstructor;
2223
import lombok.Value;
@@ -31,17 +32,20 @@ public enum Status {
3132
/**
3233
* You can get the number of messages.
3334
*/
34-
Ready,
35+
@JsonProperty("ready")
36+
READY,
3537
/**
3638
* The message counting process for the date specified in {@code date} has not been completed yet.
3739
* Retry your request later. Normally, the counting process is completed within the next day.
3840
*/
39-
Unready,
41+
@JsonProperty("unready")
42+
UNREADY,
4043
/**
4144
* The date specified in date is earlier than March 31, 2018, when the operation of the counting system
4245
* started.
4346
*/
44-
OutOfService
47+
@JsonProperty("out_of_service")
48+
OUT_OF_SERVICE
4549
}
4650

4751
Status status;

0 commit comments

Comments
 (0)