Changeset 2375

Show
Ignore:
Timestamp:
10/12/07 06:35:39
Author:
miyagawa
Message:

update per Google Suggest API change

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WebService-Google-Suggest/trunk/lib/WebService/Google/Suggest.pm

    r2320 r2375  
    2929 
    3030    my $content = $response->content(); 
    31     $content =~ /^window\.google\.ac\.sendRPCDone\(frameElement, ".*?", new Array\((.*?)\), new Array\((.*?)\), new Array\(""\)\)\;$/ 
     31    $content =~ /^window\.google\.ac\.\w+\(frameElement, ".*?", new Array\((.*?)\), new Array\(""\)\)\;$/ 
    3232        or croak "Google returns unrecognized format: $content"; 
    33     my($queries, $results) = ($1, $2); 
    34     my @queries = map { s/^"(.*?)"$/$1/; $_ } split /, /, $queries; 
    35     my @results = map { s/^"([\d,]+) results?"$/$1/; tr/,//d; $_+0 } 
    36         split /, /, $results; 
    37     return map { +{ query   => $queries[$_], 
    38                     results => $results[$_] } } 0..$#queries; 
     33    my @queries = map { s/^"(.*?)"$/$1/; $_ } split /, /, $1; 
     34    shift @queries; # new Array(2, ...) 
     35    my @results; 
     36    while (my($query, $count) = splice @queries, 0, 2) { 
     37        $count =~ s/^([\d,]+) results?$/$1/; 
     38        $count =~ tr/,//d; 
     39        $count += 0; # numify 
     40        push @results, { query => $query, results => $count }; 
     41    } 
     42 
     43    return @results; 
    3944} 
    4045 
  • WebService-Google-Suggest/trunk/t/01_suggest.t

    r1503 r2375  
    11use strict; 
    2 use Test::More tests => 4
     2use Test::More tests => 5
    33 
    44BEGIN { use_ok 'WebService::Google::Suggest' } 
     
    1010my @data = $suggest->complete("google"); 
    1111is($data[0]->{query}, "google", "google completes to google"); 
     12ok($data[0]->{results}, "google has more than 0 results"); 
    1213is_deeply( [ $suggest->complete("udfg67a") ], [ ], "empty list" ); 
    1314