Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # はてブのwebhookでdeliciousにPOSTして同期する
- use strict;
- use warnings;
- use Plack::Request;
- use Config::Pit;
- use Net::Delicious;
- my $conf = pit_get('hatena_hook', require => {
- key => '',
- delicious_user => '',
- delicious_password => '',
- });
- my $app = sub {
- my $env = shift;
- my $req = Plack::Request->new($env);
- return [403, [], []] if $conf->{key} ne $req->param('key');
- my $d = Net::Delicious->new({
- user => $conf->{delicious_user},
- pswd => $conf->{delicious_password},
- });
- my $res;
- if ($req->param('status') =~ m/^(add|update)$/) {
- my $comment = $req->param('comment');
- my @tags;
- while ($comment =~ s!\[([^\:\[\]]+)\]!!) {
- push @tags, $1;
- }
- $comment =~ s/^\s*(.*?)\s*$/$1/;
- $res = $d->add_post({
- url => $req->param('url'),
- description => $req->param('title'),
- extended => $comment,
- tags => join(' ', @tags),
- dt => $req->param('timestamp'),
- });
- }
- elsif ($req->param('status') eq 'delete') {
- $res = $d->delete_post({ url => $req->param('url') });
- }
- return [$res ? 200 : 400, [], []];
- };
Add Comment
Please, Sign In to add comment