The QuickDeployer SDK is a PHP library for interacting with the QuickDeployer API, enabling developers to manage projects and servers programmatically. Built with simplicity and modularity in mind, it provides a clean interface for listing, creating, updating, and deleting projects and servers, with robust error handling and testing support.
- Manage projects (list, get, create, update, delete).
- Manage servers within projects (list, get, create, update, delete, check status).
- Easy integration with PHP applications, including Laravel.
- Comprehensive unit tests using PHPUnit.
- Built with Guzzle HTTP client for reliable API communication.
- PHP ^7.4|^8.0
- Composer
- Guzzle HTTP Client (
guzzlehttp/guzzle: ^7.0) - PHPUnit (for running tests)
Install the SDK via Composer:
composer require niravsutariya/quick-deployer-sdkIf the SDK is not yet published, you can include it as a local or VCS repository in your composer.json:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/niravsutariya/php-quick-deployer-sdk.git"
}
],
"require": {
"niravsutariya/quick-deployer-sdk": "dev-main"
}
}Then run:
composer installCreate a Client instance with your API key:
use QuickDeployer\SDK\Client;
$apiKey = 'your-api-token';
$client = new Client($apiKey);Optionally, specify a custom base URI (defaults to https://staging.quickdeployer.com/api):
$client = new Client($apiKey, 'https://quickdeployer.com/api');Retrieve a list of projects:
$projects = $client->getProjects();
foreach ($projects as $project) {
echo "Project ID: {$project['id']}, Name: {$project['name']}\n";
}Fetch details for a specific project:
$projectResource = new QuickDeployer\Resources\Project($client->getClient());
$project = $projectResource->get('project-123');
echo "Project Name: {$project['name']}\n";Create a new project:
$projectResource = new QuickDeployer\Resources\Project($client->getClient());
$newProject = $projectResource->create([
'name' => 'New Project',
'description' => 'A test project'
]);
echo "Created Project ID: {$newProject['id']}\n";Update an existing project:
$projectResource = new QuickDeployer\Resources\Project($client->getClient());
$updatedProject = $projectResource->update('project-123', [
'name' => 'Updated Project'
]);
echo "Updated Project Name: {$updatedProject['name']}\n";Delete a project:
$projectResource = new QuickDeployer\Resources\Project($client->getClient());
$projectResource->delete('project-123');
echo "Project deleted successfully\n";Retrieve servers for a specific project:
$servers = $client->servers('project-123')->list();
foreach ($servers['servers'] as $server) {
echo "Server ID: {$server['id']}, Name: {$server['name']}\n";
}Fetch details for a specific server:
$server = $client->servers('project-123')->get('server-456');
echo "Server Name: {$server['name']}\n";Create a new server:
$newServer = $client->servers('project-123')->create([
'name' => 'New Server',
'type' => 'web'
]);
echo "Created Server ID: {$newServer['id']}\n";Update an existing server:
$updatedServer = $client->servers('project-123')->update('server-456', [
'name' => 'Updated Server'
]);
echo "Updated Server Name: {$updatedServer['name']}\n";Delete a server:
$client->servers('project-123')->delete('server-456');
echo "Server deleted successfully\n";Check the status of a server:
$status = $client->servers('project-123')->checkStatus('server-456');
echo "Server Status: {$status['status']}\n";All methods throw a \RuntimeException on API failures. Use try-catch blocks to handle errors:
try {
$projects = $client->getProjects();
} catch (\RuntimeException $e) {
echo "Error: {$e->getMessage()}\n";
}- API Key: Obtain your API key from the QuickDeployer dashboard.
- Base URI: Override the default
https://quickdeployer.com/apiif using a different environment (e.g., production).
The SDK includes unit tests for the Project and Server resources using PHPUnit.
- Install dependencies:
composer install- Run tests:
vendor/bin/phpunitTests are located in the tests/Resources directory (ProjectTest.php, ServerTest.php) and use Guzzle’s MockHandler to simulate API responses.
To use the SDK in a Laravel project with a domain-driven structure:
- Install the SDK as a Composer package (see Installation).
- Place the SDK in a domain module, e.g.,
app/Domains/Deployment/Vendor/QuickDeployer. - Create a service class to wrap SDK usage:
namespace App\Domains\Deployment\Services;
use QuickDeployer\SDK\Client;
class DeploymentService
{
private Client $client;
public function __construct()
{
$this->client = new Client(config('services.quickdeployer.api_key'));
}
public function getProjects(): array
{
return $this->client->getProjects();
}
}- Register the service in a Laravel service provider and configure the API key in
config/services.php.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a pull request.
Please include tests for new features and follow PSR-12 coding standards.
This SDK is licensed under the MIT License. See the LICENSE file for details.
For issues or questions, open an issue on the GitHub repository or contact [email protected].