Closed immauss closed 8 years ago
As you found out, there is no ->subdivision
method. The ->subdivisions
method returns an arrayref of subdivisions, not a single subdivision, which is why your ->name
call fails. A location may have more than one subdivision level. I'd suggest trying ->most_specific_subdivision
to get a single subdivision.
I looked at the documentation and I couldn't find any that mentioned a ->subdivision
method.
Gregory, Thank you for such a quick response. Yes. I'm seeing there is quite a difference between what is in the *.pm vs what maxmind has on their site for the perl module. (I was looking at their site.) I found the "->most_specific_subdivision, but always receive similar errors:
$ cat geoip-test.pl ;./geoip-test.pl
use 5.008;
use GeoIP2::WebService::Client;
my $client = GeoIP2::WebService::Client->new( user_id => MyID, license_key => '@@@@@@' );
my $insights = $client->insights( ip => '24.24.24.24' );
my $subdivision_rec = $insights->subdivisions(); print $subdivision_rec->most_specific_subdivision(), "\n"; Can't locate object method "most_specific_subdivision" via package "1" (perhaps you forgot to load "1"?) at ./geoip-test.pl line 14.
My instinct tells me I'm still doing something wrong, I just can't see it.
Thanks, Scott
Am I calling subdivisions correctly?
nl geoip-test.pl; ./geoip-test.pl
1 #!/usr/bin/perl
2 use 5.008;
3
4 use GeoIP2::WebService::Client;
5
6 my $client = GeoIP2::WebService::Client->new(
7 user_id => MyID,
8 license_key => '@@@@@@'
9 );
10
11 my $insights = $client->insights( ip => '24.24.24.24' );
12
13 my $subdivision_rec = $insights->subdivisions();
14 print $subdivision_rec,"\n";
15 print $subdivision_rec->confidence(), "\n";
1
Can't locate object method "confidence" via package "1" (perhaps you forgot to load "1"?) at ./geoip-test.pl line 15.
Shouldn't the print on line 14 output a hash reference instead of just a "1" ?
Thanks, Scott
Per the docs on MetaCPAN, most_specific_subdivision
is a method on the Insights model. You need to do something like:
my $insights = $client->insights( ip => '24.24.24.24' );
say $insights->most_specific_subdivision->name
That said, this doesn't really seem to be an issue against the API. Please direct further questions to support@maxmind.com or use the chat on our website.
Hello, I’m putting together a perl script for analyzing a client's logs. I’m able to retrieve country and city from the insights query, but when I try to get the subdivisions, it receive errors. The below code was copied from the documentation at: https://metacpan.org/pod/GeoIP2::Model::Insights#METHODS
$ cat geoip-test.pl
!/usr/bin/perl
use 5.008;
use GeoIP2::WebService::Client;
my $client = GeoIP2::WebService::Client->new( user_id => MyID, license_key => ‘@@@@@@@@@@@' );
my $insights = $client->insights( ip => '24.24.24.24' );
my $subdivision_rec = $insights->subdivision(); print $subdivision_rec->name(), "\n";
$ ./geoip-test.pl Can't locate object method "subdivision" via package "GeoIP2::Model::Insights" at ./geoip-test.pl line 13.
There are some discrepancies in the documentation in that some pages in the documentation use “subdivision” and some use “subdivisions”;
If I add the “s” I’m greeted with the following error:
cat geoip-test.pl ;./geoip-test.pl
!/usr/bin/perl
use 5.008;
use GeoIP2::WebService::Client;
my $client = GeoIP2::WebService::Client->new( user_id => MyID, license_key => ‘@@@@@@@@@@' );
my $insights = $client->insights( ip => '24.24.24.24' );
my $subdivision_rec = $insights->subdivisions(); print $subdivision_rec->name(), "\n"; Can't locate object method "name" via package "1" (perhaps you forgot to load "1"?) at ./geoip-test.pl line 14.
Thank you, Scott