npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jimpick/akismet-api

v2.0.0

Published

Nodejs bindings to the Akismet (http://akismet.com) spam detection service

Downloads

10

Readme

Akismet-api

Build Status Dependency Status

Full Nodejs bindings to the Akismet (http://akismet.com) spam detection service.

Features:

  • Promise and callback support
  • Supports node/iojs from 0.8 to 4.1
  • Supports all Akismet API features
  • Uses a modern HTTP client
  • Complete test suite
  • No coffeescript

Upgrading to 2.0? You likely don't need to change anything, but check out the changelog.

Installing

npm install akismet-api

Creating the Client

The blog and key values are required by Akismet. There are a set of other avaliable default options visible in the source, but you likely will not need to change those.

var akismet = require('akismet-api');
var client = akismet.client({
  key  : 'myKey',                   // Required!
  blog : 'http://myblog.com'        // Required!
});

Promises and Callbacks

All of the function methods below support both promises and callbacks! The returned promises use the Bluebird promise library. The following documentation primarily uses the callback version, but to return a promise simply don't provide a callback. Here is an example of the promise version of the verifyKey() function:

client.verifyKey()
.then(function(valid) {
  if (valid) console.log('Valid key!');
  else console.log('Invalid key!');
})
.catch(function(err) {
  console.log('Check failed: ' + err.message);
}):

Verifying your Key

It's a good idea to verify your key before use. If your key returns as invalid, the error field will contain the debug help message returned by Akismet.

client.verifyKey(function(err, valid) {
  if (err) console.log('Error:', err.message);
  if (valid) console.log('Valid key!');
  else console.log('Invalid key!');
});

Checking for Spam

The user_ip, user_agent, and referrer are required options. All other options are optional, but will provide you with better spam detection accuracy.

client.checkSpam({
  user_ip : '123.123.123.123',              // Required!
  user_agent : 'MyUserAgent 1.0 Webkit',    // Required!
  referrer : 'http://google.com',           // Required!
  permalink : 'http://myblog.com/myPost',
  comment_type : 'comment',
  comment_author : 'John Smith',
  comment_author_email : '[email protected]',
  comment_author_url : 'http://johnsblog.com',
  comment_content : 'Very nice blog! Check out mine!'
}, function(err, spam) {
  if (err) console.log ('Error!');
  if (spam) {
    console.log('OMG Spam!');
  } else {
    console.log('Totally not spam');
  }
});

Submitting False Negatives

If Akismet reports something as not-spam, but it turns out to be spam anyways, we can report this to Akismet via this API call.

client.submitSpam({
  user_ip : '123.123.123.123',              // Required!
  user_agent : 'MyUserAgent 1.0 Webkit',    // Required!
  referrer : 'http://google.com',           // Required!
  permalink : 'http://myblog.com/myPost',
  comment_type : 'comment',
  comment_author : 'John Smith',
  comment_author_email : '[email protected]',
  comment_author_url : 'http://johnsblog.com',
  comment_content : 'Very nice blog! Check out mine!'
}, function(err) {
  if (!err) {
    console.log('Spam reported!');
  }
});

Submitting False Positives

If Akismet reports something as spam, but it turns out to not be spam anyways, we can report this to Akismet via this API call.

client.submitHam({
  user_ip : '123.123.123.123',              // Required!
  user_agent : 'MyUserAgent 1.0 Webkit',    // Required!
  referrer : 'http://google.com',           // Required!
  permalink : 'http://myblog.com/myPost',
  comment_type : 'comment',
  comment_author : 'John Smith',
  comment_author_email : '[email protected]',
  comment_author_url : 'http://johnsblog.com',
  comment_content : 'Very nice blog! Check out mine!'
}, function(err) {
  if (!err) {
    console.log('Non-spam reported!');
  }
});

Testing

cd node_modules/akismet-api
npm test

Credits

Author and maintainer is Chris Foster. Development was sponsored by MemoryLeaf Media.

License

Released under the MIT license.

See LICENSE.txt for more information.