| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# $Id$ |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# api::geonames Brik |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
package Metabrik::Api::Geonames; |
|
7
|
1
|
|
|
1
|
|
714
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
28
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base qw(Metabrik::Client::Rest); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
601
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
|
13
|
|
|
|
|
|
|
return { |
|
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
|
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
|
16
|
|
|
|
|
|
|
author => 'GomoR ', |
|
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
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Do your init here, return 0 on error. |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
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
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
57
|
0
|
|
|
|
|
|
my ($lat, $long) = @_; |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $username = $self->username; |
|
60
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('username', $username) or return; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('find_nearby_place_name', $lat) |
|
63
|
|
|
|
|
|
|
or return; |
|
64
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('find_nearby_place_name', $long) |
|
65
|
|
|
|
|
|
|
or return; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if ($lat !~ m{^\d+\.\d+$}) { |
|
68
|
0
|
|
|
|
|
|
return $self->log->error("find_nearby_place_name: lat format error"); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
0
|
0
|
|
|
|
|
if ($long !~ m{^\d+\.\d+$}) { |
|
71
|
0
|
|
|
|
|
|
return $self->log->error("find_nearby_place_name: long format error"); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
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
|
0
|
0
|
|
|
|
|
my $get = $self->get($url) or return; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return $self->content; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub find_nearby { |
|
84
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
85
|
0
|
|
|
|
|
|
my ($lat, $long) = @_; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $username = $self->username; |
|
88
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('username', $username) or return; |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('find_nearby', $lat) |
|
91
|
|
|
|
|
|
|
or return; |
|
92
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('find_nearby', $long) |
|
93
|
|
|
|
|
|
|
or return; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if ($lat !~ m{^\d+\.\d+$}) { |
|
96
|
0
|
|
|
|
|
|
return $self->log->error("find_nearby: lat format error"); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
0
|
0
|
|
|
|
|
if ($long !~ m{^\d+\.\d+$}) { |
|
99
|
0
|
|
|
|
|
|
return $self->log->error("find_nearby: long format error"); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $url = 'http://api.geonames.org/findNearbyJSON?'. |
|
103
|
|
|
|
|
|
|
'style=full&formatted=true&lat='.$lat.'&lng='.$long.'&username='.$username; |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
my $get = $self->get($url) or return; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $self->content; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |