|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yandex\Metrica\Management; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class DelegatesClient |
|
6
|
|
|
* |
|
7
|
|
|
* @category Yandex |
|
8
|
|
|
* @package Metrica |
|
9
|
|
|
* |
|
10
|
|
|
* @author Alexander Khaylo <[email protected]> |
|
11
|
|
|
* @created 13.02.14 17:43 |
|
12
|
|
|
*/ |
|
13
|
|
|
class DelegatesClient extends ManagementClient |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Get delegates |
|
17
|
|
|
* |
|
18
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/delegates/delegates.xml |
|
19
|
|
|
* |
|
20
|
|
|
* @return Models\Delegates |
|
21
|
|
|
*/ |
|
22
|
1 |
|
public function getDelegates() |
|
23
|
|
|
{ |
|
24
|
1 |
|
$resource = 'delegates'; |
|
25
|
1 |
|
$response = $this->sendGetRequest($resource); |
|
26
|
1 |
|
$delegateResponse = new Models\GetDelegatesResponse($response); |
|
27
|
1 |
|
return $delegateResponse->getDelegates(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Update delegates |
|
33
|
|
|
* |
|
34
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/delegates/updatedelegates.xml |
|
35
|
|
|
* |
|
36
|
|
|
* @param Models\Delegates $delegates |
|
37
|
|
|
* @return Models\Delegates |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function updateDelegates(Models\Delegates $delegates) |
|
40
|
|
|
{ |
|
41
|
1 |
|
$resource = 'delegates'; |
|
42
|
1 |
|
$response = $this->sendPutRequest($resource, $delegates->toArray()); |
|
43
|
1 |
|
$delegateResponse = new Models\UpdateDelegateResponse($response); |
|
44
|
1 |
|
return $delegateResponse->getDelegates(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Add delegate |
|
50
|
|
|
* |
|
51
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/delegates/adddelegate.xml |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $login |
|
54
|
|
|
* @param string $comment |
|
55
|
|
|
* @return Models\Delegates |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function addDelegates($login, $comment = '') |
|
58
|
|
|
{ |
|
59
|
1 |
|
$resource = 'delegates'; |
|
60
|
|
|
$params = [ |
|
61
|
|
|
'delegate' => [ |
|
62
|
1 |
|
'user_login' => $login, |
|
63
|
1 |
|
'created_at' => date('c'), |
|
64
|
|
|
'comment' => $comment |
|
65
|
1 |
|
] |
|
66
|
1 |
|
]; |
|
67
|
1 |
|
$response = $this->sendPostRequest($resource, $params); |
|
68
|
1 |
|
$delegateResponse = new Models\AddDelegateResponse($response); |
|
69
|
1 |
|
return $delegateResponse->getDelegates(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Delete delegate |
|
75
|
|
|
* |
|
76
|
|
|
* @see http://api.yandex.ru/metrika/doc/beta/management/delegates/deletedelegateold.xml |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $userLogin |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function deleteDelegate($userLogin) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$resource = 'delegate/' . $userLogin; |
|
84
|
1 |
|
$response = $this->sendDeleteRequest($resource); |
|
85
|
1 |
|
return $response; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|