]> iEval git - webservice-strike.git/blobdiff - lib/WebService/Strike.pm
Use HTTPS and include diagnostics in test
[webservice-strike.git] / lib / WebService / Strike.pm
index f11d077f8dd53c490476feaaa70c9a9452f808fc..74a8c2b30ab05bc82315d92c245944b0bcce6614 100644 (file)
@@ -7,15 +7,15 @@ use parent qw/Exporter/;
 
 our @EXPORT    = qw/strike strike_search/; ## no critic (ProhibitAutomaticExportation)
 our @EXPORT_OK = qw/strike_query strike strike_search/;
-our $VERSION = '0.001002';
-our $BASE_URL = 'http://getstrike.net/api/torrents/';
+our $VERSION = '0.003';
+our $BASE_URL = 'https://getstrike.net/api/v2/torrents';
 
 use JSON::MaybeXS qw/decode_json/;
 use HTTP::Tiny;
 use Sort::ByExample qw/sbe/;
 use WebService::Strike::Torrent;
 
-sub _ht { HTTP::Tiny->new(agent => "WebService-Strike/$VERSION") }
+sub _ht { HTTP::Tiny->new(agent => "WebService-Strike/$VERSION", verify_SSL => 1) }
 
 sub _query {
        my ($url) = @_;
@@ -25,12 +25,14 @@ sub _query {
        die $response unless $response->{success}; ## no critic (RequireCarping)
        $response = decode_json $response->{content};
 
-       die $response unless ref $response eq 'ARRAY'; ## no critic (RequireCarping)
-       map { WebService::Strike::Torrent->new($_) } @{$response->[1]};
+       map { WebService::Strike::Torrent->new($_) } @{$response->{torrents}};
 }
 
 sub strike_query {
        my (@hashes) = @_;
+       if (@hashes > 50) {
+               return strike_query (@hashes[0 .. 49]), strike_query (@hashes[50 .. $#hashes]);
+       }
        my $url = "$BASE_URL/info/?hashes=" . join ',', map { uc } @hashes;
 
        my $sorter = sbe(\@hashes, {xform => sub { $_[0]->hash }});
@@ -40,7 +42,7 @@ sub strike_query {
 
 sub strike_search {
        my ($query, $full, %args) = @_;
-       $args{q} = $query;
+       $args{phrase} = $query;
        my $url = "$BASE_URL/search/?" . HTTP::Tiny->www_form_urlencode(\%args);
 
        my @torrents = _query $url;
@@ -73,7 +75,7 @@ WebService::Strike - Get torrent info from getstrike.net API
   say 'Found ' . @debian . ' torrents matching "Debian"';
   say 'First torrent has info hash ' . $debian[0]->hash;
 
-  my $mp = strike_search 'Modern perl', 1;
+  my $mp = strike_search 'Modern perl', 1, category => 'Books';
   say 'Torrent has ' . $mp->count . ' files. They are:';
   say join ' ', @{$mp->file_names};
 
@@ -94,9 +96,9 @@ error.
 
 Alias for B<strike>. Not exported by default.
 
-=item B<strike_search>(I<$search_term>, [I<$full>])
+=item B<strike_search>(I<$phrase>, [I<$full>, [ key => value ... ]])
 
-Searches for torrents given a search term. Returns a list of
+Searches for torrents given a phrase. Returns a list of
 L<WebService::Strike::Torrent> objects in list context or the first
 such object in scalar context.
 
@@ -107,11 +109,16 @@ return undef.
 If I<$full> is true, B<strike> will be called with the info hashes of
 the found torrents, thus obtaining complete objects.
 
+You can filter the search by appending key => value pairs to the call.
+For example:
+
+  strike_search 'windows', 0, category => 'Applications', sub_category => 'Windows';
+
 =back
 
 =head1 SEE ALSO
 
-L<WebService::Strike::Torrent>, L<http://getstrike.net/api/>, L<WWW::Search::Torrentz>
+L<WebService::Strike::Torrent>, L<https://getstrike.net/api/>, L<WWW::Search::Torrentz>
 
 =head1 AUTHOR
 
This page took 0.022759 seconds and 4 git commands to generate.