Fully upgraded to BitBucket API 2.0.
Previously the update checker used a mix of 2.0 and 1.0. Version 1.0 was deprecated a while ago and has now stopped working for at least some users. This should fix the errors reported in #289.
This commit is contained in:
parent
3ad92e3135
commit
3f5a340ded
|
|
@ -157,11 +157,11 @@ if ( !class_exists('Puc_v4p6_Vcs_BitBucketApi', false) ):
|
||||||
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
||||||
*/
|
*/
|
||||||
public function getRemoteFile($path, $ref = 'master') {
|
public function getRemoteFile($path, $ref = 'master') {
|
||||||
$response = $this->api('src/' . $ref . '/' . ltrim($path), '1.0');
|
$response = $this->api('src/' . $ref . '/' . ltrim($path));
|
||||||
if ( is_wp_error($response) || !isset($response, $response->data) ) {
|
if ( is_wp_error($response) || !is_string($response) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $response->data;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -186,13 +186,16 @@ if ( !class_exists('Puc_v4p6_Vcs_BitBucketApi', false) ):
|
||||||
* @return mixed|WP_Error
|
* @return mixed|WP_Error
|
||||||
*/
|
*/
|
||||||
public function api($url, $version = '2.0') {
|
public function api($url, $version = '2.0') {
|
||||||
|
$url = ltrim($url, '/');
|
||||||
|
$isSrcResource = Puc_v4p6_Utils::startsWith($url, 'src/');
|
||||||
|
|
||||||
$url = implode('/', array(
|
$url = implode('/', array(
|
||||||
'https://api.bitbucket.org',
|
'https://api.bitbucket.org',
|
||||||
$version,
|
$version,
|
||||||
'repositories',
|
'repositories',
|
||||||
$this->username,
|
$this->username,
|
||||||
$this->repository,
|
$this->repository,
|
||||||
ltrim($url, '/')
|
$url
|
||||||
));
|
));
|
||||||
$baseUrl = $url;
|
$baseUrl = $url;
|
||||||
|
|
||||||
|
|
@ -213,7 +216,13 @@ if ( !class_exists('Puc_v4p6_Vcs_BitBucketApi', false) ):
|
||||||
$code = wp_remote_retrieve_response_code($response);
|
$code = wp_remote_retrieve_response_code($response);
|
||||||
$body = wp_remote_retrieve_body($response);
|
$body = wp_remote_retrieve_body($response);
|
||||||
if ( $code === 200 ) {
|
if ( $code === 200 ) {
|
||||||
$document = json_decode($body);
|
if ( $isSrcResource ) {
|
||||||
|
//Most responses are JSON-encoded, but src resources just
|
||||||
|
//return raw file contents.
|
||||||
|
$document = $body;
|
||||||
|
} else {
|
||||||
|
$document = json_decode($body);
|
||||||
|
}
|
||||||
return $document;
|
return $document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue