Commit b9acffca authored by dockx thibault's avatar dockx thibault
Browse files

Merge branch...

Merge branch '44-integrator-rest-library-update-to-allow-easy-trigger-of-archiving-objects' into 'dev'

Resolve "[Integrator] - Rest library - update to allow easy trigger of archiving objects"

See merge request !55
1 merge request!55Resolve "[Integrator] - Rest library - update to allow easy trigger of archiving objects"
Pipeline #32429 passed with stages
in 22 seconds
Showing with 55 additions and 1 deletion
+55 -1
.directory
filelist
phpstan-baseline.neon
phpstan.neon
.idea/.gitignore
.idea/fusiondirectory-integrator.iml
.idea/modules.xml
.idea/php.xml
.idea/vcs.xml
......@@ -10,6 +10,8 @@ class WebServiceCall
*/
private $ch;
private $httpStatusCode; // Store the HTTP status code
/**
* @param string $URL
* @param string $method
......@@ -70,7 +72,12 @@ class WebServiceCall
break;
case 'post':
curl_setopt($this->ch, CURLOPT_POST, TRUE);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
// Allows a POST to be performed without DATA
if (!empty($this->data)) {
curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($this->data));
}
curl_setopt($this->ch, CURLOPT_USERAGENT, $customUserAgent);
break;
}
......@@ -198,5 +205,44 @@ class WebServiceCall
curl_close($this->ch);
return $response;
}
/**
* @return array
* @throws \Exception
*/
public function execute (): array
{
$response = curl_exec($this->ch);
// Capture the HTTP status code
$this->httpStatusCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
$this->handleCurlError($this->ch);
// Handle 204 No Content response
if ($this->httpStatusCode === 204) {
curl_close($this->ch);
return []; // Return an empty array for 204 responses
}
$decoded = json_decode($response, TRUE);
curl_close($this->ch);
if (!is_array($decoded)) {
throw new \Exception('Invalid JSON response: ' . $response);
}
return $decoded;
}
/**
* Retrieve the HTTP status code of the last request
* @return int
*/
public function getHttpStatusCode (): int
{
return $this->httpStatusCode;
}
}
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