Created
February 20, 2012 11:29
-
-
Save kraih/1868865 to your computer and use it in GitHub Desktop.
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
$ twiggy -l :3000 twitter.psgi |
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 5.14.0; | |
use Mojo::UserAgent; | |
use Mojo::ByteStream 'b'; | |
use EV; | |
# Normal PSGI application | |
my $ua = Mojo::UserAgent->new; | |
my $app = sub { | |
return sub { | |
my $respond = shift; | |
# Search Twitter for "perl" | |
$ua->get('http://search.twitter.com/search.json?q=perl' => sub { | |
my ($ua, $tx) = @_; | |
# Respond with first result | |
$respond->([ | |
200, | |
['Content-Type' => 'text/plain;charset=UTF-8'], | |
[b($tx->res->json->{results}->[0]->{text})->encode] | |
]); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment