2026-04-01 15:50:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services\ListMonk;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
|
|
|
use Illuminate\Http\Client\PendingRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
|
|
class ListMonkService
|
|
|
|
|
{
|
|
|
|
|
protected PendingRequest $http;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->http = Http::withBasicAuth(
|
|
|
|
|
config('services.listmonk.username'),
|
|
|
|
|
config('services.listmonk.password')
|
|
|
|
|
)
|
|
|
|
|
->withHeaders(['Accept' => 'application/json'])
|
2026-04-07 16:52:18 +02:00
|
|
|
->baseUrl(config('services.listmonk.base_url'));
|
2026-04-01 15:50:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-07 16:52:18 +02:00
|
|
|
* Retrieve all Listmonk user accounts.
|
2026-04-01 15:50:21 +02:00
|
|
|
*
|
2026-04-07 16:52:18 +02:00
|
|
|
* @return array<array-key, mixed>
|
2026-04-01 15:50:21 +02:00
|
|
|
*
|
|
|
|
|
* @throws ConnectionException
|
|
|
|
|
*/
|
2026-04-07 16:52:18 +02:00
|
|
|
public function getUsers(): array
|
2026-04-01 15:50:21 +02:00
|
|
|
{
|
|
|
|
|
return $this->http
|
2026-04-07 16:52:18 +02:00
|
|
|
->get('/users')
|
|
|
|
|
->json('data') ?? [];
|
2026-04-01 15:50:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-07 16:52:18 +02:00
|
|
|
* Retrieve all mailing lists with their subscriber counts.
|
2026-04-01 15:50:21 +02:00
|
|
|
*
|
2026-04-07 16:52:18 +02:00
|
|
|
* @return array<array-key, mixed>
|
2026-04-01 15:50:21 +02:00
|
|
|
*
|
|
|
|
|
* @throws ConnectionException
|
|
|
|
|
*/
|
2026-04-07 16:52:18 +02:00
|
|
|
public function getLists(): array
|
2026-04-01 15:50:21 +02:00
|
|
|
{
|
|
|
|
|
return $this->http
|
2026-04-07 16:52:18 +02:00
|
|
|
->get('/lists', ['per_page' => 'all'])
|
|
|
|
|
->json('data.results') ?? [];
|
2026-04-01 15:50:21 +02:00
|
|
|
}
|
|
|
|
|
}
|