Coder Social home page Coder Social logo

quilt-akismet's Introduction

A Tapestry 5 Module for Akismet API compatible services

This is Tapestry 5 IOC Module for interacting with services compatible to the Akismet API (http://akismet.com/development/api/). This includes Akismet itself (http://akismet.com/) as well as the free and open source alternative TypePad AntiSpam (http://antispam.typepad.com/).

This project is strongly based on the work by Michael J. Simons, java-akismet, but modified in order to be simpler in the context of a Tapestry 5 module and to take advantage of this as well.

Deployment and configuration

Download the source code and do a Maven install with the following parameters:

mvn install -DargLine="-DakismetApiKey=[YOUR API KEY] -DakismetConsumer=[YOUR SITE URL]"

Add the dependency on your project’s pom.xml like this:

	<dependency>
		<groupId>com.raulmt</groupId>
		<artifactId>quilt-akismet</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</dependency>

Finally, configure your API Key (you can obtain one for free if you use TypePad AntiSpam here: http://antispam.typepad.com/info/get-api-key.html) and API Consumer (the URL of your site) by contributing the following symbols in your app module:

	public void contributeApplicationDefaults(MappedConfiguration<String, String> configuration) {
		configuration.add(AkismetSymbols.API_CONSUMER, "[YOUR SITE URL]");
		configuration.add(AkismetSymbols.API_KEY, "[YOUR API KEY]");
	}

There are others symbols to use another service (the default is TypePad AntiSpam) or to specify the exact API endpoint you want to use.

And done!

Usage

Just inject the Akismet service and check your comments! The service’s methods natively receive a AkismetComment object, but if you provide a coercion to this class from your own Comment class, you can pass them directly to the service.

Contributing a coercion

public static void contributeTypeCoercer(final org.apache.tapestry5.ioc.Configuration<CoercionTuple> configuration) {
		
		configuration.add(new CoercionTuple<Comment, AkismetComment>(Comment.class, AkismetComment.class, new Coercion<Comment, AkismetComment>() {

					@Override
					public AkismetComment coerce(Comment input) {
						AkismetComment output = new AkismetComment();
						// set other fields of AkismetComment from your Comment class
						output.setCommentContent(input.getText());
						// ...
						return output;
					}
				}));
	}

Using the service in a Page class

@Inject
private Akismet<Comment> akismet;

@Property
private Comment comment;

// ...

void onSuccess() {
	if (akismet.commentCheck()) {
		// this comment is SPAM!!
	}
	// ...
}

quilt-akismet's People

Contributors

raulmt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.