Last updated by lance.woodson 1 year ago
Provides an integration point for
Web Purify profanity filtering services. REST aspects are abstracted away and all calls and result handling can be done with plain old groovy via the WebPurifyService class.
Installation
Standard Grails plugin installation. On command line, type:
grails install-plugin webpurify
Configuration
The plugin must have your web purify api key configured before you can use the service. This should be specified in the webpurify.apiKey property in Groovy config:
webpurify.apiKey='REPLACE-WITH-OWN'
Service Injection
The web purify service can be injected into controllers, taglibs, other services and so forth using Grails standard support for dependency injection.
class FooController {
def webPurifyService def someAction = {
// leverage webPurifyService as needed
}
}Service Methods
callCheck: Invokes the
webpurify.live.count method, and invokes a callback closure with true or false if profanity was found or not.
webPurifyService.callCheck(textToCheck, { found ->
// found == true if profanity found, or false otherwise
}) callCheckCount: Invokes the
webpurify.live.count method, and invokes a callback closure with a count of the profane words found.
webPurifyService.callCheckCount(textToCheck, { found ->
// Found will be an integer w/number of profane words found.
}) callReplace: Invokes the
webpurify.live.replace method and invokes a callback closure, passing along a count of profane words and text that has profane words replaced with a series of substitution symbols.
webPurifyService.callReplace(textToCheck, ‘*’, { found, text ->
// found will be count of profane words
// text will be text with profane words replaced with * sequences.
}) callReturn: Invokes the
webpurify.live.return method, and invokes a callback closure, passing along a count of profane words and the list of expletives found.
webPurifyService.callReturn(textToCheck, {found, expletives ->
// found will be count of profane words
// expletives will be list of profane words
}) callAddToBlackList: Invokes the
webpurify.live.addtoblacklist method.
webPurifyService.callAddToBlackList(word)
callAddToWhiteList: Invokes the
webpurify.live.addtowhitelist method.
webPurifyService.callAddToWhiteList(word)
callRemoveFromBlackList: Invokes the
webpurify.live.removefromblacklist method.
webPurifyService.callRemoveFromBlackList(word)
callRemoveFromWhiteList: Invokes the
webpurify.live.removefromwhitelist method.
webPurifyService.callRemoveFromWhiteList(word)
Handling Errors
All methods throw a WebPurifyException if an error response is received from the . The exception will contain a code and message property that contains the error code and message from the service. See the
Web Purify API docs for more information about the specific error codes for each method.
try {
webPurifyService.callAddToBlackList(word)
} catch (e) {
// handle errors, e.code will have error code if specific error handling needed.
}Language Support
All methods accept an optional language property as their last argument to allow you to specify the language you are sending the request in. See the Web Purify
docs on foreign language support for more details.
Synchronous Invocation
As of right now, all operations are synchronous in that the invoking thread is used to execute the HTTP request, process the response and invoke any callback closures. If asynchronous execution is needed, you should leverage the quartz plugin and stick the webpurify calls in a job.
String Encoding
The WebPurifyService contains an encodeString closure that is used to encode strings prior to sending them to the web purify services. The default behavior is to substitute XML entities for their corresponding characters in any text or words sent to Web Purify.
| character | replaced with |
|---|
| & | & |
| “ | " |
| “ | ' |
| > | > |
| < | < |
If custom behavior is needed here, replace the closure in BootStrap.groovy:
class BootStrap {
def webPurifyService def init = { servletContext ->
webPurifyService.encodeString = { string ->
// manpipulate string as needed
}
}
}