diff options
author | Robin Appelman <robin@icewind.nl> | 2017-09-27 17:46:24 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-12-08 16:34:33 +0100 |
commit | 74b5ce8fd4311f0d6f6a59e0636d343807b79d74 (patch) | |
tree | 30e2a3f407b94909080aaa7d536c9fe13d8cc731 /lib/private/Remote/Api | |
parent | ac2c26ffcbe63e64156fc7e0b0be4e3466430dcf (diff) | |
download | nextcloud-server-74b5ce8fd4311f0d6f6a59e0636d343807b79d74.tar.gz nextcloud-server-74b5ce8fd4311f0d6f6a59e0636d343807b79d74.zip |
Some tests for the remote cloud api
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Remote/Api')
-rw-r--r-- | lib/private/Remote/Api/OCS.php | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/private/Remote/Api/OCS.php b/lib/private/Remote/Api/OCS.php index d7027ad3f4b..f02538ad03b 100644 --- a/lib/private/Remote/Api/OCS.php +++ b/lib/private/Remote/Api/OCS.php @@ -22,6 +22,7 @@ namespace OC\Remote\Api; +use GuzzleHttp\Exception\ClientException; use OC\ForbiddenException; use OC\Remote\User; use OCP\API; @@ -39,8 +40,18 @@ class OCS extends ApiBase { * @throws \Exception */ protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { - $response = json_decode(parent::request($method, '/ocs/v2.php/' . $url, $body, $query, $headers), true); - if (!isset($result['ocs']) || !isset($result['ocs']['meta'])) { + try { + $response = json_decode(parent::request($method, '/ocs/v2.php/' . $url, $body, $query, $headers), true); + } catch (ClientException $e) { + if ($e->getResponse()->getStatusCode() === 404) { + throw new NotFoundException(); + } else if ($e->getResponse()->getStatusCode() === 403 || $e->getResponse()->getStatusCode() === 401) { + throw new ForbiddenException(); + } else { + throw $e; + } + } + if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) { throw new \Exception('Invalid ocs response'); } if ($response['ocs']['meta']['statuscode'] === API::RESPOND_UNAUTHORISED) { @@ -60,7 +71,11 @@ class OCS extends ApiBase { return new User($this->request('get', 'cloud/users/' . $userId)); } + /** + * @return array The capabilities in the form of [$appId => [$capability => $value]] + */ public function getCapabilities() { - return $this->request('get', 'cloud/capabilities'); + $result = $this->request('get', 'cloud/capabilities'); + return $result['capabilities']; } } |