Passed
Pull Request — master (#93)
by Romain
02:36
created

Broadcast::getAllowedTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Api;
6
7
use Kerox\Messenger\Helper\ValidatorTrait;
8
use Kerox\Messenger\Request\BroadcastRequest;
9
use Kerox\Messenger\Response\BroadcastResponse;
10
use Kerox\Messenger\SendInterface;
11
12
class Broadcast extends AbstractApi implements SendInterface
13
{
14
    use ValidatorTrait;
15
16
    /**
17
     * @param string|\Kerox\Messenger\Model\Message $message
18
     *
19
     * @throws \Exception
20
     *
21
     * @return \Kerox\Messenger\Response\BroadcastResponse
22
     */
23
    public function create($message): BroadcastResponse
24
    {
25
        $message = $this->isValidMessage($message);
26
27
        $request = new BroadcastRequest($this->pageToken, $message);
28
        $response = $this->client->post('me/message_creatives', $request->build());
29
30
        return new BroadcastResponse($response);
31
    }
32
33
    /**
34
     * @param string      $messageCreativeId
35
     * @param string      $notificationType
36
     * @param string|null $tag
37
     *
38
     * @throws \InvalidArgumentException
39
     *
40
     * @return \Kerox\Messenger\Response\BroadcastResponse
41
     */
42
    public function send(
43
        string $messageCreativeId,
44
        string $notificationType = self::NOTIFICATION_TYPE_REGULAR,
45
        ?string $tag = null
46
    ): BroadcastResponse {
47
        $this->isValidNotificationType($notificationType);
48
49
        if ($tag !== null) {
50
            $this->isValidTag($tag);
51
        }
52
53
        $request = new BroadcastRequest($this->pageToken, null, $messageCreativeId, $notificationType, $tag);
54
        $response = $this->client->post('me/broadcast_messages', $request->build());
55
56
        return new BroadcastResponse($response);
57
    }
58
}
59