From 3f92c12f4b3e24bd89b08020605ef6121660250e Mon Sep 17 00:00:00 2001 From: miyagawa Date: Thu, 11 Oct 2007 21:35:39 +0000 Subject: update per Google Suggest API change git-svn-id: http://svn.bulknews.net/repos/public/WebService-Google-Suggest/trunk@2375 65690182-5df0-0310-9871-95da5a3706e7 --- lib/WebService/Google/Suggest.pm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/WebService/Google/Suggest.pm b/lib/WebService/Google/Suggest.pm index 41b5251..9b2edba 100644 --- a/lib/WebService/Google/Suggest.pm +++ b/lib/WebService/Google/Suggest.pm @@ -28,14 +28,19 @@ sub complete { $response->is_success or croak "Google doesn't respond well: ", $response->code; my $content = $response->content(); - $content =~ /^window\.google\.ac\.sendRPCDone\(frameElement, ".*?", new Array\((.*?)\), new Array\((.*?)\), new Array\(""\)\)\;$/ + $content =~ /^window\.google\.ac\.\w+\(frameElement, ".*?", new Array\((.*?)\), new Array\(""\)\)\;$/ or croak "Google returns unrecognized format: $content"; - my($queries, $results) = ($1, $2); - my @queries = map { s/^"(.*?)"$/$1/; $_ } split /, /, $queries; - my @results = map { s/^"([\d,]+) results?"$/$1/; tr/,//d; $_+0 } - split /, /, $results; - return map { +{ query => $queries[$_], - results => $results[$_] } } 0..$#queries; + my @queries = map { s/^"(.*?)"$/$1/; $_ } split /, /, $1; + shift @queries; # new Array(2, ...) + my @results; + while (my($query, $count) = splice @queries, 0, 2) { + $count =~ s/^([\d,]+) results?$/$1/; + $count =~ tr/,//d; + $count += 0; # numify + push @results, { query => $query, results => $count }; + } + + return @results; } 1; -- cgit 1.4.1