Bump version and update Changes
[webservice-strike.git] / lib / WebService / Strike.pm
CommitLineData
27da1d36
MG
1package WebService::Strike;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7
8our @EXPORT = qw/strike/; ## no critic (ProhibitAutomaticExportation)
9our @EXPORT_OK = qw/strike_query strike/;
57a92368 10our $VERSION = '0.001002';
27da1d36
MG
11our $BASE_URL = 'http://getstrike.net/api/torrents/';
12
13use JSON::MaybeXS qw/decode_json/;
14use HTTP::Tiny;
15use Sort::ByExample qw/sbe/;
16use WebService::Strike::Torrent;
17
18sub _ht { HTTP::Tiny->new(agent => "WebService-Strike/$VERSION") }
19
20sub strike_query {
21 my (@hashes) = @_;
22 my $url = "$BASE_URL/info/?hashes=" . join ',', map { uc } @hashes;
23 my $ht = _ht;
24 my $response = $ht->get($url);
25 die $response unless $response->{success}; ## no critic (RequireCarping)
26 $response = decode_json $response->{content};
27
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]
33}
34
35BEGIN { *strike = \&strike_query }
36
371;
38__END__
39
40=encoding utf-8
41
42=head1 NAME
43
44WebService::Strike - Get torrent info from getstrike.net API
45
46=head1 SYNOPSIS
47
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'
54
55=head1 DESCRIPTION
56
57Strike API is a service for getting information about a torrent given
58its info hash. WebService::Strike is a wrapper for this service.
59
60=over
61
62=item B<strike>(I<@info_hashes>)
63
64Returns a list of hashrefs, one for each info hash. The hashrefs are
65blessed into the L<WebService::Strike::Torrent> package. Dies in case
66of error.
67
68=item B<strike_query>
69
70Alias for B<strike>. Not exported by default.
71
72=back
73
74=head1 SEE ALSO
75
76L<WebService::Strike::Torrent>, L<http://getstrike.net/api/>, L<WWW::Search::Torrentz>
77
78=head1 AUTHOR
79
80Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
81
82=head1 COPYRIGHT AND LICENSE
83
84Copyright (C) 2015 by Marius Gavrilescu
85
86This library is free software; you can redistribute it and/or modify
87it under the same terms as Perl itself, either Perl version 5.20.2 or,
88at your option, any later version of Perl 5 you may have available.
89
90
91=cut
This page took 0.015311 seconds and 4 git commands to generate.