Completed
Push — master ( 3347ae...8ec7fe )
by Romain
9s
created

Messenger::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
namespace Kerox\Messenger;
3
4
use GuzzleHttp\Client;
5
use Kerox\Messenger\Api\Send;
6
use Kerox\Messenger\Api\Thread;
7
use Kerox\Messenger\Api\User;
8
use Kerox\Messenger\Api\Webhook;
9
10
class Messenger
11
{
12
13
    const API_URL = 'https://graph.facebook.com/';
14
    const API_VERSION = 'v2.6';
15
16
    /**
17
     * var string
18
     */
19
    protected $pageToken;
20
21
    /**
22
     * @var \GuzzleHttp\Client
23
     */
24
    protected $client;
25
26
    /**
27
     * Messenger constructor.
28
     *
29
     * @param string $pageToken
30
     */
31
    public function __construct(string $pageToken)
32
    {
33
        $this->pageToken = $pageToken;
34
        $this->client = new Client([
35
            'base_uri' => self::API_URL . self::API_VERSION,
36
        ]);
37
    }
38
39
    /**
40
     * @return \Kerox\Messenger\Api\Send
41
     */
42
    public function send(): Send
43
    {
44
        return $this->getApiInstance('Send');
45
    }
46
47
    /**
48
     * @return \Kerox\Messenger\Api\Webhook
49
     */
50
    public function webhook(): Webhook
51
    {
52
        return $this->getApiInstance('Webhook');
53
    }
54
55
    /**
56
     * @return \Kerox\Messenger\Api\User
57
     */
58
    public function user(): User
59
    {
60
        return $this->getApiInstance('User');
61
    }
62
63
    /**
64
     * @return \Kerox\Messenger\Api\Thread
65
     */
66
    public function thread(): Thread
67
    {
68
        return $this->getApiInstance('Thread');
69
    }
70
71
    /**
72
     * @param string $className
73
     * @return mixed
74
     */
75
    private function getApiInstance(string $className)
76
    {
77
        return new $className($this->pageToken, $this->client);
78
    }
79
}
80