Exemplo n.º 1
0
 public function testShouldReturnTokenConfigIfSuccessAuth()
 {
     $authConfig = new AuthConfig('username', 'password');
     $response = $this->getMock('GuzzleHttp\\Message\\ResponseInterface');
     $response->expects($this->once())->method('json')->willReturn(array("token" => "some_token"));
     $this->client->expects($this->once())->method('post')->with($authConfig->getBaseUrl() . '/auth', array('body' => array('username' => 'username', 'password' => 'password')))->willReturn($response);
     $tokenConfig = $this->authentication->auth($authConfig);
     $this->assertInstanceOf('Rosello\\T411\\Config\\TokenConfig', $tokenConfig);
     $this->assertSame('some_token', $tokenConfig->getToken());
 }
Exemplo n.º 2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Rosello\T411\Authentication\Authentication;
use Rosello\T411\Config\AuthConfig;
use Rosello\T411\Downloader\TorrentDownloader;
use Rosello\T411\Repository\TorrentRepository;
//Create auth config object
$authConfig = new AuthConfig('username', 'password');
//Ask token
$authentication = new Authentication();
$tokenConfig = $authentication->auth($authConfig);
//Search torrents
$limit = 10;
$repository = new TorrentRepository($tokenConfig, $limit);
$torrents = $repository->search('Ubuntu');
//Download first torrent
$downloader = new TorrentDownloader($tokenConfig);
$file = $downloader->download($torrents[0]);