Completed
Pull Request — master (#85)
by Romain
02:41
created

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