https://github.com/anktx/cloud-dns-client
Cloud.ru DNS API client
https://github.com/anktx/cloud-dns-client
api client cloud dns
Last synced: 5 months ago
JSON representation
Cloud.ru DNS API client
- Host: GitHub
- URL: https://github.com/anktx/cloud-dns-client
- Owner: anktx
- Created: 2024-08-07T18:57:07.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T17:15:24.000Z (almost 2 years ago)
- Last Synced: 2024-11-29T18:17:29.227Z (over 1 year ago)
- Topics: api, client, cloud, dns
- Language: PHP
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.en.md
Awesome Lists containing this project
README
# Cloud.ru DNS API client
[](https://packagist.org/packages/anktx/cloud-dns-client)
[](https://packagist.org/packages/anktx/cloud-dns-client)
The package provides a PHP wrapper to interact with the Cloud.ru DNS API.
## Requirements
- PHP 8.2 or higher.
## Installation
```shell
composer require anktx/cloud-dns-client
```
## General usage
To interact with the [Cloud.ru DNS API](https://cloud.ru/docs/clouddns/ug/topics/api-ref.html),
you need to create an instance of the `CloudDnsApi` class. This class requires a
[PSR-18](https://www.php-fig.org/psr/psr-18/) `ClientInterface` implementation and `HttpAdapter`,
which in turn requires [PSR-17](https://www.php-fig.org/psr/psr-17/) `RequestFactoryInterface`
and `StreamFactoryInterface`.
You can use the [kriswallsmith/buzz](https://github.com/kriswallsmith/Buzz) and [nyholm/psr7](https://github.com/Nyholm/psr7) packages for this:
```shell
composer require kriswallsmith/buzz nyholm/psr7
```
Here's now you can create an instance of `CloudDnsApi`:
```php
use Anktx\Cloud\Dns\Client\Client\HttpAdapter;
use Anktx\Cloud\Dns\Client\CloudDnsApi;
use Buzz\Client\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;
// Dependencies
$psr17Factory = new Psr17Factory();
$httpAdapter = new HttpAdapter($psr17Factory, $psr17Factory);
$httpClient = new Curl($psr17Factory);
// API
$api = new CloudDnsApi(
client: $httpClient,
httpAdapter: $httpAdapter,
);
```
First, obtain an authentication token and pass it to `HttpAdapter`:
```php
$token = $api->authenticate('CLIENT_ID', 'CLIENT_SECRET');
$httpAdapter->setToken($token);
```
Now you can use the `$api` instance to interact with the Cloud.ru DNS API.
```php
// Get zones
$api->getZones('PROJECT_ID');
// Create zone
$api->createZone('New zone', 'PROJECT_ID');
```
The result will be either `FailResult` instance (on error) or an object of the corresponding type (on success). For example:
```php
// Result is a collection of `Record` objects
$records = $api->getRecords('ZONE_ID');
foreach ($records as $record) {
echo 'name: ' . $record->name . ' ttl: ' . $record->ttl . \PHP_EOL;
}
```