Add description support
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 11 Apr 2015 09:16:32 +0000 (12:16 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 11 Apr 2015 09:16:32 +0000 (12:16 +0300)
lib/WebService/Strike/Torrent.pm
t/WebService-Strike.t

index 4268d793ec062f1d349c601d26464f43dbe71f11..517020850a82aa33b2d098ddf4466573ac2ae7e4 100644 (file)
@@ -9,6 +9,7 @@ our $VERSION = '0.003';
 
 use Date::Parse qw/str2time/;
 use JSON::MaybeXS qw/decode_json/;
+use MIME::Base64;
 use WebService::Strike;
 
 __PACKAGE__->mk_ro_accessors(qw/torrent_hash torrent_title torrent_category sub_category seeds leeches file_count size upload_date uploader_username file_info file_names file_lengths magnet_uri/);
@@ -55,6 +56,16 @@ sub torrent{
        }
 }
 
+sub description{
+       my ($self) = @_;
+       return $self->{description} if $self->{description};
+       my $url = $WebService::Strike::BASE_URL . '/descriptions/?hash=' . $self->hash;
+       my $ht = WebService::Strike::_ht(); ## no critic (ProtectPrivate)
+       my $response = $ht->get($url);
+       return unless $response->{success};
+       $self->{description} = decode_base64 $response->{content}
+}
+
 1;
 __END__
 
@@ -83,6 +94,7 @@ WebService::Strike::Torrent - Class representing information about a torrent
   say $t->magnet;           # magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch%20Linux%202015.01.01%20%28x86%2Fx64%29
   my $tor = $t->torrent;    # $torrent contains the torrent file contents
   $t->torrent('x.torrent'); # Download torrent file to x.torrent
+  say $t->description;      # <HTML fragment describing Arch Linux>
 
 =head1 DESCRIPTION
 
@@ -153,6 +165,11 @@ I<$filename>.
 
 Both forms return a true value for success and false for failure.
 
+=item B<description>
+
+The description of the torrent. This method sends an extra request to
+Strike. Successful responses are cached.
+
 =back
 
 =head1 SEE ALSO
index 7713555614d44afcd20e1aa777f9a2d6c55a90a1..7b7a98441de49a091433b2965d8cea71ef9a5e83 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 
 use Data::Dumper qw/Dumper/;
 use Test::RequiresInternet qw/getstrike.net 443/;
-use Test::More tests => 9;
+use Test::More tests => 10;
 use Try::Tiny;
 BEGIN { use_ok('WebService::Strike') };
 
@@ -25,6 +25,7 @@ subtest 'order' => sub {
 is $t1->date, 1420502400, 'date';
 is $t2->title, 'FreeBSD 7.1 i386.DVD.iso', 'title';
 like $t1->torrent, qr/^d/, 'torrent file starts with d';
+like $t1->description, qr#GNU/Linux#, 'description contains GNU/Linux';
 
 try {
        strike 'aaa';
This page took 0.012905 seconds and 4 git commands to generate.