-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: webhooks_listeners app support for sending direct requests to E…
…xApps using AppAPI. Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
- Loading branch information
Showing
3 changed files
with
126 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,92 @@ | ||
<?php | ||
|
||
namespace OCA\AppAPI\Service; | ||
|
||
use OCP\IRequest; | ||
|
||
class AppAPIService { | ||
/** | ||
* @param IRequest $request | ||
* @param bool $isDav | ||
* | ||
* @return bool | ||
*/ | ||
public function validateExAppRequestToNC(IRequest $request, bool $isDav = false): bool {} | ||
namespace OCA\AppAPI\Service { | ||
use OCP\IRequest; | ||
|
||
class AppAPIService { | ||
/** | ||
* @param IRequest $request | ||
* @param bool $isDav | ||
* | ||
* @return bool | ||
*/ | ||
public function validateExAppRequestToNC(IRequest $request, bool $isDav = false): bool {} | ||
} | ||
} | ||
|
||
namespace OCA\AppAPI { | ||
|
||
use OCP\IRequest; | ||
use OCP\Http\Client\IPromise; | ||
use OCP\Http\Client\IResponse; | ||
|
||
class PublicFunctions { | ||
|
||
public function __construct( | ||
private readonly ExAppService $exAppService, | ||
private readonly AppAPIService $service, | ||
) { | ||
} | ||
|
||
/** | ||
* Request to ExApp with AppAPI auth headers | ||
*/ | ||
public function exAppRequest( | ||
string $appId, | ||
string $route, | ||
?string $userId = null, | ||
string $method = 'POST', | ||
array $params = [], | ||
array $options = [], | ||
?IRequest $request = null, | ||
): array|IResponse { | ||
$exApp = $this->exAppService->getExApp($appId); | ||
if ($exApp === null) { | ||
return ['error' => sprintf('ExApp `%s` not found', $appId)]; | ||
} | ||
return $this->service->requestToExApp($exApp, $route, $userId, $method, $params, $options, $request); | ||
} | ||
|
||
/** | ||
* Async request to ExApp with AppAPI auth headers | ||
* | ||
* @throws \Exception if ExApp not found | ||
*/ | ||
public function asyncExAppRequest( | ||
string $appId, | ||
string $route, | ||
?string $userId = null, | ||
string $method = 'POST', | ||
array $params = [], | ||
array $options = [], | ||
?IRequest $request = null, | ||
): IPromise { | ||
$exApp = $this->exAppService->getExApp($appId); | ||
if ($exApp === null) { | ||
throw new \Exception(sprintf('ExApp `%s` not found', $appId)); | ||
} | ||
return $this->service->requestToExAppAsync($exApp, $route, $userId, $method, $params, $options, $request); | ||
} | ||
|
||
/** | ||
* Get basic ExApp info by appid | ||
* | ||
* @param string $appId | ||
* | ||
* @return array|null ExApp info (appid, version, name, enabled) or null if no ExApp found | ||
*/ | ||
public function getExApp(string $appId): ?array { | ||
$exApp = $this->exAppService->getExApp($appId); | ||
if ($exApp !== null) { | ||
$info = $exApp->jsonSerialize(); | ||
return [ | ||
'appid' => $info['appid'], | ||
'version' => $info['version'], | ||
'name' => $info['name'], | ||
'enabled' => $info['enabled'], | ||
]; | ||
} | ||
return null; | ||
} | ||
} | ||
} |