Commit f310c980 authored by Artem Baranovskyi's avatar Artem Baranovskyi
Browse files

Added post data sanitising before passing to the external service.

Added user's capability check.
Few plugin API logic optimizing.
Added http curl setting script.
Added proper exception naming.

https://transfer.hft-stuttgart.de/gitlab/ulrike.pado/asyst-moodle-plugin/-/issues/4
parent efffd1a4
...@@ -96,14 +96,13 @@ function validate_data($data): array { ...@@ -96,14 +96,13 @@ function validate_data($data): array {
/** /**
* Retries an API request a specified number of times. * Retries an API request a specified number of times.
* *
* @param object $apiclient The API client to use for the request. * @param client $apiclient The API client to use for the request.
* @param array $payload The data to send in the request. * @param array $payload The data to send in the request.
* @param int $maxretries The maximum number of retry attempts. * @param int $maxretries The maximum number of retry attempts.
* @return mixed The response from the API client. * @return string|bool The response from the API client.
* @throws moodle_exception If the API request fails after the maximum retries. * @throws moodle_exception If the API request fails after the maximum retries.
*/ */
function retry_api_request($apiclient, $payload, $maxretries = 3): mixed function retry_api_request(client $apiclient, array $payload, int $maxretries = 3): string|bool {
{
for ($attempts = 0; $attempts < $maxretries; $attempts++) { for ($attempts = 0; $attempts < $maxretries; $attempts++) {
try { try {
return $apiclient->send_data(validate_data($payload)); return $apiclient->send_data(validate_data($payload));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment