@@ -25,31 +25,31 @@ |
||
| 25 | 25 | use OCP\Remote\ICredentials; |
| 26 | 26 | |
| 27 | 27 | class Credentials implements ICredentials { |
| 28 | - /** @var string */ |
|
| 29 | - private $user; |
|
| 30 | - /** @var string */ |
|
| 31 | - private $password; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $user; |
|
| 30 | + /** @var string */ |
|
| 31 | + private $password; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param string $user |
|
| 35 | - * @param string $password |
|
| 36 | - */ |
|
| 37 | - public function __construct($user, $password) { |
|
| 38 | - $this->user = $user; |
|
| 39 | - $this->password = $password; |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * @param string $user |
|
| 35 | + * @param string $password |
|
| 36 | + */ |
|
| 37 | + public function __construct($user, $password) { |
|
| 38 | + $this->user = $user; |
|
| 39 | + $this->password = $password; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public function getUsername() { |
|
| 46 | - return $this->user; |
|
| 47 | - } |
|
| 42 | + /** |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public function getUsername() { |
|
| 46 | + return $this->user; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public function getPassword() { |
|
| 53 | - return $this->password; |
|
| 54 | - } |
|
| 49 | + /** |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public function getPassword() { |
|
| 53 | + return $this->password; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -27,11 +27,11 @@ |
||
| 27 | 27 | * @since 13.0.0 |
| 28 | 28 | */ |
| 29 | 29 | interface IUserApi { |
| 30 | - /** |
|
| 31 | - * @param string $userId |
|
| 32 | - * @return IUser |
|
| 33 | - * |
|
| 34 | - * @since 13.0.0 |
|
| 35 | - */ |
|
| 36 | - public function getUser($userId); |
|
| 30 | + /** |
|
| 31 | + * @param string $userId |
|
| 32 | + * @return IUser |
|
| 33 | + * |
|
| 34 | + * @since 13.0.0 |
|
| 35 | + */ |
|
| 36 | + public function getUser($userId); |
|
| 37 | 37 | } |
@@ -25,10 +25,10 @@ |
||
| 25 | 25 | * @since 13.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ICapabilitiesApi { |
| 28 | - /** |
|
| 29 | - * @return array The capabilities in the form of [$appId => [$capability => $value]] |
|
| 30 | - * |
|
| 31 | - * @since 13.0.0 |
|
| 32 | - */ |
|
| 33 | - public function getCapabilities(); |
|
| 28 | + /** |
|
| 29 | + * @return array The capabilities in the form of [$appId => [$capability => $value]] |
|
| 30 | + * |
|
| 31 | + * @since 13.0.0 |
|
| 32 | + */ |
|
| 33 | + public function getCapabilities(); |
|
| 34 | 34 | } |
@@ -28,12 +28,12 @@ |
||
| 28 | 28 | * @since 13.0.0 |
| 29 | 29 | */ |
| 30 | 30 | interface IApiFactory { |
| 31 | - /** |
|
| 32 | - * @param IInstance $instance |
|
| 33 | - * @param ICredentials $credentials |
|
| 34 | - * @return IApiCollection |
|
| 35 | - * |
|
| 36 | - * @since 13.0.0 |
|
| 37 | - */ |
|
| 38 | - public function getApiCollection(IInstance $instance, ICredentials $credentials); |
|
| 31 | + /** |
|
| 32 | + * @param IInstance $instance |
|
| 33 | + * @param ICredentials $credentials |
|
| 34 | + * @return IApiCollection |
|
| 35 | + * |
|
| 36 | + * @since 13.0.0 |
|
| 37 | + */ |
|
| 38 | + public function getApiCollection(IInstance $instance, ICredentials $credentials); |
|
| 39 | 39 | } |
@@ -27,17 +27,17 @@ |
||
| 27 | 27 | * @since 13.0.0 |
| 28 | 28 | */ |
| 29 | 29 | interface IApiCollection { |
| 30 | - /** |
|
| 31 | - * @return IUserApi |
|
| 32 | - * |
|
| 33 | - * @since 13.0.0 |
|
| 34 | - */ |
|
| 35 | - public function getUserApi(); |
|
| 30 | + /** |
|
| 31 | + * @return IUserApi |
|
| 32 | + * |
|
| 33 | + * @since 13.0.0 |
|
| 34 | + */ |
|
| 35 | + public function getUserApi(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return ICapabilitiesApi |
|
| 39 | - * |
|
| 40 | - * @since 13.0.0 |
|
| 41 | - */ |
|
| 42 | - public function getCapabilitiesApi(); |
|
| 37 | + /** |
|
| 38 | + * @return ICapabilitiesApi |
|
| 39 | + * |
|
| 40 | + * @since 13.0.0 |
|
| 41 | + */ |
|
| 42 | + public function getCapabilitiesApi(); |
|
| 43 | 43 | } |
@@ -27,17 +27,17 @@ |
||
| 27 | 27 | * @since 13.0.0 |
| 28 | 28 | */ |
| 29 | 29 | interface ICredentials { |
| 30 | - /** |
|
| 31 | - * @return string |
|
| 32 | - * |
|
| 33 | - * @since 13.0.0 |
|
| 34 | - */ |
|
| 35 | - public function getUsername(); |
|
| 30 | + /** |
|
| 31 | + * @return string |
|
| 32 | + * |
|
| 33 | + * @since 13.0.0 |
|
| 34 | + */ |
|
| 35 | + public function getUsername(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return string |
|
| 39 | - * |
|
| 40 | - * @since 13.0.0 |
|
| 41 | - */ |
|
| 42 | - public function getPassword(); |
|
| 37 | + /** |
|
| 38 | + * @return string |
|
| 39 | + * |
|
| 40 | + * @since 13.0.0 |
|
| 41 | + */ |
|
| 42 | + public function getPassword(); |
|
| 43 | 43 | } |
@@ -27,94 +27,94 @@ |
||
| 27 | 27 | * @since 13.0.0 |
| 28 | 28 | */ |
| 29 | 29 | interface IUser { |
| 30 | - /** |
|
| 31 | - * @return string |
|
| 32 | - * |
|
| 33 | - * @since 13.0.0 |
|
| 34 | - */ |
|
| 35 | - public function getUserId(); |
|
| 30 | + /** |
|
| 31 | + * @return string |
|
| 32 | + * |
|
| 33 | + * @since 13.0.0 |
|
| 34 | + */ |
|
| 35 | + public function getUserId(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return string |
|
| 39 | - * |
|
| 40 | - * @since 13.0.0 |
|
| 41 | - */ |
|
| 42 | - public function getEmail(); |
|
| 37 | + /** |
|
| 38 | + * @return string |
|
| 39 | + * |
|
| 40 | + * @since 13.0.0 |
|
| 41 | + */ |
|
| 42 | + public function getEmail(); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - * |
|
| 47 | - * @since 13.0.0 |
|
| 48 | - */ |
|
| 49 | - public function getDisplayName(); |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + * |
|
| 47 | + * @since 13.0.0 |
|
| 48 | + */ |
|
| 49 | + public function getDisplayName(); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - * |
|
| 54 | - * @since 13.0.0 |
|
| 55 | - */ |
|
| 56 | - public function getPhone(); |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + * |
|
| 54 | + * @since 13.0.0 |
|
| 55 | + */ |
|
| 56 | + public function getPhone(); |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @return string |
|
| 60 | - * |
|
| 61 | - * @since 13.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getAddress(); |
|
| 58 | + /** |
|
| 59 | + * @return string |
|
| 60 | + * |
|
| 61 | + * @since 13.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getAddress(); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return string |
|
| 67 | - * |
|
| 68 | - * @since 13.0.0 |
|
| 69 | - */ |
|
| 70 | - public function getWebsite(); |
|
| 65 | + /** |
|
| 66 | + * @return string |
|
| 67 | + * |
|
| 68 | + * @since 13.0.0 |
|
| 69 | + */ |
|
| 70 | + public function getWebsite(); |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return string |
|
| 74 | - * |
|
| 75 | - * @since 13.0.0 |
|
| 76 | - */ |
|
| 77 | - public function getTwitter(); |
|
| 72 | + /** |
|
| 73 | + * @return string |
|
| 74 | + * |
|
| 75 | + * @since 13.0.0 |
|
| 76 | + */ |
|
| 77 | + public function getTwitter(); |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @return string[] |
|
| 81 | - * |
|
| 82 | - * @since 13.0.0 |
|
| 83 | - */ |
|
| 84 | - public function getGroups(); |
|
| 79 | + /** |
|
| 80 | + * @return string[] |
|
| 81 | + * |
|
| 82 | + * @since 13.0.0 |
|
| 83 | + */ |
|
| 84 | + public function getGroups(); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @return string |
|
| 88 | - * |
|
| 89 | - * @since 13.0.0 |
|
| 90 | - */ |
|
| 91 | - public function getLanguage(); |
|
| 86 | + /** |
|
| 87 | + * @return string |
|
| 88 | + * |
|
| 89 | + * @since 13.0.0 |
|
| 90 | + */ |
|
| 91 | + public function getLanguage(); |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return int |
|
| 95 | - * |
|
| 96 | - * @since 13.0.0 |
|
| 97 | - */ |
|
| 98 | - public function getUsedSpace(); |
|
| 93 | + /** |
|
| 94 | + * @return int |
|
| 95 | + * |
|
| 96 | + * @since 13.0.0 |
|
| 97 | + */ |
|
| 98 | + public function getUsedSpace(); |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return int |
|
| 102 | - * |
|
| 103 | - * @since 13.0.0 |
|
| 104 | - */ |
|
| 105 | - public function getFreeSpace(); |
|
| 100 | + /** |
|
| 101 | + * @return int |
|
| 102 | + * |
|
| 103 | + * @since 13.0.0 |
|
| 104 | + */ |
|
| 105 | + public function getFreeSpace(); |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return int |
|
| 109 | - * |
|
| 110 | - * @since 13.0.0 |
|
| 111 | - */ |
|
| 112 | - public function getTotalSpace(); |
|
| 107 | + /** |
|
| 108 | + * @return int |
|
| 109 | + * |
|
| 110 | + * @since 13.0.0 |
|
| 111 | + */ |
|
| 112 | + public function getTotalSpace(); |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * @return int |
|
| 116 | - * |
|
| 117 | - * @since 13.0.0 |
|
| 118 | - */ |
|
| 119 | - public function getQuota(); |
|
| 114 | + /** |
|
| 115 | + * @return int |
|
| 116 | + * |
|
| 117 | + * @since 13.0.0 |
|
| 118 | + */ |
|
| 119 | + public function getQuota(); |
|
| 120 | 120 | } |
@@ -27,40 +27,40 @@ |
||
| 27 | 27 | * @since 13.0.0 |
| 28 | 28 | */ |
| 29 | 29 | interface IInstance { |
| 30 | - /** |
|
| 31 | - * @return string The url of the remote server without protocol |
|
| 32 | - * |
|
| 33 | - * @since 13.0.0 |
|
| 34 | - */ |
|
| 35 | - public function getUrl(); |
|
| 30 | + /** |
|
| 31 | + * @return string The url of the remote server without protocol |
|
| 32 | + * |
|
| 33 | + * @since 13.0.0 |
|
| 34 | + */ |
|
| 35 | + public function getUrl(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return string The of of the remote server with protocol |
|
| 39 | - * |
|
| 40 | - * @since 13.0.0 |
|
| 41 | - */ |
|
| 42 | - public function getFullUrl(); |
|
| 37 | + /** |
|
| 38 | + * @return string The of of the remote server with protocol |
|
| 39 | + * |
|
| 40 | + * @since 13.0.0 |
|
| 41 | + */ |
|
| 42 | + public function getFullUrl(); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string The full version string in '13.1.2.3' format |
|
| 46 | - * |
|
| 47 | - * @since 13.0.0 |
|
| 48 | - */ |
|
| 49 | - public function getVersion(); |
|
| 44 | + /** |
|
| 45 | + * @return string The full version string in '13.1.2.3' format |
|
| 46 | + * |
|
| 47 | + * @since 13.0.0 |
|
| 48 | + */ |
|
| 49 | + public function getVersion(); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string 'http' or 'https' |
|
| 53 | - * |
|
| 54 | - * @since 13.0.0 |
|
| 55 | - */ |
|
| 56 | - public function getProtocol(); |
|
| 51 | + /** |
|
| 52 | + * @return string 'http' or 'https' |
|
| 53 | + * |
|
| 54 | + * @since 13.0.0 |
|
| 55 | + */ |
|
| 56 | + public function getProtocol(); |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Check that the remote server is installed and not in maintenance mode |
|
| 60 | - * |
|
| 61 | - * @since 13.0.0 |
|
| 62 | - * |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 65 | - public function isActive(); |
|
| 58 | + /** |
|
| 59 | + * Check that the remote server is installed and not in maintenance mode |
|
| 60 | + * |
|
| 61 | + * @since 13.0.0 |
|
| 62 | + * |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | + public function isActive(); |
|
| 66 | 66 | } |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | * @param array $body |
| 57 | 57 | * @param array $query |
| 58 | 58 | * @param array $headers |
| 59 | - * @return resource|string |
|
| 59 | + * @return string |
|
| 60 | 60 | * @throws \InvalidArgumentException |
| 61 | 61 | */ |
| 62 | 62 | protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
@@ -26,72 +26,72 @@ |
||
| 26 | 26 | use OCP\Remote\IInstance; |
| 27 | 27 | |
| 28 | 28 | class ApiBase { |
| 29 | - /** @var IInstance */ |
|
| 30 | - private $instance; |
|
| 31 | - /** @var ICredentials */ |
|
| 32 | - private $credentials; |
|
| 33 | - /** @var IClientService */ |
|
| 34 | - private $clientService; |
|
| 29 | + /** @var IInstance */ |
|
| 30 | + private $instance; |
|
| 31 | + /** @var ICredentials */ |
|
| 32 | + private $credentials; |
|
| 33 | + /** @var IClientService */ |
|
| 34 | + private $clientService; |
|
| 35 | 35 | |
| 36 | - public function __construct(IInstance $instance, ICredentials $credentials, IClientService $clientService) { |
|
| 37 | - $this->instance = $instance; |
|
| 38 | - $this->credentials = $credentials; |
|
| 39 | - $this->clientService = $clientService; |
|
| 40 | - } |
|
| 36 | + public function __construct(IInstance $instance, ICredentials $credentials, IClientService $clientService) { |
|
| 37 | + $this->instance = $instance; |
|
| 38 | + $this->credentials = $credentials; |
|
| 39 | + $this->clientService = $clientService; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - protected function getHttpClient() { |
|
| 43 | - return $this->clientService->newClient(); |
|
| 44 | - } |
|
| 42 | + protected function getHttpClient() { |
|
| 43 | + return $this->clientService->newClient(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - protected function addDefaultHeaders(array $headers) { |
|
| 47 | - return array_merge([ |
|
| 48 | - 'OCS-APIREQUEST' => 'true', |
|
| 49 | - 'Accept' => 'application/json' |
|
| 50 | - ], $headers); |
|
| 51 | - } |
|
| 46 | + protected function addDefaultHeaders(array $headers) { |
|
| 47 | + return array_merge([ |
|
| 48 | + 'OCS-APIREQUEST' => 'true', |
|
| 49 | + 'Accept' => 'application/json' |
|
| 50 | + ], $headers); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param string $method |
|
| 55 | - * @param string $url |
|
| 56 | - * @param array $body |
|
| 57 | - * @param array $query |
|
| 58 | - * @param array $headers |
|
| 59 | - * @return resource|string |
|
| 60 | - * @throws \InvalidArgumentException |
|
| 61 | - */ |
|
| 62 | - protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
|
| 63 | - $fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url; |
|
| 64 | - $options = [ |
|
| 65 | - 'query' => $query, |
|
| 66 | - 'headers' => $this->addDefaultHeaders($headers), |
|
| 67 | - 'auth' => [$this->credentials->getUsername(), $this->credentials->getPassword()] |
|
| 68 | - ]; |
|
| 69 | - if ($body) { |
|
| 70 | - $options['body'] = $body; |
|
| 71 | - } |
|
| 53 | + /** |
|
| 54 | + * @param string $method |
|
| 55 | + * @param string $url |
|
| 56 | + * @param array $body |
|
| 57 | + * @param array $query |
|
| 58 | + * @param array $headers |
|
| 59 | + * @return resource|string |
|
| 60 | + * @throws \InvalidArgumentException |
|
| 61 | + */ |
|
| 62 | + protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
|
| 63 | + $fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url; |
|
| 64 | + $options = [ |
|
| 65 | + 'query' => $query, |
|
| 66 | + 'headers' => $this->addDefaultHeaders($headers), |
|
| 67 | + 'auth' => [$this->credentials->getUsername(), $this->credentials->getPassword()] |
|
| 68 | + ]; |
|
| 69 | + if ($body) { |
|
| 70 | + $options['body'] = $body; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $client = $this->getHttpClient(); |
|
| 73 | + $client = $this->getHttpClient(); |
|
| 74 | 74 | |
| 75 | - switch ($method) { |
|
| 76 | - case 'get': |
|
| 77 | - $response = $client->get($fullUrl, $options); |
|
| 78 | - break; |
|
| 79 | - case 'post': |
|
| 80 | - $response = $client->post($fullUrl, $options); |
|
| 81 | - break; |
|
| 82 | - case 'put': |
|
| 83 | - $response = $client->put($fullUrl, $options); |
|
| 84 | - break; |
|
| 85 | - case 'delete': |
|
| 86 | - $response = $client->delete($fullUrl, $options); |
|
| 87 | - break; |
|
| 88 | - case 'options': |
|
| 89 | - $response = $client->options($fullUrl, $options); |
|
| 90 | - break; |
|
| 91 | - default: |
|
| 92 | - throw new \InvalidArgumentException('Invalid method ' . $method); |
|
| 93 | - } |
|
| 75 | + switch ($method) { |
|
| 76 | + case 'get': |
|
| 77 | + $response = $client->get($fullUrl, $options); |
|
| 78 | + break; |
|
| 79 | + case 'post': |
|
| 80 | + $response = $client->post($fullUrl, $options); |
|
| 81 | + break; |
|
| 82 | + case 'put': |
|
| 83 | + $response = $client->put($fullUrl, $options); |
|
| 84 | + break; |
|
| 85 | + case 'delete': |
|
| 86 | + $response = $client->delete($fullUrl, $options); |
|
| 87 | + break; |
|
| 88 | + case 'options': |
|
| 89 | + $response = $client->options($fullUrl, $options); |
|
| 90 | + break; |
|
| 91 | + default: |
|
| 92 | + throw new \InvalidArgumentException('Invalid method ' . $method); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return $response->getBody(); |
|
| 96 | - } |
|
| 95 | + return $response->getBody(); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @throws \InvalidArgumentException |
| 61 | 61 | */ |
| 62 | 62 | protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
| 63 | - $fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url; |
|
| 63 | + $fullUrl = trim($this->instance->getFullUrl(), '/').'/'.$url; |
|
| 64 | 64 | $options = [ |
| 65 | 65 | 'query' => $query, |
| 66 | 66 | 'headers' => $this->addDefaultHeaders($headers), |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $response = $client->options($fullUrl, $options); |
| 90 | 90 | break; |
| 91 | 91 | default: |
| 92 | - throw new \InvalidArgumentException('Invalid method ' . $method); |
|
| 92 | + throw new \InvalidArgumentException('Invalid method '.$method); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | return $response->getBody(); |