Official WirePusher SDK for PHP

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/wirepusher/sdk

v1.0.0-alpha.1 2025-11-17 00:01 UTC

This package is not auto-updated.

Last update: 2025-12-30 11:19:49 UTC


README

Official PHP client for WirePusher push notifications.

Installation

composer require wirepusher/sdk

Quick Start

use WirePusher\Client;

// Auto-load token from WIREPUSHER_TOKEN env var
$client = new Client();
$client->send('Deploy Complete', 'Version 1.2.3 deployed');

// Or provide token explicitly
$client = new Client(token: 'YOUR_TOKEN');
$client->send('Alert', 'Server CPU at 95%');

Features

use WirePusher\SendOptions;

// Full parameters
$options = new SendOptions(
    title: 'Deploy Complete',
    message: 'Version 1.2.3 deployed',
    type: 'deployment',
    tags: ['production', 'backend'],
    imageUrl: 'https://example.com/success.png',
    actionUrl: 'https://example.com/deploy/123',
);
$client->send($options);

// AI-powered notifications (NotifAI)
$response = $client->notifai('deployment finished, v2.1.3 is live');
echo $response->notification->title;   // AI-generated
echo $response->notification->message;

// Encrypted messages
$options = new SendOptions(
    title: 'Security Alert',
    message: 'Sensitive data',
    type: 'security',
    encryptionPassword: 'your_password',
);
$client->send($options);

Configuration

// Environment variables (recommended)
// WIREPUSHER_TOKEN - API token (required if not passed to constructor)
// WIREPUSHER_TIMEOUT - Request timeout in seconds (default: 30)
// WIREPUSHER_MAX_RETRIES - Retry attempts (default: 3)

// Or explicit configuration
$client = new Client(
    token: 'YOUR_TOKEN',
    timeout: 60.0,
    maxRetries: 5,
);

Error Handling

use WirePusher\Client;
use WirePusher\Exceptions\AuthenticationException;
use WirePusher\Exceptions\ValidationException;
use WirePusher\Exceptions\RateLimitException;

try {
    $client = new Client();
    $client->send('Title', 'Message');
} catch (AuthenticationException $e) {
    echo "Invalid token";
} catch (ValidationException $e) {
    echo "Invalid parameters";
} catch (RateLimitException $e) {
    echo "Rate limited - auto-retry handled this";
}

Automatic retry with exponential backoff for network errors, 5xx, and 429 (rate limit).

Smart Rate Limiting

The library automatically handles rate limits with Retry-After header support:

$client = new Client();
$client->send('Alert', 'Message');

// Check rate limit status after any request
$rateLimit = $client->getLastRateLimit();
if ($rateLimit !== null) {
    echo "Remaining: {$rateLimit->remaining}/{$rateLimit->limit}";
    echo "Resets at: {$rateLimit->reset}";
}

See Advanced Documentation for detailed rate limit monitoring patterns.

Links

License

MIT