Deploy Ladill Care / deploy (push) Successful in 38s
Schedule and start video visits via the Meet service API, persist join links on appointments, and propagate the shared copy-button component. Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Meet;
|
|
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use Illuminate\Http\Client\PendingRequest;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
/**
|
|
* Client for the Ladill Meet service API — schedule rooms linked to Care records.
|
|
*/
|
|
class MeetClient
|
|
{
|
|
public function __construct(private readonly string $ownerRef) {}
|
|
|
|
public static function for(string $ownerRef): self
|
|
{
|
|
return new self($ownerRef);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function createRoom(array $data): array
|
|
{
|
|
return $this->post('rooms', array_merge($data, [
|
|
'owner_ref' => $this->ownerRef,
|
|
'host_user_ref' => $data['host_user_ref'] ?? $this->ownerRef,
|
|
]));
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function startRoom(string $roomUuid, ?string $hostUserRef = null): array
|
|
{
|
|
return $this->post("rooms/{$roomUuid}/start", [
|
|
'host_user_ref' => $hostUserRef ?? $this->ownerRef,
|
|
]);
|
|
}
|
|
|
|
private function client(): PendingRequest
|
|
{
|
|
return Http::baseUrl((string) config('meet.url'))
|
|
->withToken((string) config('meet.key'))
|
|
->acceptJson()
|
|
->asJson()
|
|
->connectTimeout(10)
|
|
->timeout(20);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function post(string $path, array $data): array
|
|
{
|
|
try {
|
|
$response = $this->client()->post($path, $data);
|
|
} catch (ConnectionException) {
|
|
throw ValidationException::withMessages([
|
|
'meet' => ['Could not reach the Meet service. Please try again in a moment.'],
|
|
]);
|
|
}
|
|
|
|
if ($response->status() === 422) {
|
|
throw ValidationException::withMessages(
|
|
$response->json('errors') ?: ['meet' => [$response->json('message') ?: 'Request failed.']]
|
|
);
|
|
}
|
|
|
|
if ($response->failed()) {
|
|
abort($response->status() === 404 ? 404 : 502, 'Meet service error.');
|
|
}
|
|
|
|
return (array) $response->json();
|
|
}
|
|
}
|