ml (owner)

Revisions

  • 99595f ml Tue Oct 06 09:08:03 -0700 2009
gist: 203164 Download_button fork
public
Public Clone URL: git://gist.github.com/203164.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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.env["rack-middleware.rakismet.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
 
# replace yourkey and yourblog with real credentials or use fakeweb
use Rack::Rakismet, "yourkey", "http://yourblog.wordpress.com", form_mapping, predicate