ruby-akismet 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +6 -3
- data/lib/akismet.rb +12 -79
- data/test/akismet_test.rb +1 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -16,14 +16,17 @@ To use Typepad Antispam, just set the host:
|
|
16
16
|
Akismet.host = 'api.antispam.typepad.com'
|
17
17
|
|
18
18
|
Then you need to call any of the methods with a few attributes,
|
19
|
-
and possibly an ActionDispatch::Request object.
|
19
|
+
and possibly an <code>ActionDispatch::Request</code> object.
|
20
|
+
|
21
|
+
= Documentation
|
22
|
+
|
23
|
+
http://rubydoc.info/github/ysbaddaden/ruby-akismet/master/frames
|
20
24
|
|
21
25
|
= Integrate with Ruby on Rails (3.0+)
|
22
26
|
|
23
27
|
Add this gem to your Gemfile:
|
24
28
|
|
25
|
-
gem 'ruby-akismet', :require => 'akismet'
|
26
|
-
:git => 'git://github.com/ysbaddaden/ruby-akismet.git'
|
29
|
+
gem 'ruby-akismet', :require => 'akismet'
|
27
30
|
|
28
31
|
Create an initializer file like <code>config/initializers/akismet.rb</code>
|
29
32
|
with your configuration:
|
data/lib/akismet.rb
CHANGED
@@ -1,80 +1,8 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
|
3
3
|
# Akismet compatible library for checking spams.
|
4
|
-
#
|
5
|
-
# = Usage
|
6
|
-
#
|
7
|
-
# First you need an Akismet (or Typepad Antispam) API key. Then you need
|
8
|
-
# to setup a few configuration variable.
|
9
|
-
#
|
10
|
-
# Akismet.key = '123456789'
|
11
|
-
# Akismet.blog = 'http://example.com'
|
12
|
-
#
|
13
|
-
# To use Typepad Antispam, just set the host:
|
14
|
-
#
|
15
|
-
# Akismet.host = 'api.antispam.typepad.com'
|
16
|
-
#
|
17
|
-
# Then you need to call any of the methods with a few attributes,
|
18
|
-
# and possibly an ActionDispatch::Request object.
|
19
|
-
#
|
20
|
-
# = Integrate with Ruby on Rails (3.0+)
|
21
|
-
#
|
22
|
-
# Add this gem to your Gemfile:
|
23
|
-
#
|
24
|
-
# gem 'ruby-akismet', :require => 'akismet',
|
25
|
-
# :git => 'git://github.com/ysbaddaden/ruby-akismet.git'
|
26
|
-
#
|
27
|
-
# Create an initializer file like <code>config/initializers/akismet.rb</code>
|
28
|
-
# with your configuration:
|
29
|
-
#
|
30
|
-
# Akismet.key = '123456789'
|
31
|
-
# Akismet.blog = 'http://example.com'
|
32
|
-
#
|
33
|
-
# Then in your controller call the appropriate methods:
|
34
|
-
#
|
35
|
-
# class CommentsController < ApplicationController
|
36
|
-
# before_filter :set_post
|
37
|
-
# respond_to :html, :xml
|
38
|
-
#
|
39
|
-
# def create
|
40
|
-
# @comment = @post.comments.new(params[:comment])
|
41
|
-
# @comment.spam = Akismet.spam?(akismet_attributes, request)
|
42
|
-
# @comment.save
|
43
|
-
# respond_with(@comment, :location => @post)
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# def spam
|
47
|
-
# @comment = Comment.find(params[:id])
|
48
|
-
# @comment.update_attribute(:spam, false)
|
49
|
-
# Akismet.submit_spam(akismet_attributes)
|
50
|
-
# respond_with(@comment, :location => @post)
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# def ham
|
54
|
-
# @comment = Comment.find(params[:id])
|
55
|
-
# @comment.update_attribute(:spam, false)
|
56
|
-
# Akismet.submit_ham(akismet_attributes)
|
57
|
-
# respond_with(@comment, :location => @post)
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# private
|
61
|
-
# def akismet_attributes
|
62
|
-
# {
|
63
|
-
# :comment_author => @comment.author,
|
64
|
-
# :comment_author_url => @comment.author_url,
|
65
|
-
# :comment_author_email => @comment.author_email,
|
66
|
-
# :comment_content => @comment.body,
|
67
|
-
# :permalink => post_url(@post)
|
68
|
-
# }
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
# def set_post
|
72
|
-
# @post = Post.find(params[:post_id])
|
73
|
-
# end
|
74
|
-
# end
|
75
|
-
#
|
76
4
|
class Akismet
|
77
|
-
VERSION = '0.9.
|
5
|
+
VERSION = '0.9.2'.freeze
|
78
6
|
API_VERSION = '1.1'.freeze
|
79
7
|
|
80
8
|
@@host = 'rest.akismet.com'
|
@@ -82,23 +10,27 @@ class Akismet
|
|
82
10
|
@@blog = nil
|
83
11
|
|
84
12
|
class << self
|
13
|
+
# Configure an alternate API server.
|
85
14
|
def host=(host)
|
86
15
|
@@host = host
|
87
16
|
end
|
88
17
|
|
18
|
+
# Configure your API key (required).
|
89
19
|
def key=(key)
|
90
20
|
@@key = key
|
91
21
|
end
|
92
22
|
|
23
|
+
# Configure your homepage URL (optional).
|
93
24
|
def blog=(blog)
|
94
25
|
@@blog = blog
|
95
26
|
end
|
96
27
|
|
28
|
+
# Checks if a key is valid or not.
|
97
29
|
def valid_key?(key)
|
98
30
|
call('verify-key', :key => key) == "valid"
|
99
31
|
end
|
100
32
|
|
101
|
-
# Checks
|
33
|
+
# Checks if a comment is spam.
|
102
34
|
#
|
103
35
|
# Required attributes:
|
104
36
|
#
|
@@ -119,19 +51,19 @@ class Akismet
|
|
119
51
|
call('comment-check', attributes, request) == "true"
|
120
52
|
end
|
121
53
|
|
122
|
-
#
|
54
|
+
# Checks if a comment is ham. Takes the same arguments than spam?.
|
123
55
|
def ham?(attributes, request = nil)
|
124
56
|
call('comment-check', attributes, request) == "false"
|
125
57
|
end
|
126
58
|
|
127
59
|
# Submits a spam comment to Akismet that hadn't been recognized
|
128
|
-
# as spam. Takes the same attributes than spam
|
60
|
+
# as spam. Takes the same attributes than spam?.
|
129
61
|
def submit_spam(attributes)
|
130
62
|
call('submit-spam', attributes)
|
131
63
|
end
|
132
64
|
|
133
65
|
# Submits a false-positive comment as non-spam to Akismet.
|
134
|
-
# Takes the same attributes than spam
|
66
|
+
# Takes the same attributes than +spam+.
|
135
67
|
def submit_ham(attributes)
|
136
68
|
call('submit-ham', attributes)
|
137
69
|
end
|
@@ -142,18 +74,19 @@ class Akismet
|
|
142
74
|
end
|
143
75
|
end
|
144
76
|
|
145
|
-
def initialize(command, attributes, request = nil)
|
77
|
+
def initialize(command, attributes, request = nil)
|
146
78
|
@command = command
|
147
79
|
@attributes = attributes
|
148
80
|
@request = request
|
149
81
|
end
|
150
82
|
|
151
|
-
def call
|
83
|
+
def call
|
152
84
|
http = Net::HTTP.new(http_host, 80)
|
153
85
|
http.post(http_path, post_attributes, http_headers).body
|
154
86
|
end
|
155
87
|
|
156
88
|
private
|
89
|
+
# TODO: Extract more relevant HTTP headers.
|
157
90
|
def attributes
|
158
91
|
@attributes[:blog] ||= @@blog
|
159
92
|
|
data/test/akismet_test.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-akismet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 2
|
10
|
+
version: 0.9.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Julien Portalier
|