TrackerResource   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 87
ccs 17
cts 17
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A push() 0 8 3
A getCounters() 0 4 1
A getPostsFeed() 0 6 1
A getSubscribersFeed() 0 6 1
A getMentions() 0 6 1
A getAppsFeed() 0 4 1
1
<?php
2
3
namespace Habrahabr\Api\Resources;
4
5
use Habrahabr\Api\Exception\IncorrectUsageException;
6
7
/**
8
 * Class TrackerResource
9
 *
10
 * Ресурс работы с трекером
11
 *
12
 * @package Habrahabr\Api\Resources
13
 * @version 0.1.5
14
 * @author thematicmedia <[email protected]>
15
 * @link https://tmtm.ru/
16
 * @link https://habrahabr.ru/
17
 * @link https://github.com/thematicmedia/habrahabr_api
18
 *
19
 * For the full copyright and license information, please view the LICENSE
20
 * file that was distributed with this source code.
21
 */
22
class TrackerResource extends AbstractResource implements ResourceInterface
23
{
24
    /**
25
     * Отправить сообщение в трекер на вкладку "Приложения"
26
     *
27
     * @param string $title Заголова для пуша
28
     * @param string $text Текст для пуша
29
     * @return array
30
     * @throws IncorrectUsageException
31
     */
32 2
    public function push($title, $text)
33
    {
34 2
        if (!is_string($title) || !is_string($text)) {
35 1
            throw new IncorrectUsageException('Push failed: Title or Text is not string');
36
        }
37
38 1
        return $this->adapter->put('/tracker', ['title' => $title, 'text' => $text]);
39
    }
40
41
    /**
42
     * Возвращает счетчики новых сообщений из трекера,
43
     * элементы не отмечаются как просмотренные
44
     *
45
     * @return array
46
     */
47 1
    public function getCounters()
48
    {
49 1
        return $this->adapter->get('/tracker/counters');
50
    }
51
52
    /**
53
     * Возвращает список постов из трекера,
54
     * элементы не отмечаются как просмотренные
55
     *
56
     * @param int $page Номер страницы
57
     * @return array
58
     * @throws IncorrectUsageException
59
     */
60 1
    public function getPostsFeed($page = 1)
61
    {
62 1
        $this->checkPageNumber($page);
63
64 1
        return $this->adapter->get(sprintf('/tracker/posts?page=%d', $page));
65
    }
66
67
    /**
68
     * Возвращает список подписчиков из трекера,
69
     * элементы не отмечаются как просмотренные
70
     *
71
     * @param int $page Номер страницы
72
     * @return array
73
     * @throws IncorrectUsageException
74
     */
75 1
    public function getSubscribersFeed($page = 1)
76
    {
77 1
        $this->checkPageNumber($page);
78
79 1
        return $this->adapter->get(sprintf('/tracker/subscribers?page=%d', $page));
80
    }
81
82
83
    /**
84
     * Возвращает список упоминаний из трекера,
85
     * элементы не отмечаются как просмотренные
86
     *
87
     * @param int $page Номер страницы
88
     * @return array
89
     * @throws IncorrectUsageException
90
     */
91 1
    public function getMentions($page = 1)
92
    {
93 1
        $this->checkPageNumber($page);
94
95 1
        return $this->adapter->get(sprintf('/tracker/mentions?page=%d', $page));
96
    }
97
98
    /**
99
     * Возвращает список сообщений приложений из трекера,
100
     * элементы не отмечаются как просмотренные
101
     *
102
     * @return array
103
     */
104 1
    public function getAppsFeed()
105
    {
106 1
        return $this->adapter->get('/tracker/apps');
107
    }
108
}
109