2022-10-18 15:04:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Mailman\Support;
|
|
|
|
|
2022-10-18 15:21:14 +02:00
|
|
|
use Illuminate\Http\Client\PendingRequest;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
2022-10-18 15:04:47 +02:00
|
|
|
class MailmanService
|
|
|
|
{
|
2022-10-18 15:21:14 +02:00
|
|
|
private string $baseUrl;
|
|
|
|
private string $username;
|
|
|
|
private string $password;
|
|
|
|
|
2022-10-18 15:04:47 +02:00
|
|
|
public function setCredentials(string $baseUrl, string $username, string $password): self
|
|
|
|
{
|
2022-10-18 15:21:14 +02:00
|
|
|
$this->baseUrl = $baseUrl;
|
|
|
|
$this->username = $username;
|
|
|
|
$this->password = $password;
|
|
|
|
|
|
|
|
return $this;
|
2022-10-18 15:04:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function check(): bool
|
|
|
|
{
|
2022-10-18 15:21:14 +02:00
|
|
|
$response = $this->http()->get('/system/versions');
|
|
|
|
|
|
|
|
return 200 === $response->status();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function http(): PendingRequest
|
|
|
|
{
|
|
|
|
return Http::withBasicAuth($this->username, $this->password)->withOptions(['base_uri' => $this->baseUrl]);
|
2022-10-18 15:04:47 +02:00
|
|
|
}
|
|
|
|
}
|