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 CHANGED
@@ -1,3 +1,5 @@
1
+ = 1.1.0
2
+ * Add HTTP Proxy support [Francisco Trindade]
1
3
  = 1.0.1
2
4
  * Fix hash access for Ruby 1.9 [Alex Crichton]
3
5
  = 1.0.0
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 'spec/rake/spectask'
21
- Spec::Rake::SpecTask.new(:spec) do |spec|
22
- spec.libs << 'lib' << '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
@@ -1,6 +1,6 @@
1
1
  ---
2
- :minor: 0
2
+ :minor: 1
3
3
  :build:
4
- :patch: 1
4
+ :patch: 0
5
5
  :major: 1
6
6
 
@@ -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
@@ -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
 
@@ -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 the gemspec command
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.1"
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{2010-10-25}
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
- ".gitignore",
20
- "CHANGELOG",
21
- "MIT-LICENSE",
22
- "README.md",
23
- "Rakefile",
24
- "VERSION.yml",
25
- "lib/rakismet.rb",
26
- "lib/rakismet/middleware.rb",
27
- "lib/rakismet/model.rb",
28
- "lib/rakismet/railtie.rb",
29
- "rakismet.gemspec",
30
- "spec/.rspec",
31
- "spec/rakismet_middleware_spec.rb",
32
- "spec/rakismet_model_spec.rb",
33
- "spec/rakismet_spec.rb",
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.3.7}
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
@@ -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
- Net::HTTP.stub!(:start).and_return([nil, 'valid'])
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
- Net::HTTP.stub!(:start).and_return([nil, 'invalid'])
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
- Net::HTTP.should_receive(:start).with(host).and_yield(http)
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.stub(:start).and_yield(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
- Net::HTTP.should_receive(:start).with("#{Rakismet.key}.#{host}")
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
 
@@ -1,4 +1,4 @@
1
- require File.expand_path "../lib/rakismet"
1
+ require File.expand_path "lib/rakismet"
2
2
 
3
3
  RSpec.configure do |config|
4
4
  config.mock_with :rspec
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakismet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
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: 2010-10-25 00:00:00 -04:00
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
- - --charset=UTF-8
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.3.7
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
- - spec/rakismet_middleware_spec.rb
83
- - spec/rakismet_model_spec.rb
84
- - spec/rakismet_spec.rb
85
- - spec/spec_helper.rb
69
+ test_files: []
70
+
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- .DS_Store
2
- *.tmproj
3
- tmtags
4
- *.swp
5
- *.swo
6
- *.un~
7
- coverage
8
- rdoc
9
- pkg