/
akismet.rb
37 lines (31 loc) · 1.17 KB
/
akismet.rb
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
module SpamEngine
module Filter
class Akismet < Base
SpamEngine::Filter.register self
def check_comment(comment, context = {})
is_ham = backend.check_comment(comment_options(comment, context))
comment.spam_reports << SpamReport.new(:engine => name, :spaminess => (is_ham ? 0 : 100))
end
def mark_as_ham(comment, context = {})
key && url
end
def mark_as_spam(comment, context = {})
key && url
end
protected
def backend
@backend ||= Viking.connect("akismet", :api_key => key, :blog => url)
end
def comment_options(comment, context)
{ :permalink => context[:permalink],
:user_ip => comment.author_ip,
:user_agent => comment.author_agent,
:referrer => comment.author_referer,
:comment_author => comment.author_name,
:comment_author_email => comment.author_email,
:comment_author_url => comment.author_homepage,
:comment_content => comment.body }
end
end
end
end