Rakismet
Added by maciej
at October 09, 2009 12:04
GitHub stats:
watcher(s)
fork(s)
About
Rakismet is Akismet client for rack. Akismet is a web service which deals with spam. You have to obtain an API key and you can start using it.
Usage
You have to provide your API key, your site url, mapping hash which maps fields from your comment form to variables required by Akismet and predicate which indicates if a request should be checked by Akismet.
require 'rubygems'
require 'sinatra'
require File.join(File.dirname(__FILE__), '..', 'lib', 'rakismet.rb')
get '/' do
%{<html><head><title>Rakismet</title></head><body>
<form action="/posts" method="post">
<label for="comment_author">author</author>
<input type="text" name="author" id="comment_author" />
<br />
<label for="comment_email">email</label>
<input type="text" name="email" id="comment_email" />
<br />
<label for="comment_url">url</author>
<input type="text" name="url" id="comment_url" />
<br />
<label for="comment_content">content</author>
<input type="text" name="content" id="content" />
<br />
<input type="submit" value="submit" />
</form>
</body></html>}
end
post '/posts' do
if request.spam?
"spammer!!"
else
"<html><head><title>Rakismet</title></head><body>OHAI!</body></html>"
end
end
form_mapping = { "author" => :comment_author,
"email" => :comment_author_email,
"url" => :comment_author_url,
"content" => :comment_content }
predicate = lambda do |path, method, form_data|
path =~ /posts/ && method == "POST"
end
use Rack::Rakismet, "yourkey", "http://yourblog.wordpress.com", form_mapping, predicate
