Files
backend/app/Services/CMMS/DailyMovingMachinesService.php
2025-12-28 12:35:49 +03:30

68 lines
1.7 KiB
PHP

<?php
namespace App\Services\CMMS;
use Exception;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class DailyMovingMachinesService
{
protected string $url;
protected string $username;
protected string $password;
protected string $channelName;
public function __construct()
{
$this->url = config('cmms_web_services.CHECK_ACTIVITY.url');
$this->password = config('cmms_web_services.CHECK_ACTIVITY.password');
$this->username = config('cmms_web_services.CHECK_ACTIVITY.username');
$this->channelName = 'daily_moving_machine';
}
/**
* @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)
->timeout(120)
->throw()
->withoutVerifying()
->post($this->url)
->json();
}
private function makeInputParameters(): string
{
$day = Carbon::yesterday()->toDateString();
return json_encode([
"username" => $this->username,
"password" => $this->password,
"day" => $day,
"minMileage" => 10,
]);
}
}