X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWebService%2FStrike.pm;h=396ec48676ba61990710417fc734ec9d17032f99;hb=95b1c120488fa6a756ab596060099f85921dae73;hp=0b32f1170b3ced717e871b15c9f79f30171bae98;hpb=2c9b434d91dac852d3dd5a88a48fbf736882561d;p=webservice-strike.git diff --git a/lib/WebService/Strike.pm b/lib/WebService/Strike.pm index 0b32f11..396ec48 100644 --- a/lib/WebService/Strike.pm +++ b/lib/WebService/Strike.pm @@ -8,7 +8,7 @@ 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.002'; -our $BASE_URL = 'http://getstrike.net/api/torrents/'; +our $BASE_URL = 'http://getstrike.net/api/v2/torrents'; use JSON::MaybeXS qw/decode_json/; use HTTP::Tiny; @@ -25,8 +25,7 @@ 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 { @@ -40,7 +39,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 +72,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 +93,9 @@ error. Alias for B. Not exported by default. -=item B(I<$search_term>, [I<$full>]) +=item B(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 objects in list context or the first such object in scalar context. @@ -107,6 +106,11 @@ return undef. If I<$full> is true, B 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