Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Mastodonの更新通知を受けるテスト
use strict;
use warnings;
use Plack::Builder;
use Plack::App::PubSubHubbub::Subscriber;
use Plack::App::PubSubHubbub::Subscriber::Config;
use Plack::App::PubSubHubbub::Subscriber::Client;
use Data::Dumper;
# 購読するAtomフィード
my $topic = 'https://friends.nico/users/argrath.atom';
# 使うHubサーバ
my $hub = 'https://friends.nico/api/push';
# とりあえず空文字列でも動く
my $token = '';
# SubscriberのURL
my $host = 'http://example.com:5000';
my $conf = Plack::App::PubSubHubbub::Subscriber::Config->new(
callback => $host . '/callback',
lease_seconds => 86400,
verify => 'sync',
);
my $app = Plack::App::PubSubHubbub::Subscriber->new(
config => $conf,
on_verify => sub {
my ($topic, $token, $mode, $lease) = @_;
printf "--verify--\n%s\n%s\n%s\n%s\n", $topic, $token, $mode, $lease;
return 1;
},
on_ping => sub {
my ($content_type, $content, $token) = @_;
printf "--ping--\n%s\n%s\n%s\n", $content_type, $content, $token;
},
);
my $client = Plack::App::PubSubHubbub::Subscriber::Client->new(
config => $conf,
);
builder {
mount $app->callback_path, $app->to_app;
mount '/subscribe' => sub {
return [
200,
[ 'Content-Type' => 'text/plain' ],
[ Dumper($client->subscribe( $hub, $topic, $token )) ],
];
};
mount '/unsubscribe' => sub {
return [
200,
[ 'Content-Type' => 'text/plain' ],
[ Dumper($client->unsubscribe( $hub, $topic, $token )) ],
];
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment