69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\CMMS;
|
|
|
|
use Exception;
|
|
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)
|
|
->throw()
|
|
->withoutVerifying()
|
|
->post($this->url)
|
|
->json();
|
|
}
|
|
|
|
private function makeInputParameters(): string
|
|
{
|
|
$inputData = array(
|
|
"username" => $this->username,
|
|
"password" => $this->password,
|
|
"day" => today(),
|
|
"minMileage" => 10,
|
|
);
|
|
|
|
return json_encode($inputData);
|
|
}
|
|
}
|