dbp/relay-cabinet-connector-campusonline-bundle
Install the Bundle Add the bundle to your Laravel project via Composer:
composer require dbp/relay-cabinet-connector-campusonline-bundle
Register it in config/app.php under providers:
DigitalBlueprint\RelayCabinetConnectorCampusonlineBundle\RelayCabinetConnectorCampusonlineBundle::class,
Publish Configuration Publish the bundle’s config file to customize API endpoints, credentials, and caching:
php artisan vendor:publish --provider="DigitalBlueprint\RelayCabinetConnectorCampusonlineBundle\RelayCabinetConnectorCampusonlineBundle" --tag="config"
Edit config/relay_cabinet_connector_campusonline.php to match your CAMPUSonline API credentials and endpoints.
First Use Case: Fetch Student Data Use the bundle’s service to fetch student data via the Relay API gateway:
use DigitalBlueprint\RelayCabinetConnectorCampusonlineBundle\Service\CampusonlineService;
$campusonlineService = app(CampusonlineService::class);
$student = $campusonlineService->getStudentById('12345');
The service abstracts API calls, handles authentication, and returns structured data (e.g., Student, Study, Application entities).
docs/README.md for API endpoints, response schemas, and authentication flow.src/Service/CampusonlineService.php to understand available methods (e.g., getStudentById(), fetchApplications()).config/relay_cabinet_connector_campusonline.php for API base URLs, rate limits, and caching settings.src/Event/ for custom events (e.g., StudentFetchedEvent) to extend functionality.Trigger Sync via Relay Use the Relay API gateway to initiate a sync request:
$relay = app(\DigitalBlueprint\RelayCabinetBundle\Service\RelayService::class);
$relay->syncConnector('campusonline', ['student_id' => '12345']);
This delegates to the bundle’s connector logic.
Handle API Responses The bundle processes raw CAMPUSonline API responses into Laravel-friendly entities:
$student = $campusonlineService->getStudentById('12345');
// Returns an instance of \DigitalBlueprint\RelayCabinetConnectorCampusonlineBundle\Entity\Student
Cache Responses Leverage the built-in caching layer (default: Symfony Cache) to avoid redundant API calls:
$campusonlineService->setCacheTTL(3600); // Cache for 1 hour
Entity Mapping
Customize entity mappings in config/relay_cabinet_connector_campusonline.php to align with your Laravel models:
'entity_mappings' => [
'student' => \App\Models\Student::class,
'study' => \App\Models\Study::class,
],
Event-Driven Extensions Listen to bundle events to react to API responses or sync failures:
// In a service provider
$this->app->booted(function () {
event(new \DigitalBlueprint\RelayCabinetConnectorCampusonlineBundle\Event\StudentFetchedEvent($student));
});
Rate Limiting Configure rate limits in the config to comply with CAMPUSonline API policies:
'api' => [
'rate_limit' => 60, // Requests per minute
],
Testing
Use the bundle’s test utilities (e.g., CampusonlineServiceTest) as a foundation for your tests:
$this->mock(CampusonlineService::class)
->shouldReceive('getStudentById')
->once()
->andReturn($mockStudent);
Authentication Failures
'auth' => [
'client_id' => env('CAMPUSONLINE_CLIENT_ID'),
'client_secret' => env('CAMPUSONLINE_CLIENT_SECRET'),
'token_url' => env('CAMPUSONLINE_TOKEN_URL'),
],
'debug' => env('APP_DEBUG', false),
Schema Mismatches
src/Hydrator/ or extend the base CampusonlineHydrator.Caching Stale Data
$campusonlineService->invalidateCache('student:12345');
Relay Dependency
dbp/relay-cabinet-bundle is installed and configured.Enable API Logging Add this to your config to log raw API requests/responses:
'logging' => [
'enabled' => true,
'path' => storage_path('logs/campusonline_api.log'),
],
Mock the API for Local Development
Use the CampusonlineApiClient interface to mock responses:
$this->partialMock(CampusonlineApiClient::class, function ($mock) {
$mock->shouldReceive('getStudentById')
->andReturn(['id' => '12345', 'name' => 'Test Student']);
});
Check HTTP Status Codes
The bundle throws CampusonlineApiException for non-2xx responses. Catch and handle:
try {
$student = $campusonlineService->getStudentById('12345');
} catch (\DigitalBlueprint\RelayCabinetConnectorCampusonlineBundle\Exception\CampusonlineApiException $e) {
Log::error('CAMPUSonline API error: ' . $e->getMessage());
}
Custom API Endpoints
Extend the CampusonlineApiClient to support unsupported endpoints:
// In a service provider
$this->app->extend(CampusonlineApiClient::class, function ($client, $app) {
$client->addEndpoint('custom', '/api/custom');
return $client;
});
Add New Entity Types Create a new hydrator and update the config:
// config/relay_cabinet_connector_campusonline.php
'entity_mappings' => [
'custom_entity' => \App\Models\CustomEntity::class,
],
Modify Sync Logic
Override the SyncConnector class to customize sync behavior:
// app/Providers/CampusonlineConnectorServiceProvider.php
$this->app->bind(SyncConnector::class, function ($app) {
return new CustomSyncConnector(
$app->make(CampusonlineService::class),
$app->make(RelayService::class)
);
});
Add Webhooks
Implement a WebhookListener to process CAMPUSonline webhook events:
use DigitalBlueprint\RelayCabinetConnectorCampusonlineBundle\Event\WebhookReceivedEvent;
event(new WebhookReceivedEvent($payload));
How can I help you explore Laravel packages today?