Skip to main content

Twitter Plugin for Open BlueDragon

I finally got a chance to put some time in on a Twitter plugin for Open BlueDragon, and I'm happy to report it's coming along very nicely! The plugin API for OpenBD is really easy to dig into so I thought a Twitter plugin would be as good an exercise as any to get my feet wet. I'm planning a series of blog posts illustrating how to write plugins for OpenBD using the Twitter plugin as an example, so look for that before long.

If you aren't familiar with the plugin API for OpenBD, this is a really slick way for you to add tags and functions to OpenBD that become available natively within your OpenBD instance. The plugin code is written in Java (don't worry, it's not daunting at all), and you then drop a JAR file into your WEB-INF/lib directory. When OpenBD fires up it detects the plugin, registers the functions and tags contained within the plugin, and they're then available for you to use in your CFML code.

You can learn more about the plugin API on the OpenBD wiki, and Alan Williamson also has a great blog post about it. Note that you can do much more than add tags and functions; you can also listen for events occurring inside OpenBD itself and act on these events, and even call CFCs from within your plugin. Very powerful stuff. OpenBD ships with a plugin for IRC, and spreadsheet, wiki, and JavaScript plugins are also implemented via the plugin architecture, and they're available on the OpenBD download page.

But I digress. ;-) The main reason for this post is to give people an overview of how the Twitter plugin is working thus far, but more importantly to ask for your help. Creating a Twitter object with a TwitterNew() function and subsequently calling methods on that was really easy, but of course we CFMLers love our tags, so I also created a CFTWITTER tag. What I don't want to do, however, is add an ACTION attribute to the CFTWITTER tag for every method available on the object, so if people have thoughts on how they'd like the tag to work I'd love some opinions.

So what can you DO with the Twitter plugin for OpenBD? Well, pretty much anything you can do with the Twitter API. Basically I took the excellent jTwitter Java library and rolled that in the OpenBD plugin, and this exposes Twitter functionality natively to CFML. Here's some examples.

<!--- create a new twitter object --->
<cfset myTwitter = TwitterNew('username', 'password') />

<!--- get your friends timeline --->
<cfset timeline = myTwitter.getFriendsTimeline() />

<!--- set your status --->
<cfset status = myTwitter.setStatus("Hello from OpenBD!") />

<!--- search twitter --->
<cfset searchResults = myTwitter.search("openbd") />

You get the idea. I've implemented all the methods listed in the jTwitter javadocs, but I'll have documentation for the plugin when I make it available to download. (And hey, if you're a really, really early adopter, email me and I'll send you a copy!)

As for the tags, this is where I need your help. To me it makes complete sense to do this:

<cftwitter action="login"
               screenname="foo"
               password="bar"
               variable="myTwitter" />

But the path I don't think is worthwhile to go down is to start implementing a tag action per method available on the Twitter object, since that gets unnecessarily verbose in my opinion. So I started thinking about having some of the more common things you'd want to do with Twitter available via the tag for convenience, and maybe even let the login and action you want to perform be part of the same single tag. So maybe something like this:

<cftwitter action="setStatus"
               screenname="foo"
               password="bar"
               status="Hello from OpenBD!" />

<cftwitter action="getFriendsTimeline"
               screenname="foo"
               password="bar"
               variable="myTimeline" />

In other words, implement some of the commonly used actions so you can execute these in a single line, but leave the bulk of things available via first instantiating a Twitter object and then calling methods on that. My thinking is if you're going to perform multiple actions it's a lot less verbose to do that with the Twitter object than it is to call a tag each time and pass back in the variable name of the Twitter object on which you want to run the action.

So I'd love to get some opinions on this, and on the idea of a Twitter plugin in general, whether they be good, bad or indifferent.

Comments

atomi said…
Would oAuth support be possible in the plugin (I guess not)? I'm using twitter4j currently only because of oAuth.
Todd Rafferty said…
Looks very cool Matt. Unfortunately the predicament you're trying to avoid is what everyone (that uses tags) is used to.
Matthew Woodward said…
Well, yes and no--for example you can't do nearly as many things with the cfspreadsheet and cfimage tags as you can with the related functions, so there's at least precedent for not having the full gamut of functionality available via the tag. And I'm not going to go down the path of adding a top-level function for every action either; using the spreadsheet functions in CF 9 as an example again, in my opinion there should have been a spreadsheet object that you call methods on as opposed to adding 30+ SpreadsheetXXX() functions to which you're continually having to pass the spreadsheet's variable name.
Matthew Woodward said…
Thanks--I hadn't thought about oAuth. Honestly it wouldn't be that difficult to switch to use twitter4j instead of jtwitter for the underlying functionality if oAuth is important to people. I'll do a comparison and see how twitter4j looks.
Matthew Woodward said…
Looked into twitter4j and it's definitely more comprehensive and seems to be more actively maintained than jtwitter, and looks to be only slightly more cumbersome to work with. jtwitter is dead simple but doesn't support everything that twitter4j does, so probably best to make the change now.I'll look into switching this over and keep everyone posted. Thanks for the suggestion!
Matthew Woodward said…
Updated to use twitter4j--loads more functionality, particularly around lists. I haven't tested the list stuff yet but the bulk of it's working great!
Midway Woods Garden said…
Matthew, when will this be ready for others to use?
Matthew Woodward said…
The function-based stuff is pretty much ready to go, I was just struggling with what should and shouldn't be available in tags.I'll review what I have thus far and throw it up in google code so people can grab it and use what's there now. I'll post back here and do another blog post when it's available. Thanks for the prodding! ;-)
Matthew Woodward said…
Source code and JAR file now available, and I'm working on the documentation:http://code.google.com/p/openbd-twitter-plugin/

Popular posts from this blog

Installing and Configuring NextPVR as a Replacement for Windows Media Center

If you follow me on Google+ you'll know I had a recent rant about Windows Media Center, which after running fine for about a year suddenly decided as of January 29 it was done downloading the program guide and by extension was therefore done recording any TV shows.

I'll spare you more ranting and simply say that none of the suggestions I got (which I appreciate!) worked, and rather than spending more time figuring out why, I decided to try something different.

NextPVR is an awesome free (as in beer, not as in freedom unfortunately ...) PVR application for Windows that with a little bit of tweaking handily replaced Windows Media Center. It can even download guide data, which is apparently something WMC no longer feels like doing.

Background I wound up going down this road in a rather circuitous way. My initial goal for the weekend project was to get Raspbmc running on one of my Raspberry Pis. The latest version of XBMC has PVR functionality so I was anxious to try that out as a …

Setting Up Django On a Raspberry Pi

This past weekend I finally got a chance to set up one of my two Raspberry Pis to use as a Django server so I thought I'd share the steps I went through both to save someone else attempting to do this some time as well as get any feedback in case there are different/better ways to do any of this.

I'm running this from my house (URL forthcoming once I get the real Django app finalized and put on the Raspberry Pi) using dyndns.org. I don't cover that aspect of things in this post but I'm happy to write that up as well if people are interested.

General Comments and Assumptions

Using latest Raspbian “wheezy” distro as of 1/19/2013 (http://www.raspberrypi.org/downloads)We’lll be using Nginx (http://nginx.org) as the web server/proxy and Gunicorn (http://gunicorn.org) as the WSGI serverI used http://www.apreche.net/complete-single-server-django-stack-tutorial/ heavily as I was creating this, so many thanks to the author of that tutorial. If you’re looking for more details on …

The Definitive Guide to CouchDB Authentication and Security

With a bold title like that I suppose I should clarify a bit. I finally got frustrated enough with all the disparate and seemingly incomplete information on this topic to want to gather everything I know about this topic into a single place, both so I have it for my own reference but also in the hopes that it will help others.Since CouchDB is just an HTTP resource and can be secured at that level along the same lines as you'd secure any HTTP resource, I should also point out that I will not be covering things like putting a proxy in front of CouchDB, using SSL with CouchDB, or anything along those lines. This post is strictly limited to how authentication and security work within CouchDB itself.CouchDB security is powerful and granular but frankly it's also a bit quirky and counterintuitive. What I'm outlining here is my understanding of all of this after taking several runs at it, reading everything I could find on the Internet (yes, the whole Internet!), and a great deal…