Completed
Push — master ( 8e0ded...b5dffc )
by Romain
10s
created

Messenger::webhook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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