-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Creating the Client
var akismet = require('akismet').client(options);
where options
must include the blog url and Akismet API key. Rest of the options
are optional and default values are as shown below:
options = {
blog: '',
apiKey: null,
host: 'rest.akismet.com',
endPoint: options.apiKey + '.' + options.host,
port: 80,
userAgent: 'Generic Node.js/1.0.0 | Akismet 2.4.0',
charset: 'utf-8',
debug: false,
}
For example:
var akismet = require('akismet').client({
blog: 'http://my.blog.com',
apiKey: 'myakismetapikey123'
});
Verifying the API Key
akismet.verifyKey(callback);
where callback
takes four arguments: err
, verified
, status
and headers
. verified
will be true
if the API key was successfully verified. status
and headers
will contain response status code and headers.
For example:
akismet.verifyKey(function(err, verified, status, headers) {
if (verified)
util.log('API key successfully verified.');
else
util.log('Unable to verify API key.');
});
Checking for Spam
akismet.checkSpam(args, callback);
where args
contain query string parameters as key/value pairs. callback
takes four arguments: err
, spam
, status
and headers
. spam
will be true
if the Akismet API identifies the comment as spam.
For example:
akismet.checkSpam({
user_ip: '1.1.1.1',
permalink: 'http://www.my.blog.com/my-post',
comment_author: 'spammer',
comment_content: 'spamming your comments'
}, function(err, spam, status, headers) {
if(spam)
util.log('Spam caught.');
else
util.log('Not spam');
});
Sending Feedback to Akismet
akismet.submitSpam(args, callback);
akismet.submitHam(args, callback);
If the Akismet API returns false positives or false negatives you can send feedback to the API with these functions. Their usage is the same as checkSpam
. args
contain query string parameters as key/value pairs. callback
takes three arguments: err
, status
and headers
.
For example:
akismet.submitSpam({
user_ip: '1.1.1.1',
permalink: 'http://www.my.blog.com/my-post',
comment_author: 'spammer',
comment_content: 'spamming your comments'
});