]>
iEval git - webservice-strike.git/blob - Strike.pm
44ad562b5c9c12d030282c5c96437308433b448f
1 package WebService
::Strike
;
6 use parent qw
/Exporter/;
8 our @EXPORT = qw
/strike/; ## no critic (ProhibitAutomaticExportation)
9 our @EXPORT_OK = qw
/strike_query strike/;
10 our $VERSION = '0.001001';
11 our $BASE_URL = 'http://getstrike.net/api/torrents/';
13 use JSON
::MaybeXS qw
/decode_json/;
15 use Sort
::ByExample qw
/sbe/;
16 use WebService
::Strike
::Torrent
;
18 sub _ht
{ HTTP
::Tiny
->new(agent
=> "WebService-Strike/$VERSION") }
22 my $url = "$BASE_URL/info/?hashes=" . join ',', map { uc } @hashes;
24 my $response = $ht->get($url);
25 die $response unless $response->{success
}; ## no critic (RequireCarping)
26 $response = decode_json
$response->{content
};
28 die $response unless ref $response eq 'ARRAY'; ## no critic (RequireCarping)
29 my $sorter = sbe
(\
@hashes, {xform
=> sub { $_[0]->hash }});
30 my @torrents = map { WebService
::Strike
::Torrent
->new($_) } @
{$response->[1]};
31 @torrents = $sorter->(@torrents);
32 wantarray ?
@torrents : $torrents[0]
35 BEGIN { *strike
= \
&strike_query
}
44 WebService::Strike - Get torrent info from getstrike.net API
48 use WebService::Strike;
49 my $t = strike 'B425907E5755031BDA4A8D1B6DCCACA97DA14C04';
50 say $t->title; # Arch Linux 2015.01.01 (x86\/x64)
51 say $t->magnet; # Returns a magnet link
52 my $torrent = $t->torrent; # Returns the torrent file
53 $t->torrent('file.torrent'); # Downloads the torrent file to 'file.torrent'
57 Strike API is a service for getting information about a torrent given
58 its info hash. WebService::Strike is a wrapper for this service.
62 =item B<strike>(I<@info_hashes>)
64 Returns a list of hashrefs, one for each info hash. The hashrefs are
65 blessed into the L<WebService::Strike::Torrent> package. Dies in case
70 Alias for B<strike>. Not exported by default.
76 L<WebService::Strike::Torrent>, L<http://getstrike.net/api/>, L<WWW::Search::Torrentz>
80 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
82 =head1 COPYRIGHT AND LICENSE
84 Copyright (C) 2015 by Marius Gavrilescu
86 This library is free software; you can redistribute it and/or modify
87 it under the same terms as Perl itself, either Perl version 5.20.2 or,
88 at your option, any later version of Perl 5 you may have available.
This page took 0.054583 seconds and 3 git commands to generate.