Created
August 23, 2011 16:03
-
-
Save semifor/1165621 to your computer and use it in GitHub Desktop.
Eliminating @raw_lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # just want the user's basic info? | |
| sub trim_user { trim_hash(shift, [qw/id name screen_name/]) } | |
| sub trim_list { trim_hash(shift, [qw/name slug id mode description/]) } | |
| sub trim_hash { | |
| my ( $hash, $keys ) = @_; | |
| { map { $_ => $hash->{$_} } @$keys } | |
| } | |
| sub for_each_result { | |
| my ( $method, $items_key, $args, $code ) = @_; | |
| for ( $args->{cursor} = -1; $args->{cursor}; ) { | |
| my $args->{cursor} = $cursor; | |
| my $r = $nt->$method($args); | |
| $code->($_) for @{$r->{$items_key}}; | |
| $args->{cursor} = $r->{next_cursor}; | |
| } | |
| } | |
| for_each_result(get_lists => lists => { user => $twit_id }, sub { | |
| my $list = trim_list(shift); | |
| my $twitter_list = $twitter_lists{$list->{name}}; | |
| $twitter_list->{$_} = $list->{$_} for keys %$list; | |
| # Add nested for_each_result calls to load following/followers | |
| for_each_result(list_members => users => { user => $twit_id, list_id => $list->{slug} }, sub { | |
| push @{$twitter_list->{following}}, trim_user(shift); | |
| }); | |
| for_each_result(list_subscribers => users => { user => $twit_id, list_id => $list->{slug} }, sub { | |
| push @{$twitter_list->{followers}}, trim_user(shift); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment