Browse files

added response method; add links to newer geocoders

  • Loading branch information...
1 parent 745463f commit aeadb55c5c9ce3bb55c8fadfa9255b447deba460 @gray committed Jul 5, 2010
Showing with 25 additions and 12 deletions.
  1. +3 −0 Changes
  2. +19 −10 lib/Geo/Coder/Mapquest.pm
  3. +1 −1 t/01_new.t
  4. +2 −1 xt/live.t
View
3 Changes
@@ -1,5 +1,8 @@
Revision history for Geo-Coder-Mapquest
+0.05
+ - Added response method.
+
0.04 Wed Jun 16 21:07:08 UTC 2010
- Added https option.
- Added batch method.
View
29 lib/Geo/Coder/Mapquest.pm
@@ -43,6 +43,8 @@ sub new {
return $self;
}
+sub response { $_[0]->{response} }
+
sub ua {
my ($self, $ua) = @_;
if ($ua) {
@@ -70,7 +72,7 @@ sub geocode {
$country ? (adminArea1 => $country) : (),
);
- my $res = $self->ua->get($uri);
+ my $res = $self->{response} = $self->ua->get($uri);
return unless $res->is_success;
# Change the content type of the response from 'application/json' so
@@ -80,16 +82,16 @@ sub geocode {
my $data = eval { from_json($res->decoded_content) };
return unless $data;
- my @locations = @{ $data->{results}[0]{locations} || [] };
- if (@locations) {
- $#locations = 0 unless wantarray;
+ my @results = @{ $data->{results}[0]{locations} || [] };
+ if (@results) {
+ $#results = 0 unless wantarray;
# Keep the location data structure flat.
my $provided = $data->{results}[0]{providedLocation}{location};
- $_->{providedLocation} = $provided for @locations;
+ $_->{providedLocation} = $provided for @results;
}
- return wantarray ? @locations : $locations[0];
+ return wantarray ? @results : $results[0];
}
sub batch {
@@ -109,7 +111,7 @@ sub batch {
location => $locations,
);
- my $res = $self->ua->get($uri);
+ my $res = $self->{response} = $self->ua->get($uri);
return unless $res->is_success;
# Change the content type of the response from 'application/json' so
@@ -178,7 +180,7 @@ object.
@locations = $geocoder->geocode(location => $location)
In scalar context, this method returns the first location result; and in
-list context it returns all locations results.
+list context it returns all location results.
Each location result is a hashref; a typical example looks like:
@@ -213,6 +215,12 @@ Allows up to 100 locations to be geocoded in the same request. Returns
a list of results, each of which is a reference to a list of locations.
Will croak if more than 100 locations are given.
+=head2 response
+
+ $response = $geocoder->response()
+
+Returns an L<HTTP::Response> object for the last submitted request. Can be
+used to determine the details of an error.
=head2 ua
@@ -240,8 +248,9 @@ service at this time.
L<http://www.mapquestapi.com/geocoding/>
-L<Geo::Coder::Bing>, L<Geo::Coder::Google>, L<Geo::Coder::Multimap>,
-L<Geo::Coder::Yahoo>
+L<Geo::Coder::Bing>, L<Geo::Coder::Bing::Bulk>, L<Geo::Coder::Google>,
+L<Geo::Coder::Multimap>, L<Geo::Coder::Navteq>, L<Geo::Coder::OSM>,
+L<Geo::Coder::TomTom>, L<Geo::Coder::Yahoo>
=head1 REQUESTS AND BUGS
View
2 t/01_new.t
@@ -26,4 +26,4 @@ new_ok('Geo::Coder::Mapquest' => [apikey => 'Your API key', debug => 1]);
like($@, qr/^'https' requires/, 'https fails w/o an SSL module');
}
-can_ok('Geo::Coder::Mapquest', qw(geocode batch ua));
+can_ok('Geo::Coder::Mapquest', qw(geocode batch response ua));
View
3 xt/live.t
@@ -2,6 +2,7 @@ use strict;
use warnings;
use Encode qw(decode encode);
use Geo::Coder::Mapquest;
+use LWP::UserAgent;
use Test::More;
unless ($ENV{MAPQUEST_APIKEY}) {
@@ -16,7 +17,7 @@ unless ($debug) {
diag "Set GEO_CODER_MAPQUEST_DEBUG to see request/response data";
}
-my $has_ssl = eval { require Net::HTTPS; 1 };
+my $has_ssl = LWP::UserAgent->is_protocol_supported('https');
my $geocoder = Geo::Coder::Mapquest->new(
apikey => $ENV{MAPQUEST_APIKEY},

0 comments on commit aeadb55

Please sign in to comment.