summary refs log tree commit diff
diff options
context:
space:
mode:
authormiyagawa <miyagawa@65690182-5df0-0310-9871-95da5a3706e7>2007-10-11 21:35:39 +0000
committermiyagawa <miyagawa@65690182-5df0-0310-9871-95da5a3706e7>2007-10-11 21:35:39 +0000
commit3f92c12f4b3e24bd89b08020605ef6121660250e (patch)
tree047e91265094df65e35f3fe3606e13d331c9b0fd
parentChecking in changes prior to tagging of version 0.02. Changelog diff is: (diff)
downloadwebservice-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.pm19
-rw-r--r--t/01_suggest.t3
2 files changed, 14 insertions, 8 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;
diff --git a/t/01_suggest.t b/t/01_suggest.t
index 7db220e..07dfc6a 100644
--- a/t/01_suggest.t
+++ b/t/01_suggest.t
@@ -1,5 +1,5 @@
 use strict;
-use Test::More tests => 4;
+use Test::More tests => 5;
 
 BEGIN { use_ok 'WebService::Google::Suggest' }
 
@@ -9,5 +9,6 @@ isa_ok($suggest->ua, "LWP::UserAgent", "ua() retuens LWP");
 
 my @data = $suggest->complete("google");
 is($data[0]->{query}, "google", "google completes to google");
+ok($data[0]->{results}, "google has more than 0 results");
 is_deeply( [ $suggest->complete("udfg67a") ], [ ], "empty list" );