Files
ladill-hosting/app/Services/EmailDomain/EmailDomainClient.php
T
isaaccladandCursor e251a4cf60
Deploy Ladill Hosting / deploy (push) Failing after 17s
Initial Ladill Hosting app with Gitea deploy pipeline.
Shared web hosting extracted from the platform monolith, with CI deploy
to /var/www/ladill-hosting matching Bird/Domains/Email.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 16:24:20 +00:00

78 lines
2.4 KiB
PHP

<?php
namespace App\Services\EmailDomain;
use Illuminate\Support\Facades\Http;
/**
* Client for the shared Email-Domain service (§4-D) — one verification engine
* (SPF/DKIM/DMARC). The Email app consumes it to render its own in-app domain
* setup. Domains are scoped to the user (public_id) server-side. Summary:
* {id, domain, status, active, spf, dkim, dmarc}; detail adds {dns_records, …}.
*/
class EmailDomainClient
{
private function base(): string
{
return rtrim((string) config('emaildomain.api_url'), '/');
}
private function http()
{
return Http::withToken((string) (config('emaildomain.api_key') ?? ''))->acceptJson()->timeout(10);
}
/** All email domains for the user. */
public function forUser(string $publicId): array
{
return $this->data($this->http()->get($this->base(), ['user' => $publicId]));
}
/** Only verified/active domains (eligible for mailboxes). */
public function verified(string $publicId): array
{
return $this->data($this->http()->get($this->base(), ['user' => $publicId, 'status' => 'active']));
}
public function find(string $publicId, int $id): ?array
{
return collect($this->forUser($publicId))->firstWhere('id', $id) ?: null;
}
/** Full detail (incl. DNS records to publish) for one domain. */
public function show(string $publicId, int $id): array
{
return $this->data($this->http()->get($this->base().'/'.$id, ['user' => $publicId]));
}
/** Add an email domain. Returns its detail. */
public function create(string $publicId, string $domain, string $method = 'dns_record'): array
{
$res = $this->http()->post($this->base(), ['user' => $publicId, 'domain' => $domain, 'verification_method' => $method]);
$res->throw();
return (array) $res->json('data');
}
/** Run verification; returns updated detail. */
public function verify(string $publicId, int $id): array
{
$res = $this->http()->post($this->base().'/'.$id.'/verify', ['user' => $publicId]);
$res->throw();
return (array) $res->json('data');
}
public function delete(string $publicId, int $id): void
{
$this->http()->delete($this->base().'/'.$id, ['user' => $publicId])->throw();
}
private function data($res): array
{
$res->throw();
return (array) ($res->json('data') ?? $res->json());
}
}