briandfoy/geo-geonames — pull request #1 by initself (2012-07-17 01:08:05+00:00)
Title: no username fixes

brian d foy, I got your alert that the API for GeoCodes had changed and I went ahead and installed it. Needless to say, my code didn't do well trying to use the new module without passing a username. I added a test to prove that the module croaks properly:

dies_ok( sub { my $bad_geo = Geo::GeoNames->new() }, 'no username passed' );

More importantly, I added a subtest called 'valid username' which tests

subtest 'valid_username' => sub {
my $browser = LWP::UserAgent->new;
$browser->env_proxy();
my $request = $geo->url . '/' . 'postalCodeCountryInfo?username=' . $geo->username;
my $response = $browser->get($request);
my $result = $geo->_parse_xml_result($response->content);
ok(! defined $result->[0]->{status}, 'valid_username');
};

to make sure the module doesn't go crazy when given a bad username. _parse_xml_result was missing keys in

foreach my $attribute (keys %{$list}) {

It also died a miserable death here:

next if !defined($list->{$attribute}->[0]);

if there was a status message printing because of username issues. I added:

if ($element eq 'status') {
carp "ERROR: " . $xml->{$element}->[0]->{message};
$result[$i]->{$element} = $xml->{$element}->[0];
}
else {

I hope it is ok that the status message now returns parsed xml. It didn't before. Seems ok.

I'd be up for maintaining this code, since I use it in an iOS app API I wrote and it's caused me issues in the past when the API changes, so I'd be on top of it for my own personal reasons.

I've never used git or github before so please forgive me if I'm doing it wrong.

Thanks,

mb