|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yandex\Metrica\Management; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class CountersClient |
|
7
|
|
|
* |
|
8
|
|
|
* @category Yandex |
|
9
|
|
|
* @package Metrica |
|
10
|
|
|
* |
|
11
|
|
|
* @author Alexander Khaylo <[email protected]> |
|
12
|
|
|
* @created 13.02.14 17:30 |
|
13
|
|
|
*/ |
|
14
|
|
|
class CountersClient extends ManagementClient |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Get counters |
|
19
|
|
|
* |
|
20
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/counters/counters.xml |
|
21
|
|
|
* |
|
22
|
|
|
* @param Models\CountersParams $params |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
1 |
|
public function getCounters(Models\CountersParams $params) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$resource = 'counters'; |
|
28
|
1 |
|
$response = $this->sendGetRequest($resource, $params->toArray()); |
|
29
|
1 |
|
$counters = new Models\GetCountersResponse($response); |
|
30
|
|
|
|
|
31
|
1 |
|
return $counters; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Add counter |
|
37
|
|
|
* |
|
38
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/counters/addcounter.xml |
|
39
|
|
|
* |
|
40
|
|
|
* @param Models\Counter $counter |
|
41
|
|
|
* @return Models\Counter |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function addCounter(Models\Counter $counter) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$resource = 'counters'; |
|
46
|
1 |
|
$response = $this->sendPostRequest($resource, ["counter" => $counter->toArray()]); |
|
47
|
1 |
|
$counter = new Models\AddCounterResponse($response); |
|
48
|
1 |
|
return $counter->getCounter(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get counter |
|
54
|
|
|
* |
|
55
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/counters/counter.xml |
|
56
|
|
|
* |
|
57
|
|
|
* @param int $id |
|
58
|
|
|
* @param Models\CounterParams $params |
|
59
|
|
|
* @return Models\Counter |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function getCounter($id, Models\CounterParams $params) |
|
62
|
|
|
{ |
|
63
|
1 |
|
$resource = 'counter/' . $id; |
|
64
|
1 |
|
$response = $this->sendGetRequest($resource, $params->toArray()); |
|
65
|
1 |
|
$counter = new Models\GetCounterResponse($response); |
|
66
|
1 |
|
return $counter->getCounter(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Update counter |
|
72
|
|
|
* |
|
73
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/counters/editcounter.xml |
|
74
|
|
|
* |
|
75
|
|
|
* @param int $id |
|
76
|
|
|
* @param Models\ExtendCounter $counter |
|
77
|
|
|
* @return Models\Counter |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function updateCounter($id, Models\ExtendCounter $counter) |
|
80
|
|
|
{ |
|
81
|
1 |
|
$resource = 'counter/' . $id; |
|
82
|
1 |
|
$response = $this->sendPutRequest($resource, ["counter" => $counter->toArray()]); |
|
83
|
1 |
|
$counter = new Models\UpdateCounterResponse($response); |
|
84
|
1 |
|
return $counter->getCounter(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Undelete counter |
|
89
|
|
|
* |
|
90
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/counters/undeletecounter.xml |
|
91
|
|
|
* |
|
92
|
|
|
* @param int $id |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function undeleteCounter($id) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$resource = 'counter/' . $id . '/undelete'; |
|
98
|
1 |
|
$response = $this->sendPostRequest($resource, []); |
|
99
|
1 |
|
return $response; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Delete counter |
|
105
|
|
|
* |
|
106
|
|
|
* @see http://api.yandex.ru/metrika/doc/ref/reference/delete-counter.xml |
|
107
|
|
|
* |
|
108
|
|
|
* @param int $id |
|
109
|
|
|
* @return array |
|
110
|
|
|
*/ |
|
111
|
1 |
|
public function deleteCounter($id) |
|
112
|
|
|
{ |
|
113
|
1 |
|
$resource = 'counter/' . $id; |
|
114
|
1 |
|
$response = $this->sendDeleteRequest($resource); |
|
115
|
1 |
|
return $response; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|