Giter VIP home page Giter VIP logo

defender's Introduction

Defender

Donate to Defender at Pledgie

Build Status

Wiki | Docs

Defender is a wrapper for the Defensio spam filtering API. From their own site:

More than just another spam filter, Defensio also eliminates malware and other unwanted or risky content to fully protect your blog or Web 2.0 application.

Installing

In Rails 3, add this to your Gemfile and run the bundle command.

gem 'defender'

If you want to live on the bleeding edge, you can use the git repo. YMMV.

gem 'defender', :git => 'git://github.com/dvyjones/defender.git'

For any other kind of web framework, just install the defender gem, and require 'defender' somewhere in your code.

Getting Started

I'm going to assume that you already have a comment model. The comment model is required to have at least a content or body field.

1. Create an initializer

You need to provide Defender with your API key. The preferred way of doing this is with an initializer file. Create a file in the config/initializers folder, and put the following line in it.

Defender.api_key = 'YOUR_API_KEY'

2. Add the required fields to your model

You need to add a boolean field named spam, and a string field named defensio_sig to your model. You should also add a float field named spaminess, although this isn't required. Here's an example migration for Active Record:

class AddDefenderFieldsToComments < ActiveRecord::Migration
  def change
    add_column :comments, :spam, :boolean
    add_column :comments, :defensio_sig, :string
    add_column :comments, :spaminess, :float
  end
end

3. Configure the model

In your model, include Defender::Spammable. If the model attributes match up with what Defender autodetects (check the wiki), you are now good to go! The spam attribute will be automatically updated by Defender when you save the model.

If you need to change any of the attributes, you can pass configure_defender the mappings, like this:

class Comment < ActiveRecord::Base
    include Defender::Spammable
    configure_defender :keys => { 'content' => :data }
end

In this example, 'content' is the Defensio field, and :data is the model attribute.

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b add-resque-support)
  3. Make your changes
  4. Commit your changes (git commit -am "Added support for Resque")
  5. Push to the branch (git push origin add-resque-support)
  6. Create a Pull Request from your branch.
  7. Promote it. Get others to drop in and +1 it.

defender's People

Contributors

sarahhodne avatar ayrton avatar fauxparse avatar

Watchers

Jérémy Lecour avatar James Cloos avatar

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.