Passed
Push — master ( 151cc0...3583a4 )
by Romain
49s
created

Messenger::persona()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger;
6
7
use GuzzleHttp\Client;
8
use GuzzleHttp\ClientInterface;
9
use Kerox\Messenger\Api\Broadcast;
10
use Kerox\Messenger\Api\Code;
11
use Kerox\Messenger\Api\Insights;
12
use Kerox\Messenger\Api\Nlp;
13
use Kerox\Messenger\Api\Persona;
14
use Kerox\Messenger\Api\Profile;
15
use Kerox\Messenger\Api\Send;
16
use Kerox\Messenger\Api\Tag;
17
use Kerox\Messenger\Api\Thread;
18
use Kerox\Messenger\Api\User;
19
use Kerox\Messenger\Api\Webhook;
20
use Psr\Http\Message\ServerRequestInterface;
21
22
class Messenger
23
{
24
    public const API_URL = 'https://graph.facebook.com/';
25
    public const API_VERSION = 'v3.1';
26
27
    /**
28
     * @var string
29
     */
30
    protected $appSecret;
31
32
    /**
33
     * @var string
34
     */
35
    protected $verifyToken;
36
37
    /**
38
     * @var string
39
     */
40
    protected $pageToken;
41
42
    /**
43
     * @var \GuzzleHttp\ClientInterface
44
     */
45
    protected $client;
46
47
    /**
48
     * Messenger constructor.
49
     *
50
     * @param string                           $appSecret
51
     * @param string                           $verifyToken
52
     * @param string                           $pageToken
53
     * @param string                           $apiVersion
54
     * @param null|\GuzzleHttp\ClientInterface $client
55
     */
56 1
    public function __construct(
57
        string $appSecret,
58
        string $verifyToken,
59
        string $pageToken,
60
        string $apiVersion = self::API_VERSION,
61
        ?ClientInterface $client = null
62
    ) {
63 1
        $this->appSecret = $appSecret;
64 1
        $this->verifyToken = $verifyToken;
65 1
        $this->pageToken = $pageToken;
66
67 1
        if ($client === null) {
68 1
            $client = new Client([
69 1
                'base_uri' => self::API_URL . $apiVersion . '/',
70
            ]);
71
        }
72 1
        $this->client = $client;
73 1
    }
74
75
    /**
76
     * @return \Kerox\Messenger\Api\Send
77
     */
78 1
    public function send(): Send
79
    {
80 1
        return new Send($this->pageToken, $this->client);
81
    }
82
83
    /**
84
     * @param null|\Psr\Http\Message\ServerRequestInterface $request
85
     *
86
     * @return \Kerox\Messenger\Api\Webhook
87
     */
88 1
    public function webhook(?ServerRequestInterface $request = null): Webhook
89
    {
90 1
        return new Webhook($this->appSecret, $this->verifyToken, $this->pageToken, $this->client, $request);
91
    }
92
93
    /**
94
     * @return \Kerox\Messenger\Api\User
95
     */
96 1
    public function user(): User
97
    {
98 1
        return new User($this->pageToken, $this->client);
99
    }
100
101
    /**
102
     * @return \Kerox\Messenger\Api\Profile
103
     */
104 1
    public function profile(): Profile
105
    {
106 1
        return new Profile($this->pageToken, $this->client);
107
    }
108
109
    /**
110
     * @return \Kerox\Messenger\Api\Code
111
     */
112 1
    public function code(): Code
113
    {
114 1
        return new Code($this->pageToken, $this->client);
115
    }
116
117
    /**
118
     * @return \Kerox\Messenger\Api\Insights
119
     */
120 1
    public function insights(): Insights
121
    {
122 1
        return new Insights($this->pageToken, $this->client);
123
    }
124
125
    /**
126
     * @return \Kerox\Messenger\Api\Tag
127
     */
128 1
    public function tag(): Tag
129
    {
130 1
        return new Tag($this->pageToken, $this->client);
131
    }
132
133
    /**
134
     * @return \Kerox\Messenger\Api\Thread
135
     */
136 1
    public function thread(): Thread
137
    {
138 1
        return new Thread($this->pageToken, $this->client);
139
    }
140
141
    /**
142
     * @return \Kerox\Messenger\Api\Nlp
143
     */
144 1
    public function nlp(): Nlp
145
    {
146 1
        return new Nlp($this->pageToken, $this->client);
147
    }
148
149
    /**
150
     * @return \Kerox\Messenger\Api\Broadcast
151
     */
152 1
    public function broadcast(): Broadcast
153
    {
154 1
        return new Broadcast($this->pageToken, $this->client);
155
    }
156
157
    /**
158
     * @return \Kerox\Messenger\Api\Persona
159
     */
160 1
    public function persona(): Persona
161
    {
162 1
        return new Persona($this->pageToken, $this->client);
163
    }
164
}
165