はてブのWeb HookでDeliciousと同期する
というのを今更ながらやろうとしてHookHubにそれくらいあるだろうと思って久しぶりにみたら、まさかのまじぽかさんだったので自分で書いた。
# hatebu_hook_post_delicious.psgi
# はてブの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, [], []];
};
これをplackupで起動すればOK。
- Prev Entry:HTML5の新要素をjQueryでappendとかするとIEでバグる件
- Next Entry:gitで過去のリビジョンとか別のbranchのファイルを見る