net.sf.akismet
Class Akismet

java.lang.Object
  extended bynet.sf.akismet.Akismet

public class Akismet
extends java.lang.Object

Akistmet Java API

Akismet API documentation.

Version:
$Id: Akismet.java,v 1.4 2006/08/06 20:10:00 czarneckid Exp $
Author:
David Czarnecki

Field Summary
static java.lang.String COMMENT_TYPE_BLANK
           
static java.lang.String COMMENT_TYPE_COMMENT
           
static java.lang.String COMMENT_TYPE_PINGBACK
           
static java.lang.String COMMENT_TYPE_TRACKBACK
           
 
Constructor Summary
Akismet(java.lang.String apiKey, java.lang.String blog)
          Construct an instance to work with the Akismet API.
 
Method Summary
protected  boolean akismetCall(java.lang.String function, java.lang.String ipAddress, java.lang.String userAgent, java.lang.String referrer, java.lang.String permalink, java.lang.String commentType, java.lang.String author, java.lang.String authorEmail, java.lang.String authorURL, java.lang.String commentContent, java.util.Map other)
          Generic call to Akismet
 boolean commentCheck(java.lang.String ipAddress, java.lang.String userAgent, java.lang.String referrer, java.lang.String permalink, java.lang.String commentType, java.lang.String author, java.lang.String authorEmail, java.lang.String authorURL, java.lang.String commentContent, java.util.Map other)
          From the API docs, This is basically the core of everything.
 int getHttpResult()
          Return the HTTP status code of the last operation
 boolean isVerifiedKey()
          Check to see if the API key has been verified
 void setProxyAuthenticationConfiguration(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets proxy authentication information.
 void setProxyConfiguration(java.lang.String proxyHost, int proxyPort)
          Sets proxy configuration information.
 void submitHam(java.lang.String ipAddress, java.lang.String userAgent, java.lang.String referrer, java.lang.String permalink, java.lang.String commentType, java.lang.String author, java.lang.String authorEmail, java.lang.String authorURL, java.lang.String commentContent, java.util.Map other)
          From the API docs, This call is intended for the marking of false positives, things that were incorrectly marked as spam.
 void submitSpam(java.lang.String ipAddress, java.lang.String userAgent, java.lang.String referrer, java.lang.String permalink, java.lang.String commentType, java.lang.String author, java.lang.String authorEmail, java.lang.String authorURL, java.lang.String commentContent, java.util.Map other)
          From the API docs, This call is for submitting comments that weren't marked as spam but should have been.
 boolean verifyAPIKey()
          Verify your API key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMENT_TYPE_BLANK

public static final java.lang.String COMMENT_TYPE_BLANK
See Also:
Constant Field Values

COMMENT_TYPE_COMMENT

public static final java.lang.String COMMENT_TYPE_COMMENT
See Also:
Constant Field Values

COMMENT_TYPE_TRACKBACK

public static final java.lang.String COMMENT_TYPE_TRACKBACK
See Also:
Constant Field Values

COMMENT_TYPE_PINGBACK

public static final java.lang.String COMMENT_TYPE_PINGBACK
See Also:
Constant Field Values
Constructor Detail

Akismet

public Akismet(java.lang.String apiKey,
               java.lang.String blog)
Construct an instance to work with the Akismet API.

 Usage:
 

Akismet akismet = new Akismet("Your API key", "http://your.blog.com/"); System.out.println("Testing comment spam: " + akismet.commentCheck("x.y.z.w", "XXX", "", "", "", "", "", "", "VIAGRA! LOTS OF VIAGRA!", null));

You do not need to call verifyAPIKey() before using the commentCheck(String, String, String, String, String, String, String, String, String, java.util.Map), submitSpam(String, String, String, String, String, String, String, String, String, java.util.Map), or submitHam(String, String, String, String, String, String, String, String, String, java.util.Map) methods.

Parameters:
apiKey - Akismet API key
blog - Blog associated with the API key
Throws:
java.lang.IllegalArgumentException - If either the API key or blog is null
Method Detail

getHttpResult

public int getHttpResult()
Return the HTTP status code of the last operation

Returns:
HTTP status code

isVerifiedKey

public boolean isVerifiedKey()
Check to see if the API key has been verified

Returns:
true if the API key has been verified, false otherwise

setProxyConfiguration

public void setProxyConfiguration(java.lang.String proxyHost,
                                  int proxyPort)
Sets proxy configuration information. This method must be called before any calls to the API if you require proxy configuration.

Parameters:
proxyHost - Proxy host
proxyPort - Proxy port

setProxyAuthenticationConfiguration

public void setProxyAuthenticationConfiguration(java.lang.String proxyUsername,
                                                java.lang.String proxyPassword)
Sets proxy authentication information. This method must be called before any calls to the API if you require proxy authentication.

Parameters:
proxyUsername - Username to access proxy
proxyPassword - Password to access proxy

verifyAPIKey

public boolean verifyAPIKey()
Verify your API key

Returns:
true if the API key has been verified, false otherwise

akismetCall

protected boolean akismetCall(java.lang.String function,
                              java.lang.String ipAddress,
                              java.lang.String userAgent,
                              java.lang.String referrer,
                              java.lang.String permalink,
                              java.lang.String commentType,
                              java.lang.String author,
                              java.lang.String authorEmail,
                              java.lang.String authorURL,
                              java.lang.String commentContent,
                              java.util.Map other)
Generic call to Akismet

Parameters:
function - Function used in constructing the URL to Akismet for the proper function to call. Either "comment-check", "submit-spam", or "submit-ham".
ipAddress - IP address of the comment submitter
userAgent - User agent information
referrer - The content of the HTTP_REFERER header should be sent here
permalink - The permanent location of the entry the comment was submitted to
commentType - May be blank, comment, trackback, pingback, or a made up value like "registration"
author - Submitted name with the comment
authorEmail - Submitted email address
authorURL - Commenter URL
commentContent - The content that was submitted
other - In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
Returns:
true if the comment is identified by Akismet as spam, false otherwise

commentCheck

public boolean commentCheck(java.lang.String ipAddress,
                            java.lang.String userAgent,
                            java.lang.String referrer,
                            java.lang.String permalink,
                            java.lang.String commentType,
                            java.lang.String author,
                            java.lang.String authorEmail,
                            java.lang.String authorURL,
                            java.lang.String commentContent,
                            java.util.Map other)
From the API docs, This is basically the core of everything. This call takes a number of arguments and characteristics about the submitted content and then returns a thumbs up or thumbs down. Almost everything is optional, but performance can drop dramatically if you exclude certain elements. I would recommend erring on the side of too much data, as everything is used as part of the Akismet signature."

Parameters:
ipAddress - IP address of the comment submitter
userAgent - User agent information
referrer - The content of the HTTP_REFERER header should be sent here
permalink - The permanent location of the entry the comment was submitted to
commentType - May be blank, comment, trackback, pingback, or a made up value like "registration"
author - Submitted name with the comment
authorEmail - Submitted email address
authorURL - Commenter URL
commentContent - The content that was submitted
other - In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
Returns:
true if the comment is identified by Akismet as spam, false otherwise

submitSpam

public void submitSpam(java.lang.String ipAddress,
                       java.lang.String userAgent,
                       java.lang.String referrer,
                       java.lang.String permalink,
                       java.lang.String commentType,
                       java.lang.String author,
                       java.lang.String authorEmail,
                       java.lang.String authorURL,
                       java.lang.String commentContent,
                       java.util.Map other)
From the API docs, This call is for submitting comments that weren't marked as spam but should have been. It takes identical arguments as comment check."

Parameters:
ipAddress - IP address of the comment submitter
userAgent - User agent information
referrer - The content of the HTTP_REFERER header should be sent here
permalink - The permanent location of the entry the comment was submitted to
commentType - May be blank, comment, trackback, pingback, or a made up value like "registration"
author - Submitted name with the comment
authorEmail - Submitted email address
authorURL - Commenter URL
commentContent - The content that was submitted
other - In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
Returns:
true if the comment is identified by Akismet as spam, false otherwise

submitHam

public void submitHam(java.lang.String ipAddress,
                      java.lang.String userAgent,
                      java.lang.String referrer,
                      java.lang.String permalink,
                      java.lang.String commentType,
                      java.lang.String author,
                      java.lang.String authorEmail,
                      java.lang.String authorURL,
                      java.lang.String commentContent,
                      java.util.Map other)
From the API docs, This call is intended for the marking of false positives, things that were incorrectly marked as spam. It takes identical arguments as comment check and submit spam."

Parameters:
ipAddress - IP address of the comment submitter
userAgent - User agent information
referrer - The content of the HTTP_REFERER header should be sent here
permalink - The permanent location of the entry the comment was submitted to
commentType - May be blank, comment, trackback, pingback, or a made up value like "registration"
author - Submitted name with the comment
authorEmail - Submitted email address
authorURL - Commenter URL
commentContent - The content that was submitted
other - In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
Returns:
true if the comment is identified by Akismet as spam, false otherwise