ruby-akismet 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +17 -7
  2. data/lib/akismet.rb +21 -5
  3. metadata +6 -6
data/README.rdoc CHANGED
@@ -1,8 +1,5 @@
1
1
  Akismet compatible library for checking spams.
2
2
 
3
- Initial form is derived from Akismetor by Ryan Bates and Levy Carneiro Jr.
4
- as findable at http://github.com/levycarneiro/akismetor
5
-
6
3
  = Usage
7
4
 
8
5
  First you need an Akismet (or Typepad Antispam) API key. Then you need
@@ -11,7 +8,7 @@ to setup a few configuration variable:
11
8
  Akismet.key = '123456789'
12
9
  Akismet.blog = 'http://example.com'
13
10
 
14
- To use Typepad Antispam, just set the host:
11
+ To use Typepad Antispam, just specify the host:
15
12
 
16
13
  Akismet.host = 'api.antispam.typepad.com'
17
14
 
@@ -22,19 +19,27 @@ and possibly an <code>ActionDispatch::Request</code> object.
22
19
 
23
20
  http://rubydoc.info/github/ysbaddaden/ruby-akismet/master/frames
24
21
 
25
- = Integrate with Ruby on Rails (3.0+)
22
+ = Integrate with Ruby on Rails
26
23
 
27
- Add this gem to your Gemfile:
24
+ On rails 3, add this gem to your <code>Gemfile</code>:
28
25
 
29
26
  gem 'ruby-akismet', :require => 'akismet'
30
27
 
28
+ On rails 2, first install the gem:
29
+
30
+ gem install ruby-akismet
31
+
32
+ Then add the gem to your app:
33
+
34
+ config.gem 'ruby-akismet', :lib => 'akismet'
35
+
31
36
  Create an initializer file like <code>config/initializers/akismet.rb</code>
32
37
  with your configuration:
33
38
 
34
39
  Akismet.key = '123456789'
35
40
  Akismet.blog = 'http://example.com'
36
41
 
37
- Then in your controller call the appropriate methods:
42
+ Then in your controller call the appropriate methods (rails 3 example):
38
43
 
39
44
  class CommentsController < ApplicationController
40
45
  before_filter :set_post
@@ -77,3 +82,8 @@ Then in your controller call the appropriate methods:
77
82
  end
78
83
  end
79
84
 
85
+ = Author
86
+
87
+ ruby-akismet is a complete rewrite of Akismetor by Ryan Bates and
88
+ Levy Carneiro Jr. that you can find at http://github.com/levycarneiro/akismetor
89
+
data/lib/akismet.rb CHANGED
@@ -2,12 +2,18 @@ require 'net/http'
2
2
 
3
3
  # Akismet compatible library for checking spams.
4
4
  class Akismet
5
- VERSION = '0.9.2'.freeze
5
+ VERSION = '0.9.3'.freeze
6
6
  API_VERSION = '1.1'.freeze
7
7
 
8
8
  @@host = 'rest.akismet.com'
9
9
  @@key = nil
10
10
  @@blog = nil
11
+ @@extra_headers = [
12
+ 'HTTP_REMOTE_ADDR',
13
+ 'HTTP_CLIENT_IP',
14
+ 'HTTP_X_FORWARDED_FOR',
15
+ 'HTTP_CONNECTION'
16
+ ]
11
17
 
12
18
  class << self
13
19
  # Configure an alternate API server.
@@ -25,6 +31,16 @@ class Akismet
25
31
  @@blog = blog
26
32
  end
27
33
 
34
+ # Configure an array of extra HTTP headers to pass to Akismet from
35
+ # the request.
36
+ #
37
+ # Example:
38
+ #
39
+ # Akismet.extra_headers = ['HTTP_REMOTE_ADDR', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR']
40
+ def extra_headers=(headers)
41
+ @@extra_headers = headers
42
+ end
43
+
28
44
  # Checks if a key is valid or not.
29
45
  def valid_key?(key)
30
46
  call('verify-key', :key => key) == "valid"
@@ -86,7 +102,6 @@ class Akismet
86
102
  end
87
103
 
88
104
  private
89
- # TODO: Extract more relevant HTTP headers.
90
105
  def attributes
91
106
  @attributes[:blog] ||= @@blog
92
107
 
@@ -94,9 +109,10 @@ class Akismet
94
109
  @attributes[:comment_type] ||= 'comment'
95
110
 
96
111
  unless @request.nil?
97
- @attributes[:user_ip] ||= @request.remote_ip
98
- @attributes[:user_agent] ||= @request.headers["User-Agent"]
99
- @attributes[:referrer] ||= @request.headers["Http-Referer"]
112
+ @attributes[:user_ip] = @request.remote_ip
113
+ @attributes[:user_agent] = @request.headers["HTTP_USER_AGENT"]
114
+ @attributes[:referrer] = @request.headers["HTTP_REFERER"]
115
+ @@extra_headers.each { |h| @attributes[h] = @request.headers[h] }
100
116
  end
101
117
  end
102
118
 
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: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Julien Portalier
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-22 00:00:00 +02:00
18
+ date: 2010-10-23 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: Ruby library for Akismet and Typepad Antispam with easy integration into a Rails 3 application.
22
+ description: Ruby library for Akismet and Typepad Antispam with simplified integration into a Rails application.
23
23
  email: ysbaddaden@gmail.com
24
24
  executables: []
25
25
 
@@ -64,6 +64,6 @@ rubyforge_project:
64
64
  rubygems_version: 1.3.7
65
65
  signing_key:
66
66
  specification_version: 3
67
- summary: Ruby library for the Akismet service.
67
+ summary: Ruby library for the Akismet anti-spam service.
68
68
  test_files:
69
69
  - test/akismet_test.rb