Python Akismet Library is already done. So I wrote a quick and dirty perl function to call Akismet comment-check API.
use LWP::UserAgent;
use URI::Escape;
sub akismet ($$) {
my ($apikey,$query) = @_;
my $ua = new LWP::UserAgent;
$ua->agent('Perl 5.8.7 | Net::Akismet/0.1');
my $request = HTTP::Request->new('POST',
'http://' . $apikey . '.rest.akismet.com/1.1/comment-check');
my $query_string = '';
my $key;
foreach $key (keys(%$query)){
$query_string .= $key . '=' . uri_escape($query->{$key}) . '&';
}
$request->content_type('application/x-www-form-urlencoded; charset=UTF-8');
$request->content($query_string);
my $response = $ua->request($request);
return $response->content();
}
You can call it as follow.
my $q = {blog=>'あなたのblogのトップページのURI',
user_ip=>'投稿者のIPアドレス',
user_agent=>'投稿者の user agent',
referrer=>'投稿者の referrer',
permalink=>'投稿先の permalink',
comment_type=>'comment, trackback, pingback のいずれか',
comment_author=>'投稿者の名前',
comment_author_email=>'投稿者の mail address',
comment_author_url=>'投稿者のURL',
comment_content=>'コメント本文',
};
my $apikey = 'ここにあなたの API Key を書いてね';
if(akismet($apikey,$q) eq 'true'){
# ham ですな
}else{
# spam ですな
}
Other than comment-check, Akismet API includes verify key, submit-spam, and submit-ham interface.


December 5th, 2005 at 0:35
[...] Akismet を perl から使う話をもっと拡張して、API の四つの REST Interface を全部使えるように Net::Akismet クラスを作ってみたですよ。 [...]