Skip to content

Instantly share code, notes, and snippets.

@kraih
Created February 20, 2012 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kraih/1868865 to your computer and use it in GitHub Desktop.
Save kraih/1868865 to your computer and use it in GitHub Desktop.
$ twiggy -l :3000 twitter.psgi
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