Created
October 25, 2009 12:55
-
-
Save sugyan/218050 to your computer and use it in GitHub Desktop.
AnyEvent::Wassr example
This file contains 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
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::Wassr; | |
use Encode 'encode_utf8'; | |
my $wassr = AnyEvent::Wassr->new( | |
username => '<your user id>', | |
password => '<password>', | |
); | |
sub print_statuses { | |
my ($wassr, @statuses) = @_; | |
for my $status (reverse @statuses) { | |
my $user = encode_utf8 $status->{user}{screen_name}; | |
my $text = encode_utf8 $status->{text}; | |
print "$user: $text\n"; | |
} | |
} | |
$wassr->reg_cb( | |
friends_timeline => \&print_statuses, | |
replies => \&print_statuses, | |
error => sub { | |
my ($wassr, $error) = @_; | |
warn "Error: $error\n"; | |
}, | |
); | |
$wassr->receive_statuses_friends(2); | |
$wassr->receive_statuses_replies(1); | |
$wassr->start; | |
my $cv = AE::cv; | |
my $w = AE::io *STDIN, 0, sub { | |
my $input = scalar <STDIN>; | |
chomp($input); | |
$wassr->update_status( | |
$input, sub { | |
my ($wassr, $js_status, $error) = @_; | |
if (defined $error) { | |
warn "update error: $error\n"; | |
} else { | |
my $text = encode_utf8 $js_status->{text}; | |
print qq/update success! "$text"\n/; | |
} | |
}, | |
); | |
}; | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment