Completed
Branch develop (8166a6)
by Romain
01:52
created

Messenger::getUserProfile()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 3
nop 2
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