<?php // Autoload the library using Composer, if you're using a framework you shouldn't need to do this!! require_once '../vendor/autoload.php'; use Ballen\Dodns\CredentialManager; use Ballen\Dodns\Dodns; use Ballen\Dodns\Entities\Domain; /** * Example of retrieving the domain specific information (Zonefile and TTL) and outputting it. */ // Storing your DigitalOcean API key in a text file - Would recommend you instead use a environmental variable by for testing this is fine! $api_user_token = file_get_contents('token.txt'); // Create a new instance of the CredentialManager class... $credentials = new CredentialManager($api_user_token); // We now create an instance of the DigitalOcean DNS client passing in our API credentials. $dns = new Dodns($credentials); // Retrieve the domain information... $domain = new Domain(); $domain->setName('mytestdomain.uk'); // Make the request to the API and get the Domain entity object $domain_details = $dns->domain($domain); // See the raw data... //var_dump($domain_details); // Or simply output the ttl value or zonefile... echo 'Domain details for: ' . $domain_details->getName() . '<br>'; echo 'Domain TTL value: ' . $domain_details->getTtl() . '</br>'; echo "Domain zonefile content:<br>"; echo '<pre>' . $domain_details->getZone_file() . '</pre>';
/** * Delete a specific record for a given domain. * @param Domain $domain The domain of which the record belongs to. * @param int $record_id The record ID of which to delete * @return boolean * @throws Exceptions\ApiActionException */ public function deleteRecord(Domain $domain, $record_id) { if ($this->api_handler->request('domains/' . $domain->id() . '/records/' . $record_id, self::DELETE)->guzzleInstance()->getStatusCode() != 204) { throw new Exceptions\ApiActionException('The domain record could not be deleted!'); } return true; }
<?php // Autoload the library using Composer, if you're using a framework you shouldn't need to do this!! require_once '../vendor/autoload.php'; use Ballen\Dodns\CredentialManager; use Ballen\Dodns\Dodns; use Ballen\Dodns\Entities\Domain; use Ballen\Dodns\Entities\Record; /** * Example of updating a DNS records 'A' name IP address */ // We now create an instance of the DigitalOcean DNS client passing in our API credentials. $dns = new Dodns(new CredentialManager(file_get_contents('token.txt'))); // Set the domain entity that the record exists against... $domain = new Domain(); $domain->setName('mytestdomain.uk'); // Provide the record ID that you wish to get the details of (if you don't know this, call the records() method first, see the 'get_all_records_for_a_domain.php' example file!) $record_id = 9013589; // You can either create an instance of the Domain entity using the record() method to instaniate a record object from the API or create a new record entity manually. $record = $dns->record($domain, $record_id); // If you've saved this data in your application then you can manually re-create the domain entity to save on API calls... //$record = new Record([ // 'id' => $record_id, // The record ID must exist as the API uses this ID to update the record! // 'type' => 'A', // 'name' => 'subdomain', // 'data' => '80.90.22.11', // 'priority' => null, // 'port' => null, // 'weight' => null, // ]); // We'll set the new IP address here...