Files
ntspi-app/app/Services/Vicon/ViconApiConfig.php
T
F4ilji 73a0a6fe9c feat(vikon): extract API URL from hardcoded to integration_credentials
- Rename ViconApiToken → ViconApiConfig with token() and apiUrl()
- Replace 9 hardcoded db-nica.ru URLs with dynamic apiUrl()
- Payload now stores both token and api_url with fallback
2026-07-10 16:47:18 +05:00

33 lines
877 B
PHP

<?php
namespace App\Services\Vicon;
use App\Containers\Dashboard\Tasks\IntegrationCredentials\GetIntegrationCredentialTask;
class ViconApiConfig
{
private const FALLBACK_API_URL = 'https://db-nica.ru/api/v1';
public function __construct(
private readonly GetIntegrationCredentialTask $getCredential,
) {}
public function token(): string
{
$credential = $this->getCredential->run('vikon_api');
if (!$credential || empty($credential->payload['token'])) {
throw new \RuntimeException('VIKON API token not configured. Add it in /dashboard/integration-credentials.');
}
return $credential->payload['token'];
}
public function apiUrl(): string
{
$credential = $this->getCredential->run('vikon_api');
return $credential->payload['api_url'] ?? self::FALLBACK_API_URL;
}
}