Files
backend/app/Services/FMS/GetErrorRateService.php
2025-08-25 14:23:48 +03:30

72 lines
1.7 KiB
PHP

<?php
namespace App\Services\FMS;
use Exception;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class GetErrorRateService
{
protected string $url;
protected string $channelName;
protected string $password;
protected string $username;
protected array $inputParameters;
public function __construct()
{
$this->url = config('fms_web_services.Error_Rate.url');
$this->password = config('fms_web_services.Error_Rate.password');
$this->username = config('fms_web_services.Error_Rate.username');
$this->channelName = 'fms_error_rate';
}
public function setInputParameters(array $inputs): void
{
$this->inputParameters = $inputs;
}
/**
* @throws Exception
*/
public function run(): array
{
try {
return $this->sendRequest();
}
catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
public function sendRequest(): array
{
$inputData = $this->makeInputParameters();
return Http::withBody($inputData)
->throw()
->withoutVerifying()
->post($this->url)
->json();
}
private function makeInputParameters(): string
{
$inputData = $this->inputParameters + array(
"username" => $this->username,
"password" => $this->password,
"minStopDuration" => 1,
);
return json_encode($inputData);
}
}