57 lines
1.3 KiB
PHP
57 lines
1.3 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->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
|
|
{
|
|
return Http::withHeaders(['Content-Type' => 'application/json'])
|
|
->throw()
|
|
->withoutVerifying()
|
|
->post($this->url, $this->inputParameters)
|
|
->json();
|
|
}
|
|
}
|