Subject: | getUserNicknames assumes multiple nicknames |
Date: | Mon, 26 Apr 2010 14:27:52 -0400 |
To: | bug-REST-Google-Apps-Provisioning [...] rt.cpan.org |
From: | Ian Rifkin <ianrifkin [...] ianrifkin.com> |
The getUserNicknames fails if the person has 0 or 1 nickname. There are
probably multiple ways of handling this (including in the reading of the
XML), but one way to correct the sub is to rewrite to something like the
following:
sub getUserNicknames {
my $self = shift;
my ( $arg );
%{$arg} = @_;
map { $arg->{lc($_)} = $arg->{$_} } keys %{$arg};
foreach my $param ( qw/ username / ) {
$arg->{$param} || croak( "Missing required '$param' argument" );
}
my $url = qq(https://apps-apis.google.com/a/feeds/$self-
Show quoted text
>{'domain'}/nickname/2.0?username=$arg->{'username'});
my $result = $self->_request( 'method' => 'GET', 'url' => $url )
|| return( 0 );
my ( $ref, $nickname );
$nickname = $result->{'entry'}->{'apps:nickname'}->{'name'};
if ( $nickname ) {
$ref->{$nickname} = {
$result->{'entry'}->{'apps:login'},
$result->{'entry'}->{'apps:nickname'}
};
return( $ref );
}
else {
foreach ( keys %{$result->{'entry'}} ) {
$nickname = $1 if /^.*\/(.+)$/;
next unless $nickname;
next if $ref->{$nickname};
$ref->{$nickname} = {
%{$result->{'entry'}->{$_}->{'apps:login'}},
%{$result->{'entry'}->{$_}->{'apps:nickname'}}
};
}
}
return( $ref );
}