Rarbg-torrentapi

Perl Module to interact with https://torrentapi.org
git clone https://git.onna.be/Rarbg-torrentapi.git
Log | Files | Refs | README | LICENSE

basic.t (1809B)


      1 use strict;
      2 use Test::More;
      3 use Test::LWP::UserAgent;
      4 
      5 BEGIN {
      6     use_ok('Rarbg::torrentapi');
      7 }
      8 
      9 can_ok( 'Rarbg::torrentapi',
     10     qw( new search list _renew_token _token_valid _make_request ) );
     11 
     12 my $test_ua = Test::LWP::UserAgent->new;
     13 $test_ua->map_response(
     14     qr{get_token},
     15     HTTP::Response->new(
     16         '200',
     17         HTTP::Status::status_message('200'),
     18         [ 'Content-Type' => 'application/json' ],
     19         '{"token":"8q1sjn0yb6"}',
     20     ),
     21 );
     22 $test_ua->map_response(
     23     qr{mode=list},
     24     HTTP::Response->new(
     25         '200', HTTP::Status::status_message('200'),
     26         [ 'Content-Type' => 'application/json' ],
     27         '{
     28             "torrent_results": [
     29                 {
     30                     "category": "Foo Cat",
     31                     "download": "magnet:?xt=ublablabla",
     32                     "filename": "myfilename.mp4"
     33                 },
     34                 {
     35                     "category": "Bar category",
     36                     "download": "magnet:?xt=urn:btih:foobarbaz",
     37                     "filename": "blahblah.mp3"
     38                 }
     39             ]
     40         }',
     41     ),
     42 );
     43 $test_ua->map_response(
     44     qr{mode=search},
     45     HTTP::Response->new(
     46         '200',
     47         HTTP::Status::status_message('200'),
     48         [ 'Content-Type' => 'application/json' ],
     49         '{ "error": "No results found", "error_code": 20 } ',
     50     ),
     51 );
     52 my $tapi = Rarbg::torrentapi->new( '_ua' => $test_ua );
     53 
     54 like( $tapi->_token, qr/\w{10}/, 'Token test' );
     55 diag( "I got token " . $tapi->_token );
     56 ok( $tapi->_token_valid, 'Token time test' );
     57 ok( $tapi->ranked == 0 );
     58 is( $tapi->_format, 'json_extended' );
     59 my $list = $tapi->list;
     60 isa_ok( $list->[0], 'Rarbg::torrentapi::Res' );
     61 my $res = $tapi->search(
     62     {
     63         search_string => 'qwerasdf'
     64     }
     65 );
     66 isa_ok( $res, 'Rarbg::torrentapi::Error' );
     67 
     68 done_testing;