Skip to content

Commit 1752fba

Browse files
Fixed path construction
1 parent 85423db commit 1752fba

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Api/AbstractApi.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function pureGet(string $path, array $params = [], array $headers = []
122122
$path .= '?'.http_build_query($params);
123123
}
124124

125-
return $this->client->get($path, $headers);
125+
return $this->client->get(self::computePath($path), $headers);
126126
}
127127

128128
/**
@@ -160,7 +160,7 @@ protected function post(string $path, array $params = [], array $headers = [])
160160
*/
161161
protected function postRaw(string $path, $body = null, array $headers = [])
162162
{
163-
$response = $this->client->post($path, $headers, $body);
163+
$response = $this->client->post(self::computePath($path), $headers, $body);
164164

165165
return ResponseMediator::getContent($response);
166166
}
@@ -200,7 +200,7 @@ protected function put(string $path, array $params = [], array $headers = [])
200200
*/
201201
protected function putRaw(string $path, $body = null, array $headers = [])
202202
{
203-
$response = $this->client->put($path, $headers, $body);
203+
$response = $this->client->put(self::computePath($path), $headers, $body);
204204

205205
return ResponseMediator::getContent($response);
206206
}
@@ -240,7 +240,7 @@ protected function delete(string $path, array $params = [], array $headers = [])
240240
*/
241241
protected function deleteRaw(string $path, $body = null, array $headers = [])
242242
{
243-
$response = $this->client->delete($path, $headers, $body);
243+
$response = $this->client->delete(self::computePath($path), $headers, $body);
244244

245245
return ResponseMediator::getContent($response);
246246
}
@@ -267,6 +267,18 @@ protected static function buildPath(string ...$parts)
267267
return implode('/', $parts);
268268
}
269269

270+
/**
271+
* Compute the prefixed API path.
272+
*
273+
* @param string $path
274+
*
275+
* @return string
276+
*/
277+
private static function computePath(string $path)
278+
{
279+
return sprintf('/2.0/%s', $path);
280+
}
281+
270282
/**
271283
* Create a JSON encoded version of an array of params.
272284
*

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct(Builder $httpClientBuilder = null)
8181
$builder->addPlugin(new ExceptionThrower());
8282
$builder->addPlugin(new HistoryPlugin($this->responseHistory));
8383
$builder->addPlugin(new RedirectPlugin());
84-
$builder->addPlugin(new AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.bitbucket.org/2.0')));
84+
$builder->addPlugin(new AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.bitbucket.org')));
8585
$builder->addPlugin(new HeaderDefaultsPlugin(['User-Agent' => 'bitbucket-api-client/1.0']));
8686

8787
$builder->addHeaderValue('Accept', 'application/json');

0 commit comments

Comments
 (0)