| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::CityGrid::Search; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34687
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
WebService::CityGrid::Search - Interface to the CityGrid Search API |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
854
|
use Any::Moose; |
|
|
1
|
|
|
|
|
45564
|
|
|
|
1
|
|
|
|
|
8
|
|
|
13
|
1
|
|
|
1
|
|
1715
|
use Any::URI::Escape; |
|
|
1
|
|
|
|
|
4007
|
|
|
|
1
|
|
|
|
|
91
|
|
|
14
|
1
|
|
|
1
|
|
523
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use LWP::UserAgent; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'api_key' => ( is => 'ro', isa => 'Str', required => 1 ); |
|
18
|
|
|
|
|
|
|
has 'publisher' => ( is => 'ro', isa => 'Str', required => 1 ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use constant DEBUG => $ENV{CG_DEBUG} || 0; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $api_host = 'api2.citysearch.com'; |
|
23
|
|
|
|
|
|
|
our $api_base = "http://$api_host/search/"; |
|
24
|
|
|
|
|
|
|
our $VERSION = 0.04; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $Ua = LWP::UserAgent->new( agent => join( '_', __PACKAGE__, $VERSION ) ); |
|
27
|
|
|
|
|
|
|
our $Parser = XML::LibXML->new; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item query |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$res = $cs->query({ |
|
36
|
|
|
|
|
|
|
mode => 'locations', |
|
37
|
|
|
|
|
|
|
where => '90210', |
|
38
|
|
|
|
|
|
|
what => 'pizza%20and%20burgers', }); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Queries the web service. Dies if the http request fails, so eval it! |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub query { |
|
45
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
die "key mode missing, can be locations or events" |
|
48
|
|
|
|
|
|
|
unless ( defined $args->{mode} && ( $args->{mode} eq 'locations' ) |
|
49
|
|
|
|
|
|
|
or ( $args->{mode} eq 'events' ) ); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $url = |
|
52
|
|
|
|
|
|
|
$api_base |
|
53
|
|
|
|
|
|
|
. $args->{mode} |
|
54
|
|
|
|
|
|
|
. '?api_key=' |
|
55
|
|
|
|
|
|
|
. $self->api_key |
|
56
|
|
|
|
|
|
|
. '&publisher=' |
|
57
|
|
|
|
|
|
|
. $self->publisher . '&'; |
|
58
|
|
|
|
|
|
|
delete $args->{mode}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
for (qw( what where )) { |
|
61
|
|
|
|
|
|
|
die "missing required arg $_" unless defined $_; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
foreach my $arg ( keys %{$args} ) { |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
die "invalid key $arg" unless grep { $arg eq $_ } qw( type what tag |
|
67
|
|
|
|
|
|
|
chain event first feature where lat lon radius from to page rpp |
|
68
|
|
|
|
|
|
|
sort publisher api_key placement format callback ); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$url .= join( '=', $arg, $args->{$arg} ) . '&'; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
$url = substr( $url, 0, length($url) - 1 ); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
75
|
|
|
|
|
|
|
my $res = $ua->get($url); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
die "query for $url failed!" unless $res->is_success; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $dom = $Parser->load_xml( string => $res->decoded_content ); |
|
80
|
|
|
|
|
|
|
my @locations = $dom->documentElement->getElementsByTagName('location'); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my @results; |
|
83
|
|
|
|
|
|
|
foreach my $loc (@locations) { |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
warn("raw location: " . $loc->toString) if DEBUG; |
|
86
|
|
|
|
|
|
|
my $name = $loc->getElementsByTagName('name')->[0]->firstChild->data; |
|
87
|
|
|
|
|
|
|
my $tagline = $loc->getElementsByTagName('tagline')->[0]; |
|
88
|
|
|
|
|
|
|
my $img = $loc->getElementsByTagName('image')->[0]; |
|
89
|
|
|
|
|
|
|
my $nbh = $loc->getElementsByTagName('neighborhood')->[0]; |
|
90
|
|
|
|
|
|
|
my $sc = $loc->getElementsByTagName('samplecategories')->[0]; |
|
91
|
|
|
|
|
|
|
my %res_args = ( |
|
92
|
|
|
|
|
|
|
id => $loc->getAttribute('id'), |
|
93
|
|
|
|
|
|
|
name => $loc->getElementsByTagName('name')->[0]->firstChild->data, |
|
94
|
|
|
|
|
|
|
profile => |
|
95
|
|
|
|
|
|
|
$loc->getElementsByTagName('profile')->[0]->firstChild->data, |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if ($sc && $sc->firstChild) { |
|
100
|
|
|
|
|
|
|
$res_args{samplecategories} = $sc->firstChild->data; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if ($nbh && $nbh->firstChild) { |
|
104
|
|
|
|
|
|
|
$res_args{neighborhood} = $nbh->firstChild->data; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
if ($img) { |
|
108
|
|
|
|
|
|
|
$res_args{image} = $img->firstChild->data; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if ($tagline) { |
|
112
|
|
|
|
|
|
|
$res_args{tagline} = $tagline->firstChild->data; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
my $result = WebService::CityGrid::Search::Result->new(%res_args); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
push @results, $result; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return \@results; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item javascript_tracker |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Under construction |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub javascript_tracker { |
|
131
|
|
|
|
|
|
|
my $self = shift; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
return <
|
|
134
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|