use JSON qw( decode_json );
use List::Util qw( all );
-my $profileid = 2138280;
-my $clanmatch = 'Inno';
+my ($profileid, $clanmatch) = @ARGV; # clan host and name
+$profileid and $profileid =~ /\A\d+\z/
+ or die "Usage: $0 <profile id> [<clan name>]\n";
my $bliz = LWP::Authen::OAuth2->new(
client_id => '7f0f95ac9529474f854ee8d68a12c3e0',
my $ladders = blizget(legacy => profile => 2 => 1 => $profileid => 'ladders');
my ($ladder) = (
sort { $b->{characters}->@* <=> $a->{characters}->@* } # population desc
- grep { all { fc $_->{clanName} eq fc $clanmatch } $_->{characters}->@* } # members
+ grep {
+ !$clanmatch or
+ all { fc $_->{clanName} eq fc $clanmatch } $_->{characters}->@*
+ } # members
$ladders->{currentSeason}->@*
-);
+) or die "No matching groups found\n";
say JSON->new->canonical->pretty->encode({
league => ucfirst lc $ladder->{ladder}->[0]->{league},