Code Monkey home page Code Monkey logo

perl-geo-coder-opencage's Introduction

Geo::Coder::OpenCage

This module provides a Perl interface to the OpenCage geocoding API.

Build status

Build TestsCPAN Coverage Status Mastodon Follow

Usage

For docs please see the Geo::Coder::OpenCage page on search.metacpan.org or perldoc Geo::Coder::OpenCage.

INSTALLATION

To install into your Perl environment you can use the following command:

$ cpan Geo::Coder::OpenCage

Alternatively to work on the source:

$ git clone https://github.com/opencagedata/perl-Geo-Coder-OpenCage.git
$ cd perl-Geo-Coder-OpenCage
$ cpan Dist::Zilla
$ dzil authordeps | xargs cpan
$ dzil listdeps | xargs cpan
$ GEO_CODER_OPENCAGE_API_KEY="<your key>" dzil test

COPYRIGHT AND LICENCE

Copyright OpenCage GmbH [email protected]

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16 or, at your option, any later version of Perl 5 you may have available.

Who is OpenCage GmbH?

We run a worldwide geocoding API and geosearch service based on open data. Learn more about us.

We also run Geomob, a series of regular meetups for location based service creators, where we do our best to highlight geoinnovation. If you like geo stuff, you will probably enjoy the Geomob podcast.

perl-geo-coder-opencage's People

Contributors

freyfogle avatar kaoru avatar manwar avatar mtmail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mtmail tadzik manwar

perl-geo-coder-opencage's Issues

CPAN Install unable to run POD example - 401 error

Using the code in Synopsis of Geo::Coder::OpenCage with API key all works ok.

Using the code in Synopsis of Geo::Coder::Many::OpenCage with same API ( had to remove brackets from new as expects even list not hashref )

Can't locate object method "response" via package "Geo::Coder::OpenCage" ..perl/5.20.2/Geo/Coder/Many/OpenCage.pm line 95.

Modules installed from CPAN and running on debian/jessie.

add support for LWP user agents

Geo::Coder::OpenCage allows to set a user agent (ua parameter) which defaults to HTTP::Tiny. Documentation says "Useful if for example you want to specify that something like LWP::UserAgent::Throttled for rate limiting."

Later in code logic

my $response = $self->{ua}->get($URL);`
...
$response->{reason}
...
$response->{content}

That fits the HTTP::Tiny interface.

But the more common LWP user agents as well, e.g. LWP::Simple or LWP::UserAgent::Throttled return a HTTP::Response instance with status_line and decoded_content data accessors.

Suggestion for your FIXME

# FIXME - must be a way to get this from dist.ini?
my $version = 0.34;
my $ua_string;

You could just do:

my $version = our $VERSION;

Because our $VERSION is set by DistZilla. However it's only set in the released version of the module, not the version which sits in your repository. So it means people wouldn't be able to run the version of your module straight from Github.

You shouldn't use `ref($thing) eq 'HTTP::Response'`

my $content = (ref($response) eq 'HTTP::Response')

You're checking that $response is exactly a member of the HTTP::Response class, which prevents people from using user-agents that return a subclass of HTTP::Response.

Better would be:

    my $content = ( blessed $response and $response->isa('HTTP::Response') )
                    ? $response->decoded_content()
                    : $response->{content};

You'd need to import use Scalar::Util 'blessed'; at the top to get the blessed keyword though.

Debug left in

I suspect you mean't not to include this in the release version :-)

in new():

print Dumper $ua;

Don't use "say" feature in test suite

Currently t/02-geocode.t fails with perl 5.8.x:

Can't locate feature.pm in @INC (@INC contains: ... .) at t/02-geocode.t line 4.
BEGIN failed--compilation aborted at t/02-geocode.t line 4.
t/02-geocode.t .......... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 

Probably it would pass again if say was replaced with a normal print, and the use feature line removed.

Useless `if (!$response)`

Except in the case of some very serious bug in HTTP::Tiny or LWP::UserAgent, the get method will always return a true result, so this if (!$response) { ... } block will never, ever get run. Ever. At all.

That said, if it ever did run, you'd get further issues because you're accessing $response->{reason}; you're assuming $response is a hashref. But hashrefs are always true. Not false.

You can honestly just get rid of that entire if block though because the condition will never be true.

Sort URL parameters

In logfiles I see

https://api.opencagedata.com/geocode/v1/json/?key=52[...]0f&limit=1&language=en&no_annotations=1&q=52.358460%2C4.881337
https://api.opencagedata.com/geocode/v1/json/?key=52[...]0f&no_annotations=1&q=55.969170%2C12.542300&limit=1&language=en

The slash after json should be removed. The parameters should be sorted for better cache-ability (at least those who cache by URL).

Correct API URL

Hey MTM,

Geo::Coder::OpenCage currently points at http://prototype.opencagedata.com/geocode/v1/json/ but I think that should be changed?

https://github.com/lokku/perl-Geo-Coder-OpenCage/blob/master/lib/Geo/Coder/OpenCage.pm#L23

Ed said:

[09:25:33] Ed: if you don't mind pls do ASAP as at 13:00 I have call with the python guy
[09:25:42] Ed: and will tell him to basically copy the perl module

If you let me know what URL it should be I'll fix it and ship a 0.02 to CPAN.

Thanks,

Alex

Missing prerequisite IO::Socket::SSL?

Some of my smoker systems fail two test files like this:

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "IO::Socket::SSL 1.42...") at lib/Geo/Coder/OpenCage.pm line 86.
t/04-402-response.t ..... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "IO::Socket::SSL 1.42...") at lib/Geo/Coder/OpenCage.pm line 86.
t/05-403-response.t ..... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 

After installing IO::Socket::SSL the test suite pass. So probably IO::Socket::SSL should be declared as a prerequisite. And maybe diagnostics should be better if this test fails.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.