Subject: | domain->transferlist() fails when on a single domain in result |
Date: | Sun, 12 Apr 2015 23:47:43 +1000 |
To: | bug-WWW-Namecheap-API [...] rt.cpan.org |
From: | Nick Andrew <nick [...] nick-andrew.net> |
When a single domain transfer is returned from the API, the 'Transfer' part of the
XML response contains a hashref, and if 2 or more transfers are returned then it
contains a listref.
The code at WWW/Namecheap/Domain.pm line 540 assumes a list, and so it fails:
Not an ARRAY reference at /.../WWW/Namecheap/Domain.pm line 540.
Sample contents of the $xml data structure:
$VAR1 = {
'Status' => 'OK',
'CommandResponse' => {
'TransferGetListResult' => {
'Transfer' => {
'StatusDescription' => 'Invalid response for submit order provider call',
'Status' => 'INPROGRESS',
'OrderID' => '',
'User' => 'xxxxxxxx',
'TransferDate' => '04/12/2015',
'ID' => '3119',
'DomainName' => 'test1.com',
'StatusID' => '-9',
'StatusDate' => '04/12/2015'
}
},
'Paging' => {
'TotalItems' => '1',
'PageSize' => '100',
'CurrentPage' => '1'
},
'Type' => 'namecheap.domains.transfer.getList'
},
'ExecutionTime' => '0.034',
'Server' => 'PHX01SBAPI01',
'Warnings' => {},
'GMTTimeDifference' => '--4:00',
'Errors' => {},
'xmlns' => 'http://api.namecheap.com/xml.response',
'RequestedCommand' => 'namecheap.domains.transfer.getList'
};
This is a problem I encountered many times with converting XML documents
to perl data structures; single-element lists are not detected and a
hashref of the element is returned instead of a listref containing it.
A simple workaround could be something like:
my $ref = $xml->{CommandResponse}->{TransferGetListResult};
if (ref($ref->{Transfer}) eq 'HASH') {
$ref->{Transfer} = [ $ref->{Transfer} ];
}
Nick.