cwd/easyname-php-sdk
PHP SDK for easyname’s REST API. Provides simple access to API endpoints using cURL and JSON. Compatible with PHP 5.3+ and intended for integrating easyname services into your applications. Further docs: https://devblog.easyname.com
composer require cwd/easyname-php-sdk
use Cwd\Easyname\Client;
$client = new Client('your_api_key', 'your_api_secret');
$result = $client->domains()->checkAvailability('example.com');
if ($result->isAvailable()) {
echo "Domain is available!";
}
Client class methods (e.g., domains(), contacts(), orders()).Cwd\Easyname\Exception for API response errors.Domain Management
$client->domains()->checkAvailability('test.com');
$client->domains()->register('test.com', [
'period' => 1, // years
'nameservers' => ['ns1.example.com', 'ns2.example.com']
]);
$domains = $client->domains()->listDomains();
Contact Management
$client->contacts()->create([
'firstName' => 'John',
'lastName' => 'Doe',
'email' => 'john@example.com'
]);
$client->domains()->setContact('test.com', $contactId);
Order Management
$client->orders()->create([
'domain' => 'test.com',
'contactId' => $contactId,
'period' => 1
]);
$client->orders()->listOrders();
$client = new Client('key', 'secret', [
'retry_after' => 5, // seconds
]);
Cwd\Easyname\Webhook to listen for domain events (e.g., renewal, expiration).
$webhook = new Webhook('webhook_secret');
$webhook->handle($_POST); // Verify and process payloads
$cacheKey = "domain_availability:test.com";
if (Cache::has($cacheKey)) {
return Cache::get($cacheKey);
}
$result = $client->domains()->checkAvailability('test.com');
Cache::put($cacheKey, $result, now()->addMinutes(5));
Deprecated PHP Version:
php-compat.API Key Permissions:
try {
$client->domains()->checkAvailability('test.com');
} catch (Cwd\Easyname\Exception\UnauthorizedException $e) {
// Log or alert: Invalid credentials
}
Nameserver Validation:
$client->domains()->register('test.com', []); // Throws ValidationException
Fix: Always include nameservers in registration payloads.
Webhook Verification:
webhook_secret. Skipping this exposes your endpoint to spoofing.$webhook->handle($_POST); // Throws InvalidSignatureException if invalid
Enable Debug Mode:
$client = new Client('key', 'secret', [
'debug' => true, // Logs raw API requests/responses
]);
Check Laravel logs (storage/logs/laravel.log) for raw API interactions.
Mocking the SDK for Tests:
Use Laravel’s Mockery to isolate API calls:
$mockClient = Mockery::mock('Cwd\Easyname\Client');
$mockClient->shouldReceive('domains->checkAvailability')
->once()
->andReturn(new Cwd\Easyname\Response\DomainAvailability(true));
Custom Response Handling:
Extend Cwd\Easyname\Response\AbstractResponse to add domain-specific logic:
class CustomDomainResponse extends AbstractResponse {
public function isPremium() {
return $this->data['is_premium'] ?? false;
}
}
Add New API Endpoints:
The SDK follows a resource-based pattern (domains(), contacts()). Add new resources by extending Cwd\Easyname\Resource\AbstractResource:
class Invoices extends AbstractResource {
public function listInvoices() {
return $this->request('GET', '/invoices');
}
}
Register it in the Client class:
public function invoices() {
return new Invoices($this);
}
Override HTTP Client: Replace the default Guzzle client for custom headers/timeout:
$client = new Client('key', 'secret', [
'http_client' => new CustomGuzzleClient([
'timeout' => 30,
'headers' => ['X-Custom-Header' => 'value']
]),
]);
How can I help you explore Laravel packages today?