Completed
Pull Request — master (#34)
by Romain
02:42
created

Insights::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
namespace Kerox\Messenger\Api;
3
4
use GuzzleHttp\ClientInterface;
5
use Kerox\Messenger\Request\InsightsRequest;
6
use Kerox\Messenger\Response\InsightsResponse;
7
8
class Insights extends AbstractApi
9
{
10
11
    /**
12
     * @var null|\Kerox\Messenger\Api\Insights
13
     */
14
    private static $_instance;
15
16
    /**
17
     * Insights constructor.
18
     *
19
     * @param string $pageToken
20
     * @param \GuzzleHttp\ClientInterface $client
21
     */
22 3
    public function __construct(string $pageToken, ClientInterface $client)
23
    {
24 3
        parent::__construct($pageToken, $client);
25 3
    }
26
27
    /**
28
     * @param string $pageToken
29
     * @param \GuzzleHttp\ClientInterface $client
30
     * @return \Kerox\Messenger\Api\Insights
31
     */
32 1
    public static function getInstance(string $pageToken, ClientInterface $client): Insights
33
    {
34 1
        if (self::$_instance === null) {
35 1
            self::$_instance = new Insights($pageToken, $client);
36
        }
37
38 1
        return self::$_instance;
39
    }
40
41
    /**
42
     * @return \Kerox\Messenger\Response\InsightsResponse
43
     */
44 1
    public function threads(): InsightsResponse
45
    {
46 1
        $request = new InsightsRequest($this->pageToken);
47 1
        $response = $this->client->get('me/insights/page_messages_active_threads_unique', $request->build());
48
49 1
        return new InsightsResponse($response);
50
    }
51
52
    /**
53
     * @return \Kerox\Messenger\Response\InsightsResponse
54
     */
55 1
    public function feedback(): InsightsResponse
56
    {
57 1
        $request = new InsightsRequest($this->pageToken);
58 1
        $response = $this->client->get('me/insights/page_messages_feedback_by_action_unique', $request->build());
59
60 1
        return new InsightsResponse($response);
61
    }
62
}
63