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