Installation
Add the bundle to your composer.json:
composer require cekurte/insightlytaskbundle
Register the bundle in config/bundles.php:
return [
// ...
Cekurte\InsightlyTaskBundle\CekurteInsightlyTaskBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console insightly:install
Update config/packages/cekurte_insightly_task.yaml with your Insightly API credentials:
cekurte_insightly_task:
api_key: '%env(INSIGHTLY_API_KEY)%'
api_secret: '%env(INSIGHTLY_API_SECRET)%'
base_url: 'https://api.insight.ly/v3.1'
First Use Case Fetch a task by ID:
use Cekurte\InsightlyTaskBundle\Service\TaskService;
$taskService = $this->container->get('cekurte_insightly_task.task_service');
$task = $taskService->getTask(123);
Task CRUD Operations
createTask() with an array of task data.
$taskData = [
'name' => 'Follow up with client',
'due_date' => '2023-12-31',
'status' => 'Open',
];
$task = $taskService->createTask($taskData);
updateTask().
$taskService->updateTask(123, ['status' => 'Closed']);
deleteTask() with the task ID.
$taskService->deleteTask(123);
Querying Tasks
getTasks():
$tasks = $taskService->getTasks([
'filter' => ['status' => 'Open'],
'limit' => 10,
]);
Event Integration
task.created) via Symfony’s event dispatcher:
# config/services.yaml
services:
App\EventListener\InsightlyTaskListener:
tags:
- { name: kernel.event_listener, event: task.created, method: onTaskCreated }
Dependency Injection
TaskService into controllers/services:
public function __construct(private TaskService $taskService) {}
InsightlyApiException:
try {
$task = $taskService->getTask(123);
} catch (InsightlyApiException $e) {
$this->addFlash('error', $e->getMessage());
}
InsightlyTaskBundleTest trait in your PHPUnit tests to mock API responses:
use Cekurte\InsightlyTaskBundle\Tests\InsightlyTaskBundleTest;
class MyTest extends TestCase {
use InsightlyTaskBundleTest;
public function testTaskCreation() {
$this->mockApiResponse('tasks', ['id' => 123]);
$task = $this->taskService->createTask(['name' => 'Test']);
$this->assertEquals(123, $task['id']);
}
}
Authentication Issues
401 Unauthorized errors.api_key and api_secret in config/packages/cekurte_insightly_task.yaml. Ensure they match Insightly’s API credentials.APP_DEBUG=true) to log raw API responses.Deprecated API Endpoints
v3.1 of Insightly’s API. If Insightly updates their API, the bundle may break. Check the Insightly API changelog for compatibility.Missing Dependencies
guzzlehttp/guzzle (v6.x). If your project uses v7.x, conflicts may arise. Pin the version in composer.json:
"guzzlehttp/guzzle": "^6.5"
Pagination Quirks
getTasks() method may not handle pagination automatically. For large datasets, manually paginate using offset and limit:
$tasks = $taskService->getTasks(['limit' => 50, 'offset' => 0]);
Enable API Logging
Add this to config/packages/cekurte_insightly_task.yaml:
cekurte_insightly_task:
debug: true
Logs will appear in var/log/dev.log.
Insightly API Explorer Use Insightly’s API Explorer to test endpoints manually before integrating them into your code.
Custom Fields
Task entity by overriding the TaskService:
class CustomTaskService extends TaskService {
public function getCustomTasks(array $filters) {
$tasks = $this->getTasks($filters);
return array_map([$this, 'addCustomField'], $tasks);
}
private function addCustomField(array $task) {
$task['custom_field'] = $this->fetchCustomField($task['id']);
return $task;
}
}
config/services.yaml:
services:
App\Service\CustomTaskService:
decorates: 'cekurte_insightly_task.task_service'
arguments: ['@.inner']
Webhook Integration
WebhookListener:
class CustomWebhookListener extends WebhookListener {
public function onWebhookReceived(array $payload) {
if ($payload['event'] === 'task.updated') {
$this->handleTaskUpdate($payload['data']);
}
}
}
config/services.yaml:
services:
App\EventListener\CustomWebhookListener:
tags:
- { name: kernel.event_listener, event: insightly.webhook, method: onWebhookReceived }
Batch Operations
TaskService:
public function batchUpdateTasks(array $taskIds, array $updates) {
$batch = [];
foreach ($taskIds as $id) {
$batch[] = ['id' => $id, 'data' => $updates];
}
return $this->client->request('POST', '/Tasks/batch', [
'json' => ['batch' => $batch],
]);
}
How can I help you explore Laravel packages today?