rakismet 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README.md +7 -1
- data/Rakefile +3 -4
- data/VERSION.yml +2 -2
- data/lib/rakismet.rb +3 -3
- data/lib/rakismet/railtie.rb +2 -0
- data/rakismet.gemspec +19 -28
- data/spec/rakismet_spec.rb +35 -6
- data/spec/spec_helper.rb +1 -1
- metadata +8 -23
- data/.gitignore +0 -9
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -23,11 +23,17 @@ in an initializer or application.rb:
|
|
23
23
|
|
24
24
|
config.rakismet.key = 'your wordpress key'
|
25
25
|
config.rakismet.url = 'http://yourdomain.com/'
|
26
|
-
|
26
|
+
|
27
27
|
If you wish to use another Akismet-compatible API provider such as TypePad's
|
28
28
|
antispam service, you'll also need to set `config.rakismet.host` to your service
|
29
29
|
provider's endpoint.
|
30
30
|
|
31
|
+
If you want to use a proxy to access akismet (i.e your application is behind a firewall),
|
32
|
+
set the proxy_host and proxy_port option.
|
33
|
+
|
34
|
+
config.rakismet.proxy_host = 'http://yourdomain.com/'
|
35
|
+
config.rakismet.proxy_port = '8080'
|
36
|
+
|
31
37
|
Checking For Spam
|
32
38
|
-----------------
|
33
39
|
|
data/Rakefile
CHANGED
@@ -17,10 +17,9 @@ rescue LoadError
|
|
17
17
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
18
|
end
|
19
19
|
|
20
|
-
require '
|
21
|
-
|
22
|
-
spec.
|
23
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
20
|
+
require 'rspec/core/rake_task'
|
21
|
+
RSpec::Core::RakeTask.new do |spec|
|
22
|
+
spec.rspec_opts = ["--color", "--format progress"]
|
24
23
|
end
|
25
24
|
|
26
25
|
task :default => :spec
|
data/VERSION.yml
CHANGED
data/lib/rakismet.rb
CHANGED
@@ -13,7 +13,7 @@ module Rakismet
|
|
13
13
|
Undefined = Class.new(NameError)
|
14
14
|
|
15
15
|
class << self
|
16
|
-
attr_accessor :key, :url, :host
|
16
|
+
attr_accessor :key, :url, :host, :proxy_host, :proxy_port
|
17
17
|
|
18
18
|
def request
|
19
19
|
@request ||= Request.new
|
@@ -46,7 +46,7 @@ module Rakismet
|
|
46
46
|
def validate_key
|
47
47
|
validate_config
|
48
48
|
akismet = URI.parse(verify_url)
|
49
|
-
_, valid = Net::HTTP.start(akismet.host) do |http|
|
49
|
+
_, valid = Net::HTTP::Proxy(proxy_host, proxy_port).start(akismet.host) do |http|
|
50
50
|
data = "key=#{Rakismet.key}&blog=#{Rakismet.url}"
|
51
51
|
http.post(akismet.path, data, Rakismet.headers)
|
52
52
|
end
|
@@ -61,7 +61,7 @@ module Rakismet
|
|
61
61
|
validate_config
|
62
62
|
args.merge!(:blog => Rakismet.url)
|
63
63
|
akismet = URI.parse(call_url(function))
|
64
|
-
_, response = Net::HTTP.start(akismet.host) do |http|
|
64
|
+
_, response = Net::HTTP::Proxy(proxy_host, proxy_port).start(akismet.host) do |http|
|
65
65
|
data = args.map { |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
|
66
66
|
http.post(akismet.path, data, Rakismet.headers)
|
67
67
|
end
|
data/lib/rakismet/railtie.rb
CHANGED
@@ -12,6 +12,8 @@ module Rakismet
|
|
12
12
|
Rakismet.key = app.config.rakismet[:key]
|
13
13
|
Rakismet.url = app.config.rakismet[:url]
|
14
14
|
Rakismet.host = app.config.rakismet[:host]
|
15
|
+
Rakismet.proxy_host = app.config.rakismet[:proxy_host]
|
16
|
+
Rakismet.proxy_port = app.config.rakismet[:proxy_port]
|
15
17
|
app.middleware.use Rakismet::Middleware if app.config.rakismet.use_middleware
|
16
18
|
end
|
17
19
|
|
data/rakismet.gemspec
CHANGED
@@ -1,53 +1,44 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rakismet}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Josh French"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-07-05}
|
13
13
|
s.description = %q{Rakismet is the easiest way to integrate Akismet or TypePad's AntiSpam into your Rails app.}
|
14
14
|
s.email = %q{josh@digitalpulp.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
"spec/spec_helper.rb"
|
19
|
+
"CHANGELOG",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION.yml",
|
24
|
+
"lib/rakismet.rb",
|
25
|
+
"lib/rakismet/middleware.rb",
|
26
|
+
"lib/rakismet/model.rb",
|
27
|
+
"lib/rakismet/railtie.rb",
|
28
|
+
"rakismet.gemspec",
|
29
|
+
"spec/.rspec",
|
30
|
+
"spec/rakismet_middleware_spec.rb",
|
31
|
+
"spec/rakismet_model_spec.rb",
|
32
|
+
"spec/rakismet_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
35
34
|
]
|
36
35
|
s.homepage = %q{http://github.com/joshfrench/rakismet}
|
37
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
38
36
|
s.require_paths = ["lib"]
|
39
37
|
s.rubyforge_project = %q{rakismet}
|
40
|
-
s.rubygems_version = %q{1.
|
38
|
+
s.rubygems_version = %q{1.6.2}
|
41
39
|
s.summary = %q{Akismet and TypePad AntiSpam integration for Rails.}
|
42
|
-
s.test_files = [
|
43
|
-
"spec/rakismet_middleware_spec.rb",
|
44
|
-
"spec/rakismet_model_spec.rb",
|
45
|
-
"spec/rakismet_spec.rb",
|
46
|
-
"spec/spec_helper.rb"
|
47
|
-
]
|
48
40
|
|
49
41
|
if s.respond_to? :specification_version then
|
50
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
42
|
s.specification_version = 3
|
52
43
|
|
53
44
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/spec/rakismet_spec.rb
CHANGED
@@ -9,6 +9,13 @@ describe Rakismet do
|
|
9
9
|
Rakismet.url = 'test.localhost'
|
10
10
|
Rakismet.host = 'endpoint.localhost'
|
11
11
|
end
|
12
|
+
|
13
|
+
describe "proxy host" do
|
14
|
+
it "should have proxy host and port as nil by default" do
|
15
|
+
Rakismet.proxy_host.should be_nil
|
16
|
+
Rakismet.proxy_port.should be_nil
|
17
|
+
end
|
18
|
+
end
|
12
19
|
|
13
20
|
describe ".validate_config" do
|
14
21
|
it "should raise an error if key is not found" do
|
@@ -28,14 +35,27 @@ describe Rakismet do
|
|
28
35
|
end
|
29
36
|
|
30
37
|
describe ".validate_key" do
|
38
|
+
before (:each) do
|
39
|
+
@proxy = mock(Net::HTTP)
|
40
|
+
Net::HTTP.stub!(:Proxy).and_return(@proxy)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should use proxy host and port" do
|
44
|
+
Rakismet.proxy_host = 'proxy_host'
|
45
|
+
Rakismet.proxy_port = 'proxy_port'
|
46
|
+
@proxy.stub!(:start).and_return([nil, 'valid'])
|
47
|
+
Net::HTTP.should_receive(:Proxy).with('proxy_host', 'proxy_port').and_return(@proxy)
|
48
|
+
Rakismet.validate_key
|
49
|
+
end
|
50
|
+
|
31
51
|
it "should set @@valid_key = true if key is valid" do
|
32
|
-
|
52
|
+
@proxy.stub!(:start).and_return([nil, 'valid'])
|
33
53
|
Rakismet.validate_key
|
34
54
|
Rakismet.valid_key?.should be_true
|
35
55
|
end
|
36
56
|
|
37
57
|
it "should set @@valid_key = false if key is invalid" do
|
38
|
-
|
58
|
+
@proxy.stub!(:start).and_return([nil, 'invalid'])
|
39
59
|
Rakismet.validate_key
|
40
60
|
Rakismet.valid_key?.should be_false
|
41
61
|
end
|
@@ -43,20 +63,30 @@ describe Rakismet do
|
|
43
63
|
it "should build url with host" do
|
44
64
|
host = "api.antispam.typepad.com"
|
45
65
|
Rakismet.host = host
|
46
|
-
|
66
|
+
@proxy.should_receive(:start).with(host).and_yield(http)
|
47
67
|
Rakismet.validate_key
|
48
68
|
end
|
49
69
|
end
|
50
70
|
|
51
71
|
describe ".akismet_call" do
|
52
72
|
before do
|
53
|
-
Net::HTTP
|
73
|
+
@proxy = mock(Net::HTTP)
|
74
|
+
Net::HTTP.stub!(:Proxy).and_return(@proxy)
|
75
|
+
@proxy.stub(:start).and_yield(http)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should use proxy host and port" do
|
79
|
+
Rakismet.proxy_host = 'proxy_host'
|
80
|
+
Rakismet.proxy_port = 'proxy_port'
|
81
|
+
@proxy.stub!(:start).and_return([nil, 'valid'])
|
82
|
+
Net::HTTP.should_receive(:Proxy).with('proxy_host', 'proxy_port').and_return(@proxy)
|
83
|
+
Rakismet.send(:akismet_call, 'bogus-function')
|
54
84
|
end
|
55
85
|
|
56
86
|
it "should build url with API key for the correct host" do
|
57
87
|
host = 'api.antispam.typepad.com'
|
58
88
|
Rakismet.host = host
|
59
|
-
|
89
|
+
@proxy.should_receive(:start).with("#{Rakismet.key}.#{host}")
|
60
90
|
Rakismet.send(:akismet_call, 'bogus-function')
|
61
91
|
end
|
62
92
|
|
@@ -66,7 +96,6 @@ describe Rakismet do
|
|
66
96
|
end
|
67
97
|
|
68
98
|
it "should return response.body" do
|
69
|
-
#Net::HTTP.stub!(:start).and_return([nil, 'akismet response'])
|
70
99
|
Rakismet.send(:akismet_call, 'bogus-function').should eql('akismet response')
|
71
100
|
end
|
72
101
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rakismet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 1.0.1
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Josh French
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-07-05 00:00:00 -04:00
|
19
14
|
default_executable:
|
20
15
|
dependencies: []
|
21
16
|
|
@@ -28,7 +23,6 @@ extensions: []
|
|
28
23
|
extra_rdoc_files:
|
29
24
|
- README.md
|
30
25
|
files:
|
31
|
-
- .gitignore
|
32
26
|
- CHANGELOG
|
33
27
|
- MIT-LICENSE
|
34
28
|
- README.md
|
@@ -49,8 +43,8 @@ homepage: http://github.com/joshfrench/rakismet
|
|
49
43
|
licenses: []
|
50
44
|
|
51
45
|
post_install_message:
|
52
|
-
rdoc_options:
|
53
|
-
|
46
|
+
rdoc_options: []
|
47
|
+
|
54
48
|
require_paths:
|
55
49
|
- lib
|
56
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -58,28 +52,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
52
|
requirements:
|
59
53
|
- - ">="
|
60
54
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 3
|
62
|
-
segments:
|
63
|
-
- 0
|
64
55
|
version: "0"
|
65
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
57
|
none: false
|
67
58
|
requirements:
|
68
59
|
- - ">="
|
69
60
|
- !ruby/object:Gem::Version
|
70
|
-
hash: 3
|
71
|
-
segments:
|
72
|
-
- 0
|
73
61
|
version: "0"
|
74
62
|
requirements: []
|
75
63
|
|
76
64
|
rubyforge_project: rakismet
|
77
|
-
rubygems_version: 1.
|
65
|
+
rubygems_version: 1.6.2
|
78
66
|
signing_key:
|
79
67
|
specification_version: 3
|
80
68
|
summary: Akismet and TypePad AntiSpam integration for Rails.
|
81
|
-
test_files:
|
82
|
-
|
83
|
-
- spec/rakismet_model_spec.rb
|
84
|
-
- spec/rakismet_spec.rb
|
85
|
-
- spec/spec_helper.rb
|
69
|
+
test_files: []
|
70
|
+
|