Public API‎ > ‎

Public API recipes and examples

Using HTTP outlets

Comments posted to tags may be sent to an HTTP outlet.  An HTTP outlet will send via HTTP POST the tag name and comment to a URL of your choosing.

For example, here is a simple PHP script that receives and displays the outlet message:

 $tagname = $_POST['tag'];
 $comment = $_POST['comment'];
 $theFile = "/tmp/taglets.txt";
 $fh = fopen($theFile, 'a+') or die("Can't open file");
 $record = $tagname . "|" . $comment . "\n";
 fwrite($fh, $record);
} else { ?>
<title> comment tracker</title>
 $theFile = "/tmp/taglets.txt";
 $lines = file($theFile);
 foreach($lines as $line_num => $line) {
    echo $line . "<br>";
 } ?>
If the script is accessed via POST, the tag name and comment are appended to a text file /tmp/taglets.txt.  If the script is accessed via HTTP GET, the file contents are rendered to html.

Wrapping public API calls in the Groovy scripting language

Taglets features an open source reference implementation written in Java.  Developers can wrap these calls in Groovy, and powerful scripting language that integrates well with existing Java classes.

For example, to post a comment to a tag using Groovy and the Java API,

 Typical use of Groovy to drive a Java API call
 This example is a work in progress with respect to long options:
 For now use short option names.

import org.taglets.exception.*

def cli = new CliBuilder(usage: 'groovy tagcomment.groovy -tc [h]')
cli.h(longOpt: 'help', 'usage information')
cli.t(argName:'tagname', longOpt:'tagname', args:1, required: true, 'tag name')
cli.c(argName:'comment', longOpt:'comment', args:1, required: true, 'comment (first 124 chars used)')

def opt = cli.parse(args)
if (!opt) {
if( opt.h ) {

tagName = opt.t
comment = opt.c

try {
    TagCommentClient client = new TagCommentClient()
    TagCommentResponse response = client.postComment(tagName, comment)
    println "Comment post HTTP response code: ${response.getResponseCode()} ${response.getResponseMessage()}"
    println "Comment post succeeded: ${response.succeeded}"
    println "Headers:"
    def headers = response.getHeaderFields()
    headers.each { header -> println "    ${header}" }
} catch (TagletsException e) {

Wordpress Plugin

We've created a Wordpress plugin called Taglets Feeder that sends comments on referenced tags to when you publish a post on your blog.