A PHP client for the Transmission RPC API.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc
src
tests
.gitignore
README.md
UPGRADE-2.0.md
build.xml
composer.json
phpunit.xml

README.md

PHP client for the Debian Transmission RPC API

Build Status

Purpose

I wrote this client because of a lack of features with other PHP clients. This implementation is full, tested with PHPUnit and as close as possible from the original RPC interface.

Installation

With composer:

composer require 'martial/transmission-api:~2.0'

Usage

Instantiation

// Load composer autoloader

$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://transmission-server:9091/transmission/rpc']);
$api = new \Martial\Transmission\API\RpcClient($httpClient, 'rpc-username', 'rpc-password');

Show me what you're doing

You may want to use a logger:

$logger = new \Monolog\Logger('transmission');
$logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout'));

$api = new \Martial\Transmission\API\RpcClient($httpClient, 'rpc-username', 'rpc-password', $logger);

Session ID

You must provide a session ID as first parameter of all API methods. This ID can be retrieved by calling any of these methods with an invalid session ID, and by catching the \Martial\Transmission\API\CSRFException:

$sessionId = '';

try {
    $api->sessionGet($sessionId);
} catch (\Martial\Transmission\API\CSRFException $e) {
    // The session has been reinitialized. Fetch the new session ID with the method getSessionId().
    $sessionId = $e->getSessionId();
} catch (\Martial\Transmission\API\TransmissionException $e) {
    // The API returned an error, retrieve the reason with the method getResult().
    die('API error: ' . $e->getResult());
}

Method usage example

Then, just read the documentation of the interface \Martial\Transmission\API\TransmissionAPI. Each method is documented:

try {
    $api->torrentAdd($sessionId, [
        \Martial\Transmission\API\Argument\Torrent\Add::FILENAME => '/path/to/the/torrent/file.torrent'
    ]);
} catch (\Martial\Transmission\API\DuplicateTorrentException $e) {
    // This torrent is already in your download queue.
} catch (\Martial\Transmission\API\MissingArgumentException $e) {
    // Some required arguments are missing.
} catch (\Martial\Transmission\API\CSRFException $e) {
    // The session has been reinitialized. Fetch the new session ID with the method getSessionId().
} catch (\Martial\Transmission\API\TransmissionException $e) {
    // The API returned an error, retrieve the reason with the method getResult().
    die('API error: ' . $e->getResult());
}