Skip to content

Commit aaa64b7

Browse files
committed
Merged in titpetric/bitbucket-api (pull request gentlero#2)
fix and close gentlero#14 - group privileges grant
2 parents 12264a5 + 74b620d commit aaa64b7

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

lib/Bitbucket/API/Api.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,15 @@ public function requestDelete($endpoint, $params = array(), $headers = array())
171171
*
172172
* @throws \RuntimeException
173173
*/
174-
protected function doRequest($method, $endpoint, array $params, array $headers)
174+
protected function doRequest($method, $endpoint, $params, array $headers)
175175
{
176176
$request = new Request;
177177
$response = new Response;
178178

179-
if (strtoupper($method) != 'POST') {
180-
$params['format'] = $this->format;
179+
$query = array("format" => $this->format);
180+
181+
if (strtoupper($method) != 'POST' && is_array($params)) {
182+
$query = array_merge($query, $params);
181183
}
182184

183185
$request->setMethod($method);
@@ -186,11 +188,9 @@ protected function doRequest($method, $endpoint, array $params, array $headers)
186188

187189
$this->authorize($request);
188190

189-
if (strtoupper($method) == 'GET') {
190-
$request->fromUrl(self::API_URL.'/'.urlencode($endpoint).'?'. urldecode(http_build_query($params)));
191-
} else {
192-
$request->fromUrl(self::API_URL.'/'.urlencode($endpoint));
193-
$request->setContent(http_build_query($params));
191+
$request->fromUrl(self::API_URL.'/'.urlencode($endpoint).'?'. urldecode(http_build_query($query)));
192+
if (strtoupper($method) !== 'GET') {
193+
$request->setContent(is_array($params) ? http_build_query($params) : $params);
194194
}
195195

196196
$this->client->send($request, $response);

lib/Bitbucket/API/GroupPrivileges.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function grant($account, $repo, $group_owner, $group_slug, $privilege)
111111

112112
return $this->requestPut(
113113
sprintf('group-privileges/%s/%s/%s/%s', $account, $repo, $group_owner, $group_slug),
114-
array('privilege' => $privilege)
114+
$privilege
115115
);
116116
}
117117

test/Bitbucket/Tests/API/GroupPrivilegesTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ public function testGrantGroupPrivilegesInvalidPrivilege()
7373
public function testGrantGroupPrivilegesSuccess()
7474
{
7575
$endpoint = 'group-privileges/gentle/repo/owner/sys-admins';
76-
$params = array(
77-
'privilege' => 'read'
78-
);
76+
$params = 'read';
7977

8078
$privileges = $this->getApiMock('Bitbucket\API\GroupPrivileges');
8179
$privileges->expects($this->once())

0 commit comments

Comments
 (0)