Api/Geonames.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Api/Cvesearch.pm ↑ Summary Api/Shodan.pm »
1 #
2 # $Id$
3 #
4 # api::geonames Brik
5 #
6 package Metabrik::Api::Geonames;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::Client::Rest);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 username => [ qw(username) ],
20 },
21 attributes_default => {
22 },
23 commands => {
24 find_nearby_place_name => [ qw(lat long) ],
25 find_nearby => [ qw(lat long) ],
26 },
27 require_modules => {
28 },
29 require_binaries => {
30 },
31 optional_binaries => {
32 },
33 need_packages => {
34 },
35 };
36 }
37  
38 #
39 # API doc:
40 #
41 # http://www.geonames.org/export/web-services.html
42 #
43  
44 sub brik_init {
45 my $self = shift;
46  
47 # Do your init here, return 0 on error.
48  
49 return $self->SUPER::brik_init;
50 }
51  
52 #
53 # curl 'http://api.geonames.org/findNearbyPlaceNameJSON?formatted=true&lat=52.22991544468422&lng=21.011717319488525&username=demo'
54 #
55 sub find_nearby_place_name {
56 my $self = shift;
57 my ($lat, $long) = @_;
58  
59 my $username = $self->username;
60 $self->brik_help_set_undef_arg('username', $username) or return;
61  
62 $self->brik_help_run_undef_arg('find_nearby_place_name', $lat)
63 or return;
64 $self->brik_help_run_undef_arg('find_nearby_place_name', $long)
65 or return;
66  
67 if ($lat !~ m{^\d+\.\d+$}) {
68 return $self->log->error("find_nearby_place_name: lat format error");
69 }
70 if ($long !~ m{^\d+\.\d+$}) {
71 return $self->log->error("find_nearby_place_name: long format error");
72 }
73  
74 my $url = 'http://api.geonames.org/findNearbyPlaceNameJSON?'.
75 #'radius=10&style=full&lang=en&formatted=true&lat='.$lat.'&lng='.$long.'&username='.$username;
76 'cities=cities1000&style=full&formatted=true&lat='.$lat.'&lng='.$long.'&username='.$username;
77  
78 my $get = $self->get($url) or return;
79  
80 return $self->content;
81 }
82  
83 sub find_nearby {
84 my $self = shift;
85 my ($lat, $long) = @_;
86  
87 my $username = $self->username;
88 $self->brik_help_set_undef_arg('username', $username) or return;
89  
90 $self->brik_help_run_undef_arg('find_nearby', $lat)
91 or return;
92 $self->brik_help_run_undef_arg('find_nearby', $long)
93 or return;
94  
95 if ($lat !~ m{^\d+\.\d+$}) {
96 return $self->log->error("find_nearby: lat format error");
97 }
98 if ($long !~ m{^\d+\.\d+$}) {
99 return $self->log->error("find_nearby: long format error");
100 }
101  
102 my $url = 'http://api.geonames.org/findNearbyJSON?'.
103 'style=full&formatted=true&lat='.$lat.'&lng='.$long.'&username='.$username;
104  
105 my $get = $self->get($url) or return;
106  
107 return $self->content;
108 }
109  
110 1;
111  
112 __END__
« Api/Cvesearch.pm ↑ Summary Api/Shodan.pm »