Installation:
composer require qencode/api-client:^1.13
Verify autoloading by requiring vendor/autoload.php in your entry point.
First Use Case: Initialize the client with your API key:
$client = new \QencodeApiClient('your_api_key_here');
Basic Workflow:
$task = $client->createTask();
$task->start($profileId, 'https://example.com/video.mp4');
$status = $task->getStatus();
Key Files to Reference:
src/QencodeApiClient.php (core client logic)src/Task.php (task management methods)src/Exceptions/ (error handling)Task Lifecycle Management:
// Create and trigger a task
$task = $client->createTask();
$task->start($profileId, $sourceUrl, ['output' => 's3://bucket/output.mp4']);
// Monitor progress
while ($task->getStatus()['status'] !== 'finished') {
sleep(5);
}
Batch Processing:
$tasks = [];
foreach ($videoUrls as $url) {
$task = $client->createTask();
$task->start($profileId, $url);
$tasks[] = $task;
}
Error Handling:
try {
$task->start($profileId, $sourceUrl);
} catch (\QencodeApiClientException $e) {
\Log::error('Transcoding failed:', ['error' => $e->getMessage()]);
// Retry logic or fallback
}
Laravel Service Provider: Bind the client to the container for dependency injection:
$this->app->singleton(QencodeApiClient::class, function ($app) {
return new QencodeApiClient(config('services.qencode.key'));
});
Queue Jobs: Dispatch long-running tasks to Laravel queues:
TranscodeJob::dispatch($client, $profileId, $sourceUrl, $outputPath);
Configuration:
Store API key in .env:
QENCODE_API_KEY=your_key_here
Load via config:
$client = new QencodeApiClient(config('qencode.key'));
Rate Limiting:
getStatus()).$retryAfter = $e->getRetryAfter();
sleep($retryAfter);
Task Timeouts:
if ($task->getStatus()['status'] === 'processing' && $task->getDuration() > 3600) {
$task->cancel(); // Abort if stuck
}
API Key Exposure:
config() or environment variables.Enable Verbose Logging:
$client = new QencodeApiClient($apiKey, [
'debug' => true,
'logger' => new \Monolog\Logger('qencode')
]);
Common HTTP Errors:
401 Unauthorized: Invalid API key or expired token.429 Too Many Requests: Hit rate limit. Check Retry-After header.500 Internal Server Error: Contact Qencode support with task ID.Custom Profiles:
Task to add profile validation:
class CustomTask extends \Qencode\Task {
public function start($profileId, $source, array $options = []) {
if (!in_array($profileId, config('qencode.allowed_profiles'))) {
throw new \InvalidArgumentException('Profile not allowed');
}
parent::start($profileId, $source, $options);
}
}
Webhook Integration:
Route::post('/qencode-webhook', function (Request $request) {
event(new \Qencode\Events\TaskCompleted($request->input()));
});
Mocking for Tests:
$mock = Mockery::mock(QencodeApiClient::class)->makePartial();
$mock->shouldReceive('createTask')->andReturnSelf();
$mock->shouldReceive('start')->once();
Endpoint Overrides:
https://api.qencode.com. Override in constructor:
$client = new QencodeApiClient($apiKey, ['endpoint' => 'https://custom.qencode.com']);
SSL Verification:
$client = new QencodeApiClient($apiKey, ['verify_ssl' => false]);
How can I help you explore Laravel packages today?