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
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user