Code: Select all
package PluginWithAsyncWebRequest;
use Mojo::IOLoop;
use Mojo::UserAgent;
# <normal callbacks that SPADS plugins require>
my $ua = Mojo::UserAgent->new;
sub eventLoop {
Mojo::IOLoop->one_tick;
}
sub new {
my $class = shift;
addSpadsCommandHandler(spring_news => sub {
my $source = shift;
my $user = shift;
$ua->get("springrts.com" => sub {
my ($ua, $tx) = @_;
my $headline = $tx->res->dom('div.newsheadline a')->first->text;
sayPrivate($user, "the current headline is: $headline");
});
}});
bless({}, $class);
}
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
1;
because Mojolicious is the bomb, I could even serve web routes from within a spads plugin, but that's probably better left to an external service.