Git Product home page Git Product logo

rakismet's Introduction

Rakismet

Akismet (http://akismet.com/) is a collaborative spam filtering service. Rakismet is easy Akismet integration with Rails and rack apps. TypePad's AntiSpam service and generic Akismet endpoints are supported.

Compatibility

Rakismet >= 1.0.0 work with Rails 3 and other Rack-based frameworks.

Rakismet <= 0.4.2 is compatible with Rails 2.

Getting Started

Add the Rakismet gem to your Gemfile

gem 'rakismet'

Once you've added the Rakismet gem to your Gemfile and installed it with bundle install, you'll need an API key. Head on over to http://akismet.com/signup/ and sign up for a new username.

Configure the Rakismet key and the URL of your application by setting the following in application.rb:

config.rakismet.key = 'your wordpress key'
config.rakismet.url = 'http://yourdomain.com/'

or an initializer, for example config/initializers/rakismet.rb:

YourApp::Application.config.rakismet.key = 'your wordpress key'
YourApp::Application.config.rakismet.url = 'http://yourdomain.com/'

If you wish to use another Akismet-compatible API provider such as TypePad's antispam service, you'll also need to set config.rakismet.host to your service provider's endpoint.

If you want to use a proxy to access akismet (i.e. your application is behind a firewall), set the proxy_host and proxy_port option.

config.rakismet.proxy_host = 'http://yourdomain.com/'
config.rakismet.proxy_port = '8080'

If your Rails app is a multitenant application, you can specify your Rakismet url as a proc:

config.rakismet.url = Proc.new { ApplicationController.current_tenant.url }

Checking For Spam

First, introduce Rakismet to your model:

class Comment
  include Rakismet::Model
end

With Rakismet mixed in to your model, you'll get three instance methods for interacting with Akismet:

  • spam? submits the comment to Akismet and returns true if Akismet thinks the comment is spam, false if not.
  • ham! resubmits a valid comment that Akismet erroneously marked as spam (marks it as a false positive.)
  • spam! resubmits a spammy comment that Akismet missed (marks it as a false negative.)

The ham! and spam! methods will change the value of spam? but their primary purpose is to send feedback to Akismet. The service works best when you help correct the rare mistake; please consider using these methods if you're moderating comments or otherwise reviewing the Akismet responses.

Configuring Your Model

Rakismet sends the following information to the spam-hungry robots at Akismet:

author        : name submitted with the comment
author_url    : URL submitted with the comment
author_email  : email submitted with the comment
comment_type  : Defaults to comment but you can set it to trackback, pingback, or something more appropriate
content       : the content submitted
permalink     : the permanent URL for the entry the comment belongs to
user_ip       : IP address used to submit this comment
user_agent    : user agent string
referrer      : referring URL (note the spelling)

By default, Rakismet just looks for attributes or methods on your class that match these names. You don't have to have accessors that match these exactly, however. If yours differ, just tell Rakismet what to call them:

class Comment
  include Rakismet::Model
  attr_accessor :commenter_name, :commenter_email
  rakismet_attrs :author => :commenter_name, :author_email => :commenter_email
end

Or you can pass in a proc, to access associations:

class Comment < ActiveRecord::Base
  include Rakismet::Model
  belongs_to :author
  rakismet_attrs  :author => proc { author.name },
                  :author_email => proc { author.email }
end

You can even hard-code specific fields:

class Trackback
  include Rakismet::Model
  rakismet_attrs :comment_type => "trackback"
end

Optional Request Variables

Akismet wants certain information about the request environment: remote IP, the user agent string, and the HTTP referer when available. Normally, Rakismet asks your model for these. Storing this information on your model allows you to call the spam? method at a later time. For instance, maybe you're storing your comments in an administrative queue or processing them with a background job.

You don't need to have these three attributes on your model, however. If you choose to omit them, Rakismet will instead look at the current request (if one exists) and take the values from the request object instead.

This means that if you are not storing the request variables, you must call spam? from within the controller action that handles comment submissions. That way the IP, user agent, and referer will belong to the person submitting the comment. If you're not storing the request variables and you call spam? at a later time, the request information will be missing or invalid and Akismet won't be able to do its job properly.

If you've decided to handle the request variables yourself, you can disable the middleware responsible for tracking the request information by adding this to your app initialization:

config.rakismet.use_middleware = false

Additionally, the middleware will send along additional env variables starting with HTTP_ to Akismet. If you wish to block any sensitive user information, use:

config.rakismet.excluded_headers = ['HTTP_COOKIE','HTTP_SENSITIVE']

excluded_headers will default to ['HTTP_COOKIE']

Testing

Rakismet can be configued to tell Akismet that it should operate in test mode - so Akismet will not change its behavior based on any test API calls, meaning they will have no training effect. That means your tests can be somewhat repeatable in the sense that one test won't influence subsequent calls.

You can configure Rakismet for test mode via application.rb:

config.rakismet.test = false # <- default
config.rakismet.test = true

Or via an initializer:

YourApp::Application.config.rakismet.test = false # <- default
YourApp::Application.config.rakismet.test = true

NOTE: When running in Rails, Rakismet will run in test mode when your Rails environment is test or development, unless explictly configured otherwise. Outside of Rails Rakismet defaults to test mode turned off.

Verifying Responses

If you want to see what's happening behind the scenes, after you call one of @comment.spam?, @comment.spam! or @comment.ham! you can check @comment.akismet_response.

This will contain the last response from the Akismet server. In the case of spam? it should be true or false. For spam! and ham! it should be Feedback received. If Akismet returned an error instead (e.g. if you left out some required information) this will contain the error message.

FAQ

Why does Akismet think all of my test data is spam?

Akismet needs enough information to decide if your test data is spam or not. Try to supply as much as possible, especially the author name and request variables.

How can I simulate a spam submission?

Most people have the opposite problem, where Akismet doesn't think anything is spam. The only guaranteed way to trigger a positive spam response is to set the comment author to "viagra-test-123". To simulate a negative (not spam) result, set user_role to administrator, and all other required fields populated with typical values. The Akismet API will always return a false response.

If you've done this and spam? is still returning false, you're probably missing the user IP or one of the key/url config variables. One way to check is to call @comment.akismet_response. If you are missing a required field or there was another error, this will hold the Akismet error message. If your comment was processed normally, this value will simply be true or false.

Can I use Rakismet with a different ORM or framework?

Sure. Rakismet doesn't care what your persistence layer is. It will work with Datamapper, a NoSQL store, or whatever next month's DB flavor is.

Rakismet also has no dependencies on Rails or any of its components, and only uses a small Rack middleware object to do some of its magic. Depending on your framework, you may have to modify this slightly and/or manually place it in your stack.

You'll also need to set a few config variables by hand. Instead of config.rakismet.key, config.rakismet.url, and config.rakismet.host, set these values directly with Rakismet.key, Rakismet.url, and Rakismet.host.


If you have any implementation or usage questions, don't hesitate to get in touch: [email protected].

Copyright (c) 2008 Josh French, released under the MIT license

rakismet's People

Contributors

alexcrichton avatar bnferguson avatar bradly avatar ehoch avatar frankmt avatar joshfrench avatar jrmyward avatar leonid-shevtsov avatar mike-burns avatar ryana avatar stevenharman avatar takestar15 avatar tapajos avatar tilsammans avatar xtian avatar zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rakismet's Issues

Turn off rakismet in tests

Is it possible to turnoff rakismet in tests so that it wouldn't connect to akismet for real, and just return what I explicitly want?

permalink parameter is sent as comment_permalink

I don't know Ruby all that well, but it appears that the permalink parameter is actually being sent as comment_permalink, based on its inclusion in arrays like the one at

[:comment_type, :author, :author_email, :author_url, :content, :permalink].each do |field|

it "should have default mappings" do
    [:comment_type, :author, :author_email, :author_url, :content, :permalink].each do |field|
      fieldname = field.to_s =~ %r(^comment_) ? field : "comment_#{field}".intern
      AkismetModel.akismet_attrs[fieldname].should eql(field)
     end
    AkismetModel::akismet_attrs[:user_role].should eql(:user_role)
end

Can you confirm whether this is the case, and if so, just send the value in the permalink argument?

Problem when validating extra attributes

I am using Rakismet(1.5.3) gem in my Rails(3.2.22) project. Rakismet validates attributes such as author, author_email, author_url, content by default.

My question: I want to validate extra columns in model like post tile, post summary, post content.I tried to merge the post title, post content and post summary and assigned to content field.

post.rb

class Post < ActiveRecord::Base
  include Rakismet::Model
  belongs_to :user

  rakismet_attrs  :author => proc { user.full_name }, 
                           :author_email => proc { user.email }
                           :content => :post_detail

  #Virtual attribute
  def post_detail
    "#{title} #{summary} #{content}"
  end
end

It didn't work as expected viz didn't throw any spam errors even though title, content and summary had spam text(viagra-test-123).
I have also tried Proc :content => proc { "#{title} #{summary} #{content}" }, but no result.

It is working only when we assign title/summary separately to rakismet's content attribute as :content => :title

SocketError (getaddrinfo: nodename nor servname provided, or not known):

Hi Josh:

I'm trying to implement Rakismet 0.4.2 in my Rails 2.3.14 app. I'm getting the following error after clicking "submit request" from my offerings#show view, the page from which our clients submit ProjectRequests (analogous to a blog_post view from which readers would submit comments):

SocketError (getaddrinfo: nodename nor servname provided, or not known):
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:inopen'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in connect' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:53:intimeout'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in timeout' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:inconnect'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in do_start' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:542:instart'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:440:in start' rakismet (0.4.2) lib/rakismet.rb:39:inakismet_call'
rakismet (0.4.2) lib/rakismet/model.rb:45:in spam?' app/models/project_request.rb:59:incheck_for_spam'
app/controllers/users/project_requests_controller.rb:26:in `create'
....

I'm running the app on my development server (http://localhost:3000). I'm connected to the Internet.

I've got the following in my ProjectRequest.rb model:


    class ProjectRequest < ActiveRecord::Base

    include AccountingMethods
    include CurrencyMethods
    include Rakismet::Model

    attr_accessible :title, :details, :budget, :provider_id, :offering_id, :offering_quantity, :request_type_id,
                    :accepted_date, :declined_date, :cancelled_date, :archived_by_user, :archived_by_provider, :workflow_state

    validates_presence_of :title, :details, :request_type_id
    validates_presence_of :budget, :if => :is_hourly?
    validates_numericality_of :budget_number, :greater_than_or_equal_to => 1, :if => :is_hourly?,
                              :message => "must be at least 0.01."

    has_one :project
    has_one :payable_item
    belongs_to :user
    belongs_to :provider
    belongs_to :offering
    belongs_to :offering_type, :foreign_key => :request_type_id

    before_create :check_for_spam

    def author
      self.user.login || "John Smith"
    end

    def author_email
      self.user.email || "[email protected]"
    end

    def comment_type
      "project_request"
    end

    def content
      self.title + ' ' + self.details
    end

    def permalink
      base = 'http://www.genlighten.com'
      if self.offering_id
        offering_title = self.offering.title.slugorize
        base + '/offerings/' + offering_title
      else
        provider_login = self.provider.login
        base + '/provider_profiles/' + provider_login
      end
    end

# following two methods from Ryan Bates' Railscast #65 "Stopping Spam with Akismet"
    def request=(request)
      self.user_ip     = request.remote_ip
      self.user_agent  = request.env['HTTP_USER_AGENT']
      self.referrer    = request.env['HTTP_REFERER']
    end

    def check_for_spam
      self.akismet_approved = !self.spam?
      puts "akismet response = #{self.akismet_response}"
      true
    end```

And the following snippet comes from the top of my project_requests_controller.rb: (the if @project_request.save line is line 26 in the error message above). This controller processes creation of a project request when the user clicks "submit request" on the offerings#show request submission form.

```Ruby/Rails
class Users::ProjectRequestsController < ApplicationController

    include UserMethods
    include CartMethods
    include ProjectRequestMethods
    include ProviderMethods

    layout 'new_default'

    before_filter :login_required
    before_filter :get_user_from_user_id
    before_filter :check_user_access
    before_filter :recover_cart, :only => :update
    before_filter :get_project_request, :only => [ :convert, :show, :update ]
    before_filter :get_offering_from_offering_id, :only => [ :create ]
    before_filter :get_provider_for_project_request, :only => :show
    before_filter :get_provider_from_provider_id, :only => [ :create ]
    before_filter :get_project_for_project_request, :only => [ :show, :update ]

    helper_method :sort_column, :sort_direction


    def create
      @project_request = @user.project_requests.build(params[:project_request])
      @project_request.request = request
      if @project_request.save
        if @project_request.akismet_approved?
          redirect_to convert_user_project_request_path(@user,@project_request)
        else
          # email admin that we've received a spam project_request
          flash[:error] = "We were unable to submit your request. Please contact Genlighten Support at (302)566-5871."
          redirect_to root_path
        end
      else
        flash[:error] = "Failed to submit your request #{@project_request.title}."
        get_offering_for_project_request
        @page_title = "#{@offering.title} | Genlighten"
        get_provider_for_project_request
        get_provider_feedback_summary
        render 'offerings/show'
      end    
    end```

And my config/initializers/rakismet.rb file contains these lines:

Rakismet::KEY = GlobalConfig.rakismet_key
Rakismet::URL = GlobalConfig.rakismet_url
Rakismet::HOST = GlobalConfig.rakismet_host

while my global_config.yml file contains the following:

  # Key and url for use with rakismet gem and Akismet anti-spam API access
  rakismet_key: 'my_akismet_key'
  rakismet_url: 'http://www.genlighten.com'
  rakismet_host: 'http://akismet.com/'

Can you offer any advice or suggestions? I'm guessing I haven't given rakismet the right parameters to find akismet to process the API there?

Thanks very much!

Dean Richardson (still a Rails novice, obviously)
Genlighten.com

permalink never set (or used)

I noticed the readme makes reference to sending the permalink:

permalink     : the permanent URL for the entry the comment belongs to

But then it's never used in the actual code.

Define raskimet attrs with accepts_nested_attributes_for

Hi, first of all cool gem !
I have some doubts about how or where define akismet attributes when dealing with these 2 models:

class Conversation < ActiveRecord::Base
   has_many :messages
   accepts_nested_attributes_for :messages
end
class Message < ActiveRecord::Base
   belongs_to :conversation
   attr_accessor :body, ...
end

My idea is to call spam? before calling Conversation.save in my ConversationsController.
The problem is that I don't know how match asktmet "content" attribute with Message.body

Should I do something like:

class Conversation < ActiveRecord::Base
   has_many :messages
   accepts_nested_attributes_for :messages
   include Rakismet::Model
   rakismet_attrs :content => => proc { message.body } # ??????????
end

Thanks in advance.

ArgumentError: invalid byte sequence in UTF-8 in ruby-1.9.2-p136

Error happens on this line, when I'm trying to call .spam? on a comment:
@post.comments << @comment unless @comment.spam?

Only happens on comments with UTF-8 characters.

Stack trace:
/home/monk/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/cgi/util.rb:7:in `gsub'

/home/monk/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/cgi/util.rb:7:in `escape'

[GEM_ROOT]/gems/rakismet-1.0.1/lib/rakismet.rb:65:in `block (2 levels) in akismet_call'

[GEM_ROOT]/gems/rakismet-1.0.1/lib/rakismet.rb:65:in `each'

[GEM_ROOT]/gems/rakismet-1.0.1/lib/rakismet.rb:65:in `map'

[GEM_ROOT]/gems/rakismet-1.0.1/lib/rakismet.rb:65:in `block in akismet_call'

/home/monk/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/net/http.rb:627:in `start'

/home/monk/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/net/http.rb:490:in `start'

[GEM_ROOT]/gems/rakismet-1.0.1/lib/rakismet.rb:64:in `akismet_call'

[GEM_ROOT]/gems/rakismet-1.0.1/lib/rakismet/model.rb:37:in `spam?'

app/controllers/blog_controller.rb:127:in `comment'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/implicit_render.rb:4:in `send_action'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/abstract_controller/base.rb:150:in `process_action'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/rendering.rb:11:in `process_action'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/abstract_controller/callbacks.rb:18:in `block in process_action'

[GEM_ROOT]/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:450:in `_run__2145909047847877237__process_action__3443656973696802015__callbacks'

[GEM_ROOT]/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'

[GEM_ROOT]/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:93:in `run_callbacks'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/abstract_controller/callbacks.rb:17:in `process_action'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'

[GEM_ROOT]/gems/activesupport-3.0.4/lib/active_support/notifications.rb:52:in `block in instrument'

[GEM_ROOT]/gems/activesupport-3.0.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'

[GEM_ROOT]/gems/activesupport-3.0.4/lib/active_support/notifications.rb:52:in `instrument'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:29:in `process_action'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/rescue.rb:17:in `process_action'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/abstract_controller/base.rb:119:in `process'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/abstract_controller/rendering.rb:41:in `process'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal.rb:138:in `dispatch'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_controller/metal.rb:178:in `block in action'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/routing/route_set.rb:62:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/routing/route_set.rb:62:in `dispatch'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/routing/route_set.rb:27:in `call'

[GEM_ROOT]/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:148:in `block in call'

[GEM_ROOT]/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:93:in `block in recognize'

[GEM_ROOT]/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:89:in `optimized_each'

[GEM_ROOT]/gems/rack-mount-0.6.13/lib/rack/mount/code_generation.rb:92:in `recognize'

[GEM_ROOT]/gems/rack-mount-0.6.13/lib/rack/mount/route_set.rb:139:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/routing/route_set.rb:492:in `call'

[GEM_ROOT]/gems/rakismet-1.0.1/lib/rakismet/middleware.rb:10:in `call'

[GEM_ROOT]/gems/haml-3.0.25/lib/sass/plugin/rack.rb:41:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/head.rb:14:in `call'

[GEM_ROOT]/gems/rack-1.2.1/lib/rack/methodoverride.rb:24:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/params_parser.rb:21:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/flash.rb:182:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/cookies.rb:302:in `call'

[GEM_ROOT]/gems/activerecord-3.0.4/lib/active_record/query_cache.rb:32:in `block in call'

[GEM_ROOT]/gems/activerecord-3.0.4/lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'

[GEM_ROOT]/gems/activerecord-3.0.4/lib/active_record/query_cache.rb:12:in `cache'

[GEM_ROOT]/gems/activerecord-3.0.4/lib/active_record/query_cache.rb:31:in `call'

[GEM_ROOT]/gems/activerecord-3.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'

[GEM_ROOT]/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:415:in `_run_call_callbacks'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/callbacks.rb:44:in `call'

[GEM_ROOT]/gems/rack-1.2.1/lib/rack/sendfile.rb:107:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'

[GEM_ROOT]/gems/actionpack-3.0.4/lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'

[GEM_ROOT]/gems/railties-3.0.4/lib/rails/rack/logger.rb:13:in `call'

[GEM_ROOT]/gems/rack-1.2.1/lib/rack/runtime.rb:17:in `call'

[GEM_ROOT]/gems/rack-1.2.1/lib/rack/lock.rb:11:in `block in call'

:

[GEM_ROOT]/gems/rack-1.2.1/lib/rack/lock.rb:11:in `call'

[GEM_ROOT]/gems/railties-3.0.4/lib/rails/application.rb:168:in `call'

[GEM_ROOT]/gems/railties-3.0.4/lib/rails/application.rb:77:in `method_missing'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:205:in `start_request_handler'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:170:in `block in handle_spawn_application'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/utils.rb:479:in `safe_fork'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:165:in `handle_spawn_application'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:180:in `start'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/rack/application_spawner.rb:128:in `start'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'

:

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'

/home/monk/.rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2/helper-scripts/passenger-spawn-server:99:in `

'

rakismet_attrs not propogated to subclasses

Would be possible to inherit rakismet config to subclasses?

class Comment < ActiveRecord::Base
   rakismet_attrs :author => proc { user.full_name }
end

class DiscussionTopic < Comment
end

DiscussionTopic.akismet_attrs
=> nil

Workaround:

class DiscussionTopic < Comment
   self.akismet_attrs = base_class.akismet_attrs.dup
end

How does the model have access to the request environment?

(hi Josh!)

The readme says:

This means that if you are not storing the request variables, you must call spam? from within the controller action that handles comment submissions. That way the IP, user agent, and referer will belong to the person submitting the comment.

I chased user_ip around the code in a loop and am too stupid to figure out how a model can have access to the request environment. Where does this happen?

List required fields?

Is it possible to list the required values in the README? I'm not a regular Akismet user, so it took a little bit of work and looking and the akismet_responses to figure out what fields were needed. As far as I can tell, the following values need to be populated:

  • author
  • author_email
  • content
  • user_ip
  • user_agent

Just thinking of how to make the gem more approachable from a novice's standpoint.

Doubts with the response

Hi,
I have forced spam? = true by using :author => "viagra-test-123". That's ok, I'm getting true
Is there a way to set/force other comments as true ?
I have tried in the console:

@comment = Comment.find(1) As you know I'm storing user_ip, user_agent and referrer in my model :)
@comment.spam? # false
@comment.spam! # true
@comment.akismet_response # "false" Why do I get "false" here ???!!!
@comment.spam? # true Ok, I'm happy with this true, but:
@comment = Comment.find(1)
@comment.spam? # false Ouch! WHY? I had set it to true before using spam!...

Thanks in advance.

ps: using raskimet 0.4.2, rails 2.3.5, ruby 1.8.7

Have you tested this with Rails 3?

I got uninitialised constant MyController::Rakismet
Also the generator didn't work, I had to create the initialiser manually.
No biggy I'll roll my own Akismet solution, just thought it might be helpful if you mention what versions this gem works with.

Customized parameters

Hello,

I'm using rakismet with some customized parameters.

has_rakismet :author => proc { user.dispname },
           :author_email => proc { user.email },
           :author_url => proc { user.website },
           :comment_type => proc { 'comment' },

However when I'm like that, I get the following error from Akismet : "Missing required field: user_ip.".
But I have a user_ip field in my model, which is appropriately filled.

When I declare the following in my model :

has_rakismet :author => proc { user.dispname },
           :author_email => proc { user.email },
           :author_url => proc { user.website },
           :comment_type => proc { 'comment' },
           :user_ip => :user_ip,
           :user_agent => :user_agent,
           :referrer => :referrer

It works well.
So I guess when we customize some elements, Rakismet isn't able to take the other ones by itself.

Rakisment response issue.

Hi,

I am using Rakismet plugin in my Rails application to check a comment is spam or not.
I am using typepad api for that.


configurations in my initializer and model:

Rakismet::KEY = '8ef8ccb04d9c1f0049041c86371982a6'
Rakismet::URL = 'http://www.postonline.co.uk/'
Rakismet::HOST = 'api.antispam.typepad.com'

has_rakismet
:author => :user_name,
:author_url => :author_url,
:author_email => :email,
:comment_type => :status,
:content => :description,
:permalink => :permalink,
:user_ip => :ip_address,
:referrer => :referrer


I felt that i am doing mistake some where, since i always got the spam response ( @comment.spam? => 'false' ) as false, even if i submit @comment as spam ( @comment.spam! ),
So i tried to trace the rakismet plugin. I got some results while tracing.


  def validate_key
    validate_constants
    akismet = URI.parse(verify_url)
    _, valid = Net::HTTP.start(akismet.host) do |http|
      data = "key=#{Rakismet::KEY}&blog=#{Rakismet::URL}"
      http.post(akismet.path, data, Rakismet::HEADERS)
    end
    self.valid_key = (valid == 'valid')
  end

verify_url => "http://api.antispam.typepad.com/1.1/verify-key"

data => "key=8ef8ccb04d9c1f0049041c86371982a6&blog=http://www.postonline.co.uk/"

Rakismet::HEADERS => {"Content-Type"=>"application/x-www-form-urlencoded", "User-Agent"=>"Rails/2.2.2 | Rakismet/0.3.5"}

_, result = http.post(akismet.path, data, Rakismet::HEADERS)
result => 'valid'


As per my configuration in initializer i can sure that my api key is valid, since validate_key method returns true. And i have got this key from typepad site.

If i write wrong key ( like Rakismet::KEY = 'bangalore is a great city' ) also i am getting the same positive response ( validate_key => true )

also,

@comment.akismet_response => always 'false'
@comment.spam! => "Feedback received."
@comment.spam!? => 'false'

I am using Rails 2.2.2 and Rakismet 0.3.5.

Where i am doing mistake?

Thanks in advance.

With Regards,

Manoj


which is the best way to update my Table and define raskimet attributes ?

Hi,
I read that you have to store optional request variables if you want to process your comments in a later stage.
It means that I have to save user_ip, user_agent and referrer in one of my models.

  1. How and when should I store these values in my model. How do I get them ?
  2. is there a standard way to define my table fields or do I have to create them with a migration ?
  3. How should I store or set other vars like: permalink and author_url ? Should I store these 2 in my model as well ?

Thanks !

Rakismet in test and development environments?

I'm wondering if it's possible to deactivate Rakismet in certain Rails environments. When running the test suite or when there's no internet connection available, I would like Rakismet just to return "not spam" all the time.

I've already looked through the code, but couldn't find a satisfying solution? An option in the environment files (such as config.rakismet.perform = :test # or :live) would be a nice a solution.

What do you think?

user_role is not working

I tried to send user_role parameter to Askimet, but it actually sends 'comment_user_role'.

rakismet_attrs :author => proc { user.full_name },
:author_email => proc { user.email },
:content => :body,
:user_ip => proc { user.current_sign_in_ip },
:user_role => 'administrator',
:comment_type => 'blog-post'

Even I set user_role as 'administrator', it returns true. This is because of https://github.com/joshfrench/rakismet/blob/master/lib/rakismet/model.rb#L17, which converts 'user_role' to 'comment_user_role'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.