stoolie

Content filter to determine the XSS, spam and profanity content of text

Installation

The easiest way to install is with Bundler

gem 'stoolie'

Stoolie will work on Ruby 1.8.7+, however the development gems (such as rspec) will only work on 1.9.3+.

Configuration

In Rails, create an initializer such as config/initializers/stoolie.rb and add your SmartFilter rule key and API key

MyApplication::Application.config.stoolie.smart_filter.api_key = 'my api key'
 MyApplication::Application.config.stoolie.smart_filter.rule_key = 'my rule key'

Otherwise, add the keys like so:

Stoolie.configure do |config|
   config.smart_filter = {rule_key: 'rule-key', api_key: 'api-key'}
 end

Default Filter and SmartFilter Thresholds

Stoolie uses Prevoty’s SmartFilter by default, but it's possible to add other clients as long as they implement stoolie's API requirements.

These are the default thresholds.

XSS

Spam

Blacklisted Phrases

Offensive Phrases

All thresholds can be configured using the names given above.

MyApplication.config.stoolie.smart_filter.profanity_threshold = 5

Examples

XSS

> result = Stoolie::Filter.new.analyze('<script>xss is bad.</script>')
 => #<Stoolie::Result>
 > result.is_insecure?
 => true

Spam

> result = Stoolie::Filter.new.analyze('http://mylink.com http://anotherlink.com http://yetanotherlink.com')
 => #<Stoolie::Result>
 > result.is_spam?
 => true

Blacklisted Phrases

> filter = Stoolie::Filter.new
 > result = filter.analyze('some text')
 => #<Stoolie::Result>
 > result.is_blacklisted?
 => false
 > result = filter.analyze('an incredibly racist word')
 => #<Stoolie::Result>
 > result.is_blacklisted?
 => true

Offensive Phrases

> result = Stoolie::Filter.new.analyze('enough curse words to trip the threshold')
 => #<Stoolie::Result>
 > result.is_offensive?
 => true

Extending stoolie

If you want to add your own filter client, create one in lib/stoolie/clients/ and make sure it meets the API requirements:

Instance Attributes

Implement public analyze instance method

return @result = Stoolie::Result.new(self)

Implement these public boolean instance methods

To use your new client instead of SmartFilter, you can set it in your configuration:

MyApplication::Application.config.client = MyFilterClient

Or on the fly

filter = Stoolie::Filter.new(MyFilterClient)

Contributing to stoolie

Copyright © 2014 Aaron Wallis. See LICENSE.txt for further details.