Coder Social home page Coder Social 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

Stargazers

 avatar Tim Herby avatar Mikhail Kuzmin avatar  avatar  avatar Surya Tripathi avatar Fayi FB avatar  avatar Benjamin avatar Faruk Celik avatar Jason Carrell avatar mihey avatar Mitch Dempsey avatar Kyle Decot avatar Brock Batsell avatar Suhair Hassan E avatar Arvid Andersson avatar Gimi Liang avatar Evgeny avatar Ryan Oberholzer avatar Omar Karim avatar Marc Remolt avatar Jason Weathered avatar Gavin Morrice avatar Sasha Koss avatar Wong Liang Zan avatar Andy Wang avatar Dzmitry Ilyashevich avatar Ben Matz avatar Warren Li avatar Pavel Evstigneev avatar  avatar Tom Cocca avatar Matt Yoho avatar W@ng avatar Rodrigo Tassinari de Oliveira avatar Diego Carrion avatar Ed Wildgoose avatar John avatar Lon Baker avatar  avatar David Genord II avatar Camilo Lopez avatar Lalit Shandilya avatar Brandon Hicks avatar Joel AZEMAR avatar Nilesh Chaudhari avatar Jim Jones avatar James Miller avatar Benjamin Lim avatar Arun Agrawal avatar Hans Petter Wilhelmsen avatar Libin Pan avatar Paolo Negri avatar Ladi avatar  avatar Chris Johnson avatar Bill Turner avatar Aaron Gibralter avatar George avatar  avatar Patrick Crowley avatar Anthony Underwood avatar Ravil Bayramgalin avatar Jonas von Andrian avatar Hemant Kumar avatar Brian Smith avatar

Watchers

Anthony Underwood avatar James Cloos avatar  avatar

defender's Issues

Saving a document with a signature doesn't work

When performing a PUT to /[FILTERED]/documents/[FILTERED].json

This is the response I get from defensio:

{"defensio-result"=>{"api-version"=>"2.0", "status"=>"fail", "message"=>"Not found"}}

But I can GET from that URL just fine:

>> HTTParty.get("http://api.defensio.com/2.0/users/[FILTERED]/documents/[FILTERED].json")
=> {"defensio-result"=>{"allow"=>false, "profanity-match"=>nil, "signature"=>"[FILTERED]", "spaminess"=>nil, "api-version"=>"2.0", "classification"=>"", "status"=>"pending", "message"=>""}}

Mass assignment

Currently when I try to invoke the false_positive! method then I receive a mass assignment exception. This is because the gem is using update_attributes.

I'd prefer not to add the spam attribute in attr_accessible a possible solution would be to change the update_attributes method calls to update_attribute

What do you think? If you want I can make those changes and send a pull request.

Using an initializer

Hi, I see I need to define my API key for every Spammable module, is there a way to use an initializer or a config file instead? Isn't it a better solution to take away configuration from the model?

Add async support

Defensio supports asynchronous requests, and Defender should as well. This might shorten the load times on web sites.

Posting fails!

d.attributes_hash
=> {"author-ip"=>"127.0.0.1", "author-logged-in"=>"false", "client"=>"Defender | 0.2.0 | Henrik Hodne | [email protected]", "type"=>"test", "author-email"=>"[email protected]", "content"=>"Test comment (no funny business)", "document-permalink"=>"http://www.leftclick.com/blog/dumb#comment_9", "parent-document-permalink"=>"http://www.leftclick.com/blog/dumb", "parent-document-date"=>"2010-01-18", "platform"=>"ruby", "author-trusted"=>"false"}
d.save
{"api-version"=>2.0, "status"=>"fail", "message"=>"The following fields are missing but required: client, content, platform, type"}
=> false

The fields are present in the attributes_hash, so what's going on? :/

Report as spam?

Is there a way to report a comment to Defensio as spam? I've looked through the Defender code and I'm not seeing anything.

Defender.test_mode not defined

@ngw @ https://github.com/dvyjones/defender/issues/4#issuecomment-1996995

This doesn't appear to work, test_mode seems undefined at the module level.

  Defender.api_key = 'FOO'
  if Rails.env == 'production'
    Defender.test_mode = false
  else
    Defender.test_mode = true
  end

The only way I found to do this is at the class level (inside the model)

  if Rails.env != 'production'
    configure_defender :api_key => 'FOO', :test_mode => true
  else
    configure_defender :api_key => 'FOO', :test_mode => false
  end

How can I do it?

YARD or TomDoc?

Not to long ago I switched the documentation from YARD to TomDoc. However, I'm not sure whether to keep TomDoc or switch back to YARD.

I think TomDoc looks nice for in-code documentation, and when working on Defender , in-code documentation is nice (that way I don't have to switch around between windows).

However, if you use Defender in your app, I imagine things like RubyDoc.info is nicer, and TomDoc doesn't work well with that.

So, what do you think? Keep TomDoc or switch back to YARD?

Using Defender correctly

Hi, I followed the documentation but without success. Sorry if the body of some comments contain some vulgarity, I'm testing :)

User.last.messages.each do |m|
    puts m.spam?
    puts m.body
    puts m.defensio_data
end; nil

false
Viagra buy viagra
{}
false
Fuck fuck
{}

This is my model: https://gist.github.com/d1ce80aad9ca70f963f0

The empty defensio_data hash makes me think that I'm doing something wrong in my model.

Any clues?

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.