コード例 #1
0
 public function testGetFreeSpaceWithDir()
 {
     $this->api = $this->getMock('Martial\\Transmission\\API\\RpcClient', ['sessionGet', 'getSessionId', 'freeSpace'], [$this->httpClient, '', '']);
     $this->api->method('sessionGet')->willReturn([Session\Get::DOWNLOAD_DIR => '/a/b/c']);
     $this->client = new TransmissionClient($this->api);
     $this->api->expects($this->once())->method('freeSpace')->with(null, '/d/e/f')->willReturn(['size-bytes' => 12345]);
     $this->assertEquals(12345, $this->client->getFreeSpace('/d/e/f'));
 }
コード例 #2
0
 public function testFreeSpaceShouldThrowAnExceptionWithAnInvalidSessionId()
 {
     $requestBody = '{"method":"free-space","arguments":{"path":"/var/lib/transmission-daemon/downloads"}}';
     $invalidSessionId = uniqid();
     $this->sendRequest($requestBody, $invalidSessionId)->andThrow($this->generateCSRFException());
     try {
         $this->rpcClient->freeSpace($invalidSessionId, '/var/lib/transmission-daemon/downloads');
     } catch (CSRFException $e) {
         $this->assertSame($this->sessionId, $e->getSessionId());
     }
 }
コード例 #3
0
use Martial\Transmission\API\Argument\Torrent\Add;
use Martial\Transmission\API\Argument\Torrent\Get;
use Martial\Transmission\API\CSRFException;
use Martial\Transmission\API\RpcClient;
use Martial\Transmission\API\TorrentIdList;
use Martial\Transmission\API\TransmissionAPI;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$rpcUri = 'http://42.42.42.42:9091/transmission/rpc';
$rpcUsername = '******';
$rpcPassword = '******';
$newTorrentFile = '/tmp/debian-8.2.0-amd64-CD-1.iso.torrent';
$guzzle = new Client(['base_uri' => $rpcUri]);
$logger = new Logger('transmission');
$logger->pushHandler(new StreamHandler('php://stdout'));
$api = new RpcClient($guzzle, $rpcUsername, $rpcPassword, $logger);
/**
 * @param array $torrentList
 */
function printTorrentData(array $torrentList)
{
    foreach ($torrentList as $torrentData) {
        printf('The status of the torrent "%s" with the ID %d is "%s".', $torrentData[Get::NAME], $torrentData[Get::ID], $torrentData[Get::STATUS]);
        echo PHP_EOL;
    }
}
/**
 * @param TransmissionAPI $api
 * @param $sessionId
 * @param array $ids
 * @return array