Skip to content

Commit

Permalink
Admit object as parameter in post method
Browse files Browse the repository at this point in the history
- Add object type as a possible parameter for post method
  • Loading branch information
Lucas Montoya authored and Jacobomara901 committed Dec 17, 2024
1 parent 034c9a2 commit 3927f92
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions code/web/Drivers/KohaApiUserAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ public function get(string $endpoint, string $caller, array $dataToSanitize = []
* Recover specific data of it as properties.
*
* @param string $endpoint e.g "/api/v1/auth/password/validation"
* @param array $requestParameters e.g ['identifier' => $username,'password' => $password,]
* @param array|object $requestParameters e.g ['identifier' => $username,'password' => $password,]
* @param string $caller e.g "koha.PatronLogin"
* @param array $dataToSanitize e.g ['password' => $password]
* @param array|null $extraHeaders e.g ['x-koha-embed: +strings,extended_attributes']
*
* @return array|bool An array containing the response body and response code retrieved by the request or false if authorization fails.
* @access public
*/
public function post(string $endpoint, array $requestParameters, string $caller, array $dataToSanitize = [], array $extraHeaders = null): array|bool {
public function post(string $endpoint, array|object $requestParameters, string $caller, array $dataToSanitize = [], array $extraHeaders = null): array|bool {
// Preparing request
$apiURL = $this->baseURL . $endpoint;
$jsonEncodedParams = json_encode($requestParameters);

if ($this->getAuthorizationHeader($caller)) {
$this->apiCurlWrapper->addCustomHeaders([
$this->getAuthorizationHeader($caller)
Expand All @@ -106,6 +106,7 @@ public function post(string $endpoint, array $requestParameters, string $caller,
$response = $this->apiCurlWrapper->curlSendPage($apiURL, 'POST', $jsonEncodedParams);
$responseCode = $this->apiCurlWrapper->getResponseCode();
$jsonResponse = $this->jsonValidate($response);

ExternalRequestLogEntry::logRequest($caller, 'POST', $apiURL, $this->apiCurlWrapper->getHeaders(), $jsonEncodedParams, $responseCode, $response, $dataToSanitize);
return [
'content' => $jsonResponse,
Expand Down

0 comments on commit 3927f92

Please sign in to comment.