1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bitbucket-api package. |
5
|
|
|
* |
6
|
|
|
* (c) Alexandru G. <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bitbucket\API; |
13
|
|
|
|
14
|
|
|
use Bitbucket\API\Groups\Members; |
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Provides functionality for querying information about groups, |
19
|
|
|
* creating new ones, updating memberships, and deleting them. |
20
|
|
|
* |
21
|
|
|
* @author Alexandru G. <[email protected]> |
22
|
|
|
* @see https://confluence.atlassian.com/bitbucket/groups-endpoint-296093143.html |
23
|
|
|
*/ |
24
|
|
|
class Groups extends Api |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Get a list of groups. |
28
|
|
|
* |
29
|
|
|
* If `$filters` is not omitted, will return a list of matching groups. |
30
|
|
|
* |
31
|
|
|
* <example> |
32
|
|
|
* $filters = array( |
33
|
|
|
* 'group' => array('account_name/group_slug', 'other_account/group_slug') |
34
|
|
|
* ); |
35
|
|
|
* </example> |
36
|
|
|
* |
37
|
|
|
* @access public |
38
|
|
|
* @param string $account The team or individual account owning the repository. |
39
|
|
|
* @param array $filters |
40
|
2 |
|
* @return ResponseInterface |
41
|
|
|
*/ |
42
|
|
|
public function get($account, array $filters = array()) |
43
|
2 |
|
{ |
44
|
|
|
// Default: fetch groups list |
45
|
2 |
|
$endpoint = sprintf('/groups/%s/', $account); |
46
|
1 |
|
|
47
|
|
|
if (!empty($filters)) { |
48
|
1 |
|
$endpoint = '/groups'; |
49
|
1 |
|
|
50
|
|
|
if (isset($filters['group']) && is_array($filters['group'])) { |
51
|
|
|
$filters['group'] = implode('&group=', $filters['group']); |
52
|
|
|
} |
53
|
2 |
|
} |
54
|
|
|
|
55
|
|
|
return $this->getClient()->setApiVersion('1.0')->get($endpoint, $filters); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create a new group |
60
|
|
|
* |
61
|
|
|
* @access public |
62
|
|
|
* @param string $account The team or individual account owning the repository. |
63
|
|
|
* @param string $name The name of the group. |
64
|
1 |
|
* @return ResponseInterface |
65
|
|
|
*/ |
66
|
1 |
|
public function create($account, $name) |
67
|
1 |
|
{ |
68
|
1 |
|
return $this->getClient()->setApiVersion('1.0')->post( |
69
|
|
|
sprintf('/groups/%s/', $account), |
70
|
|
|
array('name' => $name) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Update a group |
76
|
|
|
* |
77
|
|
|
* @access public |
78
|
|
|
* @param string $account The team or individual account owning the repository. |
79
|
|
|
* @param string $name The name of the group. |
80
|
|
|
* @param array $params |
81
|
1 |
|
* @return ResponseInterface |
82
|
|
|
*/ |
83
|
1 |
|
public function update($account, $name, array $params) |
84
|
1 |
|
{ |
85
|
1 |
|
return $this->getClient()->setApiVersion('1.0')->put( |
86
|
|
|
sprintf('/groups/%s/%s/', $account, $name), |
87
|
|
|
$params |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Delete a group |
93
|
|
|
* |
94
|
|
|
* @access public |
95
|
|
|
* @param string $account The team or individual account owning the repository. |
96
|
|
|
* @param string $name The name of the group. |
97
|
1 |
|
* @return ResponseInterface |
98
|
|
|
*/ |
99
|
1 |
|
public function delete($account, $name) |
100
|
1 |
|
{ |
101
|
|
|
return $this->getClient()->setApiVersion('1.0')->delete( |
102
|
|
|
sprintf('/groups/%s/%s/', $account, $name) |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get members |
108
|
|
|
* |
109
|
|
|
* @access public |
110
|
|
|
* @return Groups\Members |
111
|
|
|
* |
112
|
|
|
* @throws \InvalidArgumentException |
113
|
|
|
* @codeCoverageIgnore |
114
|
|
|
*/ |
115
|
|
|
public function members() |
116
|
|
|
{ |
117
|
|
|
return $this->api(Members::class); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|