diff options
author | miyagawa <miyagawa@65690182-5df0-0310-9871-95da5a3706e7> | 2007-10-11 21:35:39 +0000 |
---|---|---|
committer | miyagawa <miyagawa@65690182-5df0-0310-9871-95da5a3706e7> | 2007-10-11 21:35:39 +0000 |
commit | 3f92c12f4b3e24bd89b08020605ef6121660250e (patch) | |
tree | 047e91265094df65e35f3fe3606e13d331c9b0fd /lib | |
parent | Checking in changes prior to tagging of version 0.02. Changelog diff is: (diff) | |
download | webservice-google-suggest-3f92c12f4b3e24bd89b08020605ef6121660250e.tar.gz |
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
Diffstat (limited to '')
-rw-r--r-- | lib/WebService/Google/Suggest.pm | 19 |
1 files changed, 12 insertions, 7 deletions
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; |