PHP code example of anktx / cloud-dns-client

1. Go to this page and download the library: Download anktx/cloud-dns-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anktx / cloud-dns-client example snippets


use Anktx\Cloud\Dns\Client\Client\HttpAdapter;
use Anktx\Cloud\Dns\Client\CloudDnsApi;
use Buzz\Client\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;

// Зависимости
$psr17Factory = new Psr17Factory();
$httpAdapter = new HttpAdapter($psr17Factory, $psr17Factory);
$httpClient = new Curl($psr17Factory);

// API
$api = new CloudDnsApi(
    client: $httpClient,
    httpAdapter: $httpAdapter,
);

$token = $api->authenticate('CLIENT_ID', 'CLIENT_SECRET');
$httpAdapter->setToken($token);

// Получение зон
$api->getZones('PROJECT_ID');

// Создание зоны
$api->createZone('New zone', 'PROJECT_ID');

// Результат - коллекция объектов `Record`
$records = $api->getRecords('ZONE_ID');

foreach ($records as $record) {
    echo 'name: ' . $record->name . ' ttl: ' . $record->ttl . \PHP_EOL;
}