- How do I integrate Oh Dear monitoring into a Laravel application for uptime checks?
- Use the SDK to create monitors via `OhDear::createMonitor()` with your target URL, type (e.g., HTTP), and team ID. For async processing, wrap calls in Laravel queues (e.g., `OhDearJob`) to avoid blocking requests during deployments. Example: `$ohDear->createMonitor(['url' => 'https://example.com', 'type' => 'http'])`.
- Can this SDK handle API token authentication securely in Laravel?
- Yes. Store your Oh Dear API token in Laravel’s `.env` file (e.g., `OHDEAR_API_TOKEN=your_token`) and inject it into the SDK constructor. Avoid hardcoding tokens in your application code to prevent security risks. Use Laravel’s `config/services.php` for centralized configuration if needed.
- What Laravel versions and PHP versions does this SDK support?
- The SDK requires PHP 8.1+ and is compatible with Laravel 10/11. It leverages Saloon v4, which has no major conflicts with Laravel’s ecosystem. Test thoroughly if using older Laravel versions (e.g., 9.x) due to dependency changes in newer PHP versions.
- How can I mock Oh Dear API responses for PHPUnit testing?
- Saloon supports mocking HTTP responses. Use Saloon’s `MockClient` to simulate API calls in your tests. For example, create a mock response for `GetMonitorsRequest` and assert DTO parsing. Check Saloon’s docs for advanced mocking techniques like stubbing validation errors.
- Does this SDK support asynchronous operations for Oh Dear API calls?
- Yes. Wrap SDK methods like `createMonitor()` or `updateStatusPage()` in Laravel queues (e.g., `OhDearJob`) to process them asynchronously. This is ideal for delaying maintenance windows or batch operations. Use `dispatch()` to queue jobs from controllers or commands.
- How do I handle rate limiting or API errors in production?
- The SDK throws `OhDearException` for API errors and `ValidationException` for validation failures. Implement retry logic using Saloon’s built-in retry features or Laravel’s `retry()` helper. Cache monitor lists (e.g., `Cache::remember()`) to reduce API calls and mitigate rate limits.
- Can I use this SDK to automate status page updates during Laravel deployments?
- Absolutely. Listen to Laravel’s `Deploying` event and trigger maintenance periods via `OhDear::startMaintenancePeriod($monitorId, $duration, $message)`. Example: `public function handle(Deploying $event) { OhDear::startMaintenancePeriod(1, 3600, 'Deployment in progress'); }` for a 1-hour window.
- What alternatives exist if I need more control over HTTP requests?
- If you prefer direct API control, use Guzzle HTTP client with Oh Dear’s API docs. However, this SDK abstracts complexity with typed DTOs (e.g., `Monitor`, `CheckSummary`) and Saloon’s features like request/response objects. For advanced use cases, extend the SDK or fork it to customize behavior.
- How do I register the Oh Dear SDK as a Laravel service provider?
- Bind the SDK to Laravel’s service container in `AppServiceProvider::boot()`. Example: `$app->singleton(OhDear::class, fn() => new OhDear(config('services.ohdear.token')));`. Then inject `OhDear` into controllers or services via constructor dependency injection.
- What should I do if Oh Dear’s API changes break the SDK’s DTOs?
- Monitor Oh Dear’s API updates via their changelog. If the SDK lags, fork the repository and update DTOs (e.g., `Monitor`, `CheckSummary`) to match new API responses. Test changes locally before reporting issues or submitting PRs to the official SDK.