<?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; /** * Example of deleting a domain */ // 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 we wish to delete from our account... $domain = new \Ballen\Dodns\Entities\Domain(); $domain->setName('mytestdodmain.uk'); // Now we carry out the deletion and check if it was successful... if (!$dns->deleteDomain($domain)) { echo "An error occured and the domain could not be deleted!"; } else { echo sprintf("Congratulations, the domain <strong>%s</strong> has been deleted successfully!", $domain->getName()); }
<?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; /** * Example of retrieving all domains configured on a DigitalOcean account and outputting them! */ // 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 all the domains for your account... $my_domains = $dns->domains(); // If the account does not have any domains configured we'll just send an error message now and be done with it! if (!$my_domains->count()) { echo 'You have no domains configured on your account at present!'; die; } // Using the collection object you can get the total number of configured domains.... echo 'You have a total of ' . $my_domains->count() . ' domains on your account.'; // You can use the standard 'foreach()' function to iterate over them or use the collection method like so... foreach ($my_domains->all()->toObject() as $domain) { echo sprintf("<p> - %s</p>", $domain->getName()); }
<?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; /** * Example of deleting a domain record. */ // 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 \Ballen\Dodns\Entities\Domain(); $domain->setName('mytestdomain.uk'); // Provide the record ID that you wish to delete (if you don't know this, call the records() method first, see the 'get_all_records_for_a_domain.php' example file!) $record_id = 9012666; // Now we carry out the deletion and check if it was successful... if (!$dns->deleteRecord($domain, $record_id)) { echo "An error occured and the domain record could not be deleted!"; } else { echo sprintf("Congratulations, the domain record has been deleted successfully!"); }
<?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; /** * Example of creating a new domain */ // 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'))); // Using the DomainBuilder class we#ll create a new domain object that we can then use to create the domain with... $domain = new \Ballen\Dodns\Support\DomainBuilder('mytestdomain4.com', '80.23.22.22'); // Now we carry out the creation and check if it was successful... $new_domain = $dns->createDomain($domain); if ($new_domain) { echo sprintf("Congratulations, the domain <strong>%s</strong> has been created successfully!", $new_domain->getName()); }
<?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; /** * Example of getting details of a single record. */ // 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 \Ballen\Dodns\Entities\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 now access the record details... $record = $dns->record($domain, $record_id); // Want to inspect the data? //var_dump($record); // Access the entity properties using the 'getX' methods... echo "Record type: " . $record->getType() . "<br>"; echo "Record name: " . $record->getName() . "<br>"; echo "Record data (eg. Server IP for a 'A' record): " . $record->getData() . "<br>";
<?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>';
<?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...
<?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; /** * Example of creating a new record. */ // 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 of which we are saving the new record against.... $domain = new Ballen\Dodns\Entities\Domain(); $domain->setName('mytestdomain.uk'); // Using the RecordBuilder class we create our record before saving it to the domain via. the API... $new_record = new Ballen\Dodns\Support\RecordBuilder('A', 'server2', '80.1.1.1'); // Now we carry out the creation and check if it was successful... $record = $dns->createRecord($domain, $new_record); if ($record) { echo "Congratulations, the record <strong>{$record->getName()}.{$domain->getName()}</strong> has been created successfully!"; }