WebPurify RubyGem
This gem allows simple interaction with the WebPurify API using Ruby. For more information about WebPurify and the services it offers, check out http://webpurify.com/.
Commands
Filters
Blacklist
Whitelist
Install & Initialize
gem install webpurify
or with bundler
gem webpurify
bundle install
Initialize with
@wp = WebPurify::Client.new('my_api_key')
or
@wp = WebPurify::Client.new({
api_key: 'my_api_key',
endpoint: :us, # can be :us, :eu, :ap (defaults to :us)
enterprise: false, # true for ssl (default false, enterprise key required)
})
Commands
check
Check a string of text for profanity. Returns true if profanity found, false if none.
puts @wp.check('some profane text')
check_count
Check a string of text for profanity. Returns number of words if profanity found, 0 if none.
puts @wp.check_count('profane text')
replace
Check a string of text for profanity. Replaces any found profanity with a provided symbol, and returns the formatted string.
puts @wp.replace('profane text', '*')
return
Check a string of text for profanity. If any found, returns an array of profane words. Else, returns empty array.
p @wp.return('profane text')
Options
All filter commands can take an additional options object, just before the callback. The available options are:
options = {
lang: 'en', # the 2 letter language code for the text you are submitting
semail: 1, # treat email addresses like profanity
sphone: 1, # treat phone numbers like profanity
slink: 1 # treat urls like profanity
}
puts @wp.check('some profane text', options)
add_to_blacklist
Add a word to the blacklist.
@wp.add_to_blacklist('my_awesome_word')
For Deep search, add optional parameter 1 after word:
@wp.add_to_blacklist('my_awesome_word', 1)
remove_from_blacklist
Remove a word from the blacklist.
@wp.remove_from_blacklist('my_awesome_word')
get_blacklist
Get the blacklist as an array of words.
p @wp.get_blacklist
add_to_whitelist
Add a word to the whitelist.
@wp.add_to_whitelist('my_awesome_word')
remove_from_whitelist
Remove a word from the whitelist.
@wp.remove_from_whitelist('my_awesome_word')
get_whitelist
Get the whitelist as an array of words.
p @wp.get_whitelist
To-do:
- Handle error responses
- Tests