or die "Usage: $0 <profile id>... [<clan name>...]\n";
my ($clanmatch) = map { $_ && qr/\A(?:$_)\z/i } join '|', @{$clanmatches || []};
+my @realmget = (profile => 2 => 1); # common request path for european data
sub blizget {
state $bliz = do {
- my %auth = do './.blizzard.passwd.pl' or die "no auth setup: $!\n";
+ my @authdata = do './.blizzard.passwd.pl' and not $@ || $!
+ or die "No auth setup: ", $@ || $!, "\n";
+ my %auth = @authdata;
my $bliz = LWP::Authen::OAuth2->new(%auth,
token_endpoint => 'https://eu.battle.net/oauth/token',
request_required_params => [qw( client_id client_secret grant_type )],
# prefer deprecated interface to prevent costly ladder search
my @ladderdata = map {
- blizget(legacy => profile => 2 => 1 => $_ => 'ladders')
+ blizget(legacy => @realmget => $_ => 'ladders')
} @{$profiles};
# merge relevant ladder data of all users
}
my @ladders = (
- sort_by { $_->{season} } # season
- nsort_by {
- -($_->{ladder}->[0]->{wins} + $_->{ladder}->[0]->{losses})
- } # activity desc
nsort_by { $_->{ladder}->[0]->{ladderId} } # stable order
grep {
!$clanmatch or
$memberidx{ $_->{id} } //= push(@members, $_) && $#members
for map { $_->{characters}->@* } @ladders;
+my %game;
+for my $member (map { $_->{id} } @members) {
+ my $usergames = blizget(legacy => @realmget => $member => 'matches');
+ for ($usergames->{matches}->@*) {
+ my $match = join ':', sort values %{$_};
+ $game{$match} //= $_;
+ push $game{$match}->{players}->@*, $memberidx{$member};
+ }
+}
+
say JSON->new->canonical->pretty->encode({
name => $members[0]->{clanName},
tag => $members[0]->{clanTag},
- ladders => [map {{
- league => lc $_->{ladder}->[0]->{league},
- division => $_->{ladder}->[0]->{ladderName},
- rank => $_->{ladder}->[0]->{rank},
- members => [map { $memberidx{$_->{id}} } $_->{characters}->@*],
- wins => $_->{ladder}->[0]->{wins},
- losses => $_->{ladder}->[0]->{losses},
- (season => -1) x ($_->{season} eq 'previousSeason'),
- }} @ladders],
+ ladders => [
+ map {{
+ id => $_->{ladder}->[0]->{ladderId},
+ league => lc $_->{ladder}->[0]->{league},
+ division => $_->{ladder}->[0]->{ladderName},
+ rank => $_->{ladder}->[0]->{rank},
+ members => [map { $memberidx{$_->{id}} } $_->{characters}->@*],
+ wins => $_->{ladder}->[0]->{wins},
+ losses => $_->{ladder}->[0]->{losses},
+ (season => -1) x ($_->{season} eq 'previousSeason'),
+ }}
+ sort_by { $_->{season} } # season
+ nsort_by {
+ -($_->{ladder}->[0]->{wins} + $_->{ladder}->[0]->{losses})
+ } # activity desc
+ @ladders
+ ],
members => [map {
- blizget(metadata => profile => 2 => 1 => $_->{id})
+ blizget(metadata => @realmget => $_->{id})
# lacks mmr, fav race (available in new api)
} @members],
+ matches => [nsort_by { -$_->{date} } values %game],
}) =~ s/(?: \G \d,? | \[ ) \K \s+ (?=\d|\])/ /grx; # concat arrays of single digits