Skip to content

Instantly share code, notes, and snippets.

@hideo55
Last active December 14, 2015 15:09
Show Gist options
  • Save hideo55/5105481 to your computer and use it in GitHub Desktop.
Save hideo55/5105481 to your computer and use it in GitHub Desktop.
metacpan fav search
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use JSON;
use Furl;
use constant {
METACPAN_URL => 'http://api.metacpan.org',
API_FAV => '/v0/favorite/_search?q=distribution:',
API_USER => '/v0/author/_search?q=user:',
};
my $dist = $ARGV[0];
if( !defined $dist ){
print "Usage: $0 <dist name>\n";
exit 1;
}
my $furl = Furl->new();
$furl->env_proxy;
my $url_get_fav = METACPAN_URL . API_FAV . $dist . '&fields=user';
my $res = $furl->get($url_get_fav);
die if ! $res->is_success;
my $json = JSON->new->utf8;
my $fav = $json->decode($res->content);
for my $hit (@{ $fav->{hits}{hits} || [] }){
my $faved_user_id = $hit->{fields}{user};
my $res = $furl->get(API_USER . $faved_user_id);
next if ! $res->is_success;
my $user = $json->decode($res->content);
my $pause_id = $user->{hits}{hits}[0]{_source}{pauseid};
print $pause_id, "\n";
}
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment