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
|
|
|
|