cocochepeau/yourls-php-sdk

A PHP SDK for interacting with the YOURLS API, enabling URL shortening, expansion, and statistics retrieval.

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 1

Open Issues: 1

pkg:composer/cocochepeau/yourls-php-sdk

0.1.3 2024-08-27 10:25 UTC

This package is auto-updated.

Last update: 2025-12-29 04:00:51 UTC


README

Installation

composer require cocochepeau/yourls-php-sdk

Example Usage

// Initialize the SDK
$yourls = new \Cocochepeau\YourlsPhpSdk\YourlsSDK('http://sho.rt/yourls-api.php', 'your_username', 'your_password');

// Create a short URL
try {
    $shortUrl = $yourls->createShortUrl('http://example.com', 'custom-keyword', 'Example Title');
    echo "Short URL: $shortUrl\n";
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

// Expand a short URL
try {
    $longUrl = $yourls->expandShortUrl('custom-keyword');
    echo "Long URL: $longUrl\n";
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

// Get stats for a specific short URL
try {
    $stats = $yourls->getUrlStats('custom-keyword');
    print_r($stats);
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

// Get global stats
try {
    $dbStats = $yourls->getDbStats();
    print_r($dbStats);
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}