Skip to content

Commit f773f2c

Browse files
authored
Merge pull request #214 from moririnson/add-get-number-of-messages
Add get number of messages sent.
2 parents 2b8df4a + 0b498de commit f773f2c

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

src/LINEBot.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use LINE\LINEBot\SignatureValidator;
2727
use LINE\LINEBot\RichMenuBuilder;
2828
use ReflectionClass;
29+
use DateTime;
30+
use DateTimeZone;
2931

3032
/**
3133
* A client class of LINE Messaging API.
@@ -479,4 +481,43 @@ public function getRichMenuList()
479481
{
480482
return $this->httpClient->get($this->endpointBase . '/v2/bot/richmenu/list');
481483
}
484+
485+
/**
486+
* Get number of sent reply messages
487+
*
488+
* @param DateTime $datetime Date the messages were sent.
489+
* @return Response
490+
*/
491+
public function getNumberOfSentReplyMessages(DateTime $datetime)
492+
{
493+
$url = $this->endpointBase . '/v2/bot/message/delivery/reply';
494+
$datetime->setTimezone(new DateTimeZone('Asia/Tokyo'));
495+
return $this->httpClient->get($url, ['date' => $datetime->format('Ymd')]);
496+
}
497+
498+
/**
499+
* Get number of sent push messages
500+
*
501+
* @param DateTime $datetime Date the messages were sent.
502+
* @return Response
503+
*/
504+
public function getNumberOfSentPushMessages(DateTime $datetime)
505+
{
506+
$url = $this->endpointBase . '/v2/bot/message/delivery/push';
507+
$datetime->setTimezone(new DateTimeZone('Asia/Tokyo'));
508+
return $this->httpClient->get($url, ['date' => $datetime->format('Ymd')]);
509+
}
510+
511+
/**
512+
* Get number of sent multicast messages
513+
*
514+
* @param DateTime $datetime Date the messages were sent.
515+
* @return Response
516+
*/
517+
public function getNumberOfSentMulticastMessages(DateTime $datetime)
518+
{
519+
$url = $this->endpointBase . '/v2/bot/message/delivery/multicast';
520+
$datetime->setTimezone(new DateTimeZone('Asia/Tokyo'));
521+
return $this->httpClient->get($url, ['date' => $datetime->format('Ymd')]);
522+
}
482523
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2019 LINE Corporation
5+
*
6+
* LINE Corporation licenses this file to you under the Apache License,
7+
* version 2.0 (the "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at:
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
namespace LINE\Tests\LINEBot;
20+
21+
use LINE\LINEBot;
22+
use LINE\Tests\LINEBot\Util\DummyHttpClient;
23+
use PHPUnit\Framework\TestCase;
24+
use DateTime;
25+
use DateTimeZone;
26+
27+
class GetNumberOfMessagesSentTest extends TestCase
28+
{
29+
public function testGetNumberOfSentReplyMessages()
30+
{
31+
$date = new DateTime();
32+
$mock = function ($testRunner, $httpMethod, $url, $data) use ($date) {
33+
/** @var \PHPUnit\Framework\TestCase $testRunner */
34+
$testRunner->assertEquals('GET', $httpMethod);
35+
$testRunner->assertEquals('https://api.line.me/v2/bot/message/delivery/reply', $url);
36+
$date->setTimezone(new DateTimeZone('Asia/Tokyo'));
37+
$testRunner->assertEquals([
38+
'date' => $date->format('Ymd')
39+
], $data);
40+
return [
41+
'status' => 'ready',
42+
'success' => 10000
43+
];
44+
};
45+
$bot = new LINEBot(new DummyHttpClient($this, $mock), ['channelSecret' => 'CHANNEL-SECRET']);
46+
$res = $bot->getNumberOfSentReplyMessages($date);
47+
48+
$this->assertEquals(200, $res->getHTTPStatus());
49+
$this->assertTrue($res->isSucceeded());
50+
51+
$data = $res->getJSONDecodedBody();
52+
$this->assertEquals('ready', $data['status']);
53+
$this->assertEquals(10000, $data['success']);
54+
}
55+
56+
public function testGetNumberOfSentPushMessages()
57+
{
58+
$date = new DateTime();
59+
$mock = function ($testRunner, $httpMethod, $url, $data) use ($date) {
60+
/** @var \PHPUnit\Framework\TestCase $testRunner */
61+
$testRunner->assertEquals('GET', $httpMethod);
62+
$testRunner->assertEquals('https://api.line.me/v2/bot/message/delivery/push', $url);
63+
$date->setTimezone(new DateTimeZone('Asia/Tokyo'));
64+
$testRunner->assertEquals([
65+
'date' => $date->format('Ymd')
66+
], $data);
67+
return [
68+
'status' => 'ready',
69+
'success' => 10000
70+
];
71+
};
72+
$bot = new LINEBot(new DummyHttpClient($this, $mock), ['channelSecret' => 'CHANNEL-SECRET']);
73+
$res = $bot->getNumberOfSentPushMessages($date);
74+
75+
$this->assertEquals(200, $res->getHTTPStatus());
76+
$this->assertTrue($res->isSucceeded());
77+
78+
$data = $res->getJSONDecodedBody();
79+
$this->assertEquals('ready', $data['status']);
80+
$this->assertEquals(10000, $data['success']);
81+
}
82+
83+
public function testGetNumberOfSentMulticastMessages()
84+
{
85+
$date = new DateTime();
86+
$mock = function ($testRunner, $httpMethod, $url, $data) use ($date) {
87+
/** @var \PHPUnit\Framework\TestCase $testRunner */
88+
$testRunner->assertEquals('GET', $httpMethod);
89+
$testRunner->assertEquals('https://api.line.me/v2/bot/message/delivery/multicast', $url);
90+
$date->setTimezone(new DateTimeZone('Asia/Tokyo'));
91+
$testRunner->assertEquals([
92+
'date' => $date->format('Ymd')
93+
], $data);
94+
return [
95+
'status' => 'ready',
96+
'success' => 10000
97+
];
98+
};
99+
$bot = new LINEBot(new DummyHttpClient($this, $mock), ['channelSecret' => 'CHANNEL-SECRET']);
100+
$res = $bot->getNumberOfSentMulticastMessages($date);
101+
102+
$this->assertEquals(200, $res->getHTTPStatus());
103+
$this->assertTrue($res->isSucceeded());
104+
105+
$data = $res->getJSONDecodedBody();
106+
$this->assertEquals('ready', $data['status']);
107+
$this->assertEquals(10000, $data['success']);
108+
}
109+
}

0 commit comments

Comments
 (0)