members.php
5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Orgs Members class for the Joomla Platform.
*
* @documentation https://developer.github.com/v3/orgs/members/
*
* @since 3.1.4
* @deprecated 4.0 Use the `joomla/github` package via Composer instead
*/
class JGithubPackageOrgsMembers extends JGithubPackage
{
/**
* Members list.
*
* List all users who are members of an organization.
* A member is a user that belongs to at least 1 team in the organization.
* If the authenticated user is also a member of this organization then
* both concealed and public members will be returned.
* If the requester is not a member of the organization the query will be
* redirected to the public members list.
*
* @param string $org The name of the organization.
*
* @throws UnexpectedValueException
* @since 3.3 (CMS)
*
* @return boolean|mixed
*/
public function getList($org)
{
// Build the request path.
$path = '/orgs/' . $org . '/members';
$response = $this->client->get($this->fetchUrl($path));
switch ($response->code)
{
case 302 :
// Requester is not an organization member.
return false;
break;
case 200 :
return json_decode($response->body);
break;
default :
throw new UnexpectedValueException('Unexpected response code: ' . $response->code);
break;
}
}
/**
* Check membership.
*
* Check if a user is, publicly or privately, a member of the organization.
*
* @param string $org The name of the organization.
* @param string $user The name of the user.
*
* @throws UnexpectedValueException
* @since 3.3 (CMS)
*
* @return boolean
*/
public function check($org, $user)
{
// Build the request path.
$path = '/orgs/' . $org . '/members/' . $user;
$response = $this->client->get($this->fetchUrl($path));
switch ($response->code)
{
case 204 :
// Requester is an organization member and user is a member.
return true;
break;
case 404 :
// Requester is an organization member and user is not a member.
// Requester is not an organization member and is inquiring about themselves.
return false;
break;
case 302 :
// Requester is not an organization member.
return false;
break;
default :
throw new UnexpectedValueException('Unexpected response code: ' . $response->code);
break;
}
}
/**
* Add a member.
*
* To add someone as a member to an org, you must add them to a team.
*/
/**
* Remove a member.
*
* Removing a user from this list will remove them from all teams and they will no longer have
* any access to the organization’s repositories.
*
* @param string $org The name of the organization.
* @param string $user The name of the user.
*
* @since 3.3 (CMS)
*
* @return object
*/
public function remove($org, $user)
{
// Build the request path.
$path = '/orgs/' . $org . '/members/' . $user;
return $this->processResponse(
$this->client->delete($this->fetchUrl($path)),
204
);
}
/**
* Public members list.
*
* Members of an organization can choose to have their membership publicized or not.
*
* @param string $org The name of the organization.
*
* @since 3.3 (CMS)
*
* @return object
*/
public function getListPublic($org)
{
// Build the request path.
$path = '/orgs/' . $org . '/public_members';
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* Check public membership.
*
* @param string $org The name of the organization.
* @param string $user The name of the user.
*
* @throws UnexpectedValueException
* @since 3.3 (CMS)
*
* @return object
*/
public function checkPublic($org, $user)
{
// Build the request path.
$path = '/orgs/' . $org . '/public_members/' . $user;
$response = $this->client->get($this->fetchUrl($path));
switch ($response->code)
{
case 204 :
// Response if user is a public member.
return true;
break;
case 404 :
// Response if user is not a public member.
return false;
break;
default :
throw new UnexpectedValueException('Unexpected response code: ' . $response->code);
break;
}
}
/**
* Publicize a user’s membership.
*
* @param string $org The name of the organization.
* @param string $user The name of the user.
*
* @since 3.3 (CMS)
*
* @return object
*/
public function publicize($org, $user)
{
// Build the request path.
$path = '/orgs/' . $org . '/public_members/' . $user;
return $this->processResponse(
$this->client->put($this->fetchUrl($path), ''),
204
);
}
/**
* Conceal a user’s membership.
*
* @param string $org The name of the organization.
* @param string $user The name of the user.
*
* @since 3.3 (CMS)
*
* @return object
*/
public function conceal($org, $user)
{
// Build the request path.
$path = '/orgs/' . $org . '/public_members/' . $user;
return $this->processResponse(
$this->client->delete($this->fetchUrl($path)),
204
);
}
}