Skip to content

Commit aeb43a4

Browse files
authored
Merge pull request #270 from moririnson/feature/add-narrow-cast
Support Narrowcast api endpoint
2 parents eb006f6 + 6391f36 commit aeb43a4

14 files changed

+878
-0
lines changed

src/LINEBot.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use LINE\LINEBot\HTTPClient;
2323
use LINE\LINEBot\MessageBuilder;
2424
use LINE\LINEBot\MessageBuilder\TextMessageBuilder;
25+
use LINE\LINEBot\Narrowcast\DemographicFilter\DemographicFilterBuilder;
26+
use LINE\LINEBot\Narrowcast\Recipient\RecipientBuilder;
2527
use LINE\LINEBot\Response;
2628
use LINE\LINEBot\SignatureValidator;
2729
use LINE\LINEBot\RichMenuBuilder;
@@ -728,4 +730,50 @@ public function revokeChannelAccessToken($channelAccessToken)
728730
['Content-Type: application/x-www-form-urlencoded']
729731
);
730732
}
733+
734+
/**
735+
* Send Narrowcast message.
736+
*
737+
* @param MessageBuilder $messageBuilder
738+
* @param RecipientBuilder|null $recipientBuilder
739+
* @param DemographicFilterBuilder|null $demographicFilterBuilder
740+
* @param int|null $limit
741+
* @return Response
742+
*/
743+
public function sendNarrowcast(
744+
MessageBuilder $messageBuilder,
745+
RecipientBuilder $recipientBuilder = null,
746+
DemographicFilterBuilder $demographicFilterBuilder = null,
747+
$limit = null
748+
) {
749+
$params = [
750+
'messages' => $messageBuilder->buildMessage()
751+
];
752+
if (isset($recipientBuilder)) {
753+
$params['recipient'] = $recipientBuilder->build();
754+
}
755+
if (isset($demographicFilterBuilder)) {
756+
$params['filter'] = [
757+
'demographic' => $demographicFilterBuilder->build(),
758+
];
759+
}
760+
if (isset($limit)) {
761+
$params['limit'] = [
762+
'max' => $limit
763+
];
764+
}
765+
return $this->httpClient->post($this->endpointBase . '/v2/bot/message/narrowcast', $params);
766+
}
767+
768+
/**
769+
* Get Narrowcast message sending progress.
770+
*
771+
* @param string $requestId
772+
* @return Response
773+
*/
774+
public function getNarrowcastProgress($requestId)
775+
{
776+
$url = $this->endpointBase . '/v2/bot/message/progress/narrowcast';
777+
return $this->httpClient->get($url, ['requestId' => $requestId]);
778+
}
731779
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright 2020 LINE Corporation
4+
*
5+
* LINE Corporation licenses this file to you under the Apache License,
6+
* version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at:
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*/
17+
18+
namespace LINE\LINEBot\Narrowcast\DemographicFilter;
19+
20+
/**
21+
* A builder class for age demographic filter
22+
*
23+
* @package LINE\LINEBot\Narrowcast\DemographicFilter
24+
*/
25+
class AgeDemographicFilterBuilder extends RangeDemographicFilterBuilder
26+
{
27+
const TYPE = 'age';
28+
29+
/**
30+
* @return string
31+
*/
32+
protected function getType()
33+
{
34+
return self::TYPE;
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright 2020 LINE Corporation
4+
*
5+
* LINE Corporation licenses this file to you under the Apache License,
6+
* version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at:
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*/
17+
18+
namespace LINE\LINEBot\Narrowcast\DemographicFilter;
19+
20+
/**
21+
* A builder class for app type demographic filter
22+
*
23+
* @package LINE\LINEBot\Narrowcast\DemographicFilter
24+
*/
25+
class AppTypeDemographicFilterBuilder extends OneOfDemographicFilter
26+
{
27+
const TYPE = 'appType';
28+
29+
/**
30+
* Get type
31+
*
32+
* @return string
33+
*/
34+
protected function getType()
35+
{
36+
return self::TYPE;
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright 2020 LINE Corporation
4+
*
5+
* LINE Corporation licenses this file to you under the Apache License,
6+
* version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at:
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*/
17+
18+
namespace LINE\LINEBot\Narrowcast\DemographicFilter;
19+
20+
/**
21+
* A builder class for area demographic filter
22+
*
23+
* @package LINE\LINEBot\Narrowcast\DemographicFilter
24+
*/
25+
class AreaDemographicFilterBuilder extends OneOfDemographicFilter
26+
{
27+
const TYPE = 'area';
28+
29+
/**
30+
* Get type
31+
*
32+
* @return string
33+
*/
34+
protected function getType()
35+
{
36+
return self::TYPE;
37+
}
38+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright 2020 LINE Corporation
4+
*
5+
* LINE Corporation licenses this file to you under the Apache License,
6+
* version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at:
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*/
17+
18+
namespace LINE\LINEBot\Narrowcast\DemographicFilter;
19+
20+
/**
21+
* A builder class for demographic filter
22+
*
23+
* @package LINE\LINEBot\Narrowcast\DemographicFilter
24+
*/
25+
abstract class DemographicFilterBuilder
26+
{
27+
/**
28+
* Builds demographic filter
29+
*
30+
* @return array
31+
*/
32+
abstract public function build();
33+
34+
/**
35+
* Create builder
36+
*
37+
* @return DemographicFilterBuilder
38+
*/
39+
public static function builder()
40+
{
41+
$class = \get_called_class();
42+
return new $class();
43+
}
44+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright 2020 LINE Corporation
4+
*
5+
* LINE Corporation licenses this file to you under the Apache License,
6+
* version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at:
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*/
17+
18+
namespace LINE\LINEBot\Narrowcast\DemographicFilter;
19+
20+
/**
21+
* A builder class for gender demographic filter
22+
*
23+
* @package LINE\LINEBot\Narrowcast\DemographicFilter
24+
*/
25+
class GenderDemographicFilterBuilder extends OneOfDemographicFilter
26+
{
27+
const TYPE = 'gender';
28+
29+
/**
30+
* Get type
31+
*
32+
* @return string
33+
*/
34+
protected function getType()
35+
{
36+
return self::TYPE;
37+
}
38+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright 2020 LINE Corporation
4+
*
5+
* LINE Corporation licenses this file to you under the Apache License,
6+
* version 2.0 (the "License"); you may not use this file except in compliance
7+
* with the License. You may obtain a copy of the License at:
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*/
17+
18+
namespace LINE\LINEBot\Narrowcast\DemographicFilter;
19+
20+
/**
21+
* A builder class for demographic filter has a oneOf parameter
22+
*
23+
* @package LINE\LINEBot\Narrowcast\DemographicFilter
24+
*/
25+
abstract class OneOfDemographicFilter extends DemographicFilterBuilder
26+
{
27+
/** @var string[] $oneOf */
28+
private $oneOf = [];
29+
30+
/**
31+
* Get type
32+
*
33+
* @return string
34+
*/
35+
abstract protected function getType();
36+
37+
/**
38+
* Set oneOf
39+
*
40+
* @param string[] $oneOf
41+
* @return $this
42+
*/
43+
public function setOneOf($oneOf)
44+
{
45+
$this->oneOf = $oneOf;
46+
return $this;
47+
}
48+
49+
/**
50+
* Builds demographic filter
51+
*
52+
* @return array
53+
*/
54+
public function build()
55+
{
56+
return [
57+
'type' => $this->getType(),
58+
'oneOf' => $this->oneOf,
59+
];
60+
}
61+
}

0 commit comments

Comments
 (0)