inspiredigital-rakismet 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +136 -0
- data/lib/rakismet/controller_extensions.rb +26 -0
- data/lib/rakismet/model_extensions.rb +69 -0
- data/rails/init.rb +2 -0
- metadata +62 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Josh French
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
Rakismet
|
2
|
+
========
|
3
|
+
|
4
|
+
**Akismet** (<http://akismet.com/>) is a collaborative spam filtering service.
|
5
|
+
**Rakismet** is easy Akismet integration with your Rails app, including support
|
6
|
+
for TypePad's AntiSpam service.
|
7
|
+
|
8
|
+
|
9
|
+
Setup
|
10
|
+
=====
|
11
|
+
|
12
|
+
Install with `script/plugin install git://github.com/jfrench/rakismet`
|
13
|
+
|
14
|
+
To get up and running with Rakismet, you'll need an API key from the folks at
|
15
|
+
WordPress. Head on over to http://wordpress.com/api-keys/ and sign up for a
|
16
|
+
new username.
|
17
|
+
|
18
|
+
Rakismet installation should have created a file called rakismet.rb in
|
19
|
+
config/initializers. Add your WordPress key and the front page or home URL of
|
20
|
+
your app. Rakismet::URL must be a fully qualified URI including the http://.
|
21
|
+
|
22
|
+
If that file is missing, create it and add the following:
|
23
|
+
|
24
|
+
Rakismet::KEY = 'your key from WordPress'
|
25
|
+
Rakismet::URL = 'http://base url for your application/'
|
26
|
+
Rakismet::HOST = 'rest.akismet.com'
|
27
|
+
|
28
|
+
The Rakismet host can be changed if you wish to use another Akismet-compatible
|
29
|
+
API provider such as TypePad's antispam service.
|
30
|
+
|
31
|
+
Now introduce Rakismet to your application. Let's assume you have a Comment
|
32
|
+
model and a CommentsController:
|
33
|
+
|
34
|
+
class Comment < ActiveRecord::Base
|
35
|
+
has_rakismet
|
36
|
+
end
|
37
|
+
|
38
|
+
class CommentsController < ActionController::Base
|
39
|
+
has_rakismet
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
Basic Usage
|
44
|
+
===========
|
45
|
+
|
46
|
+
Rakismet provides three methods for interacting with Akismet:
|
47
|
+
|
48
|
+
`spam?`
|
49
|
+
|
50
|
+
From within a CommentsController action, simply call `@comment.spam?` to get a
|
51
|
+
true/false response. True means it's spam, false means it's not. Well,
|
52
|
+
usually; it's possible something went wrong and Akismet returned an error
|
53
|
+
message. `@comment.spam?` will return false if this happens. You can check
|
54
|
+
`@comment.akismet_response` to be certain; anything other than 'true' or
|
55
|
+
'false' means you got an error. That said, as long as you're collecting the
|
56
|
+
data listed above it's probably sufficient to check `spam?` alone.
|
57
|
+
|
58
|
+
`ham!` and `spam!`
|
59
|
+
|
60
|
+
Akismet works best with your feedback. If you spot a comment that was
|
61
|
+
erroneously marked as spam, `@comment.ham!` will resubmit to Akismet, marked
|
62
|
+
as a false positive. Likewise if they missed a spammy comment,
|
63
|
+
`@comment.spam!` will resubmit marked as spam.
|
64
|
+
|
65
|
+
|
66
|
+
What's Required in the Comment Model?
|
67
|
+
=====================================
|
68
|
+
|
69
|
+
Rakismet sends the following information to the spam-hungry robots at Akismet.
|
70
|
+
This means these attributes should be stored in your Comment model or
|
71
|
+
accessible through that class's associations.
|
72
|
+
|
73
|
+
author : name submitted with the comment
|
74
|
+
author_url : URL submitted with the comment
|
75
|
+
author_email : email submitted with the comment
|
76
|
+
comment_type : 'comment', 'trackback', 'pingback', or whatever you fancy
|
77
|
+
content : the content submitted
|
78
|
+
permalink : the permanent URL for the entry the comment belongs to
|
79
|
+
user_ip : IP address used to submit this comment
|
80
|
+
user_agent : user agent string
|
81
|
+
referrer : http referer
|
82
|
+
|
83
|
+
`user_ip`, `user_agent`, and `referrer` are optional; you don't have to store
|
84
|
+
them, but it's a good idea. If you omit them from your model (see "Customizing
|
85
|
+
Attributes"), the `spam?` method will attempt to extract these values from the
|
86
|
+
current request object, if there is one. This means Rakismet can operate
|
87
|
+
asynchronously by storing the request attributes and validating the comment at
|
88
|
+
a later time. Or it can operate synchronously by plucking the request
|
89
|
+
attributes from the environment at the time the comment is initially submitted
|
90
|
+
and validating on the spot. The latter could work well with a before_create
|
91
|
+
callback.
|
92
|
+
|
93
|
+
|
94
|
+
Customizing the Comment Model
|
95
|
+
=============================
|
96
|
+
|
97
|
+
If your attribute names don't match those listed above, or if some of them
|
98
|
+
live on other objects, you can pass `has_rakismet` a hash mapping the default
|
99
|
+
attributes to your own. You can change the names, if your comment attributes
|
100
|
+
don't match the defaults:
|
101
|
+
|
102
|
+
class Comment < ActiveRecord::Base
|
103
|
+
has_rakismet :author => :commenter_name,
|
104
|
+
:author_email => :commenter_email
|
105
|
+
end
|
106
|
+
|
107
|
+
Or you can pass in a proc, to access associations:
|
108
|
+
|
109
|
+
class Comment < ActiveRecord::Base
|
110
|
+
belongs_to :author
|
111
|
+
has_rakismet :author => proc { author.name },
|
112
|
+
:author_email => proc { author.email }
|
113
|
+
end
|
114
|
+
|
115
|
+
For any attribute you don't specify, Rakismet will try to find an attribute or
|
116
|
+
method matching the default name. As mentioned above, if `user_ip`,
|
117
|
+
`user_agent`, and `referrer` are not present on your model, Rakismet will
|
118
|
+
attempt to find them in the request environment when `spam?` is called from
|
119
|
+
within a Rakismet-aware controller action.
|
120
|
+
|
121
|
+
Customizing the Comments Controller
|
122
|
+
===================================
|
123
|
+
|
124
|
+
Most of the time you won't be checking for spam on every action defined in
|
125
|
+
your controller. If you only call `spam?` within `CommentsController#create`
|
126
|
+
and you'd like to reduce filter overhead, `has_rakismet` takes `:only` and
|
127
|
+
`:except` parameters that work like the standard before/around/after filter
|
128
|
+
options.
|
129
|
+
|
130
|
+
class CommentsController < ActionController::Base
|
131
|
+
has_rakismet :only => :create
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
--------------------------------------------------------------
|
136
|
+
Copyright (c) 2008 Josh French, released under the MIT license
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Rakismet
|
2
|
+
module ControllerExtensions
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
extend ClassMethods
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def rakismet(&block)
|
11
|
+
Rakismet::Base.rakismet_binding = binding
|
12
|
+
yield
|
13
|
+
Rakismet::Base.rakismet_binding = nil
|
14
|
+
end
|
15
|
+
private :rakismet
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def has_rakismet(opts={})
|
19
|
+
skip_filter :rakismet # in case we're inheriting from another Rakismeted controller
|
20
|
+
opts.assert_valid_keys(:only, :except)
|
21
|
+
self.around_filter :rakismet, opts
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Rakismet
|
2
|
+
module ModelExtensions
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
attr_accessor :akismet_response
|
7
|
+
class_inheritable_hash :akismet_attrs
|
8
|
+
extend ClassMethods
|
9
|
+
include InstanceMethods
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def has_rakismet(args={})
|
15
|
+
self.akismet_attrs ||= {}
|
16
|
+
[:comment_type, :author, :author_url, :author_email, :content].each do |field|
|
17
|
+
# clunky, but throwing around +type+ will break your heart
|
18
|
+
fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
|
19
|
+
self.akismet_attrs[fieldname] = args.delete(field) || field
|
20
|
+
end
|
21
|
+
[:user_ip, :user_agent, :referrer].each do |field|
|
22
|
+
self.akismet_attrs[field] = (args.delete(field) || field) if args.has_key?(field) or self.public_instance_methods.include?(field.to_s)
|
23
|
+
end
|
24
|
+
args.each_pair do |f,v|
|
25
|
+
self.akismet_attrs[f] = v
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module InstanceMethods
|
31
|
+
def spam?
|
32
|
+
data = akismet_data
|
33
|
+
|
34
|
+
unless Rakismet::Base.rakismet_binding.nil?
|
35
|
+
{ :referrer => 'request.referer', :user_ip => 'request.remote_ip',
|
36
|
+
:user_agent => 'request.user_agent' }.each_pair do |k,v|
|
37
|
+
data[k] = eval(v, Rakismet::Base.rakismet_binding) || ''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
self.akismet_response = Rakismet::Base.akismet_call('comment-check', data)
|
42
|
+
self.akismet_response == 'true'
|
43
|
+
end
|
44
|
+
|
45
|
+
def spam!
|
46
|
+
Rakismet::Base.akismet_call('submit-spam', akismet_data)
|
47
|
+
end
|
48
|
+
|
49
|
+
def ham!
|
50
|
+
Rakismet::Base.akismet_call('submit-ham', akismet_data)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def akismet_data
|
56
|
+
self.class.akismet_attrs.keys.inject({}) do |data,attr|
|
57
|
+
data.merge attr => if self.class.akismet_attrs[attr].is_a?(Proc)
|
58
|
+
instance_eval(&self.class.akismet_attrs[attr])
|
59
|
+
elsif respond_to?(self.class.akismet_attrs[attr])
|
60
|
+
send(self.class.akismet_attrs[attr])
|
61
|
+
else
|
62
|
+
self.class.akismet_attrs[attr]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inspiredigital-rakismet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh French
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Rakismet is easy Akismet integration with your Rails app, including support for TypePad's AntiSpam service. This version is a fork Josh French's rakismet plugin.
|
17
|
+
email: systems@inspiredigital.com.au
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.md
|
24
|
+
- MIT-LICENSE
|
25
|
+
files:
|
26
|
+
- CHANGELOG
|
27
|
+
- README.md
|
28
|
+
- rails/init.rb
|
29
|
+
- lib/rakismet
|
30
|
+
- lib/rakismet/controller_extensions.rb
|
31
|
+
- lib/rakismet/model_extensions.rb
|
32
|
+
- MIT-LICENSE
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/inspiredigital/rakismet
|
35
|
+
licenses:
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --inline-source
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project: rakismet
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Rakismet is easy Akismet integration with your Rails app, including support for TypePad's AntiSpam service. This version is a fork Josh French's rakismet plugin.
|
61
|
+
test_files: []
|
62
|
+
|