Class.jaiku.php

From rukapedia
Revision as of 16:00, 19 January 2007 by Peter (talk | contribs)
Jump to: navigation, search

class.jaiku.php is an PHP5 class that allows for basic interaction with Jaiku. At present the useful functionality is limited to updating your Jaiku presence programmatically, and grabbing the current presence message and location for a given Jaiku user (you or someone else).

Jaiku is only beginning to have public API yet -- the only documentation right now is in this comment -- so most of the magic is done be sending standard HTTP POSTs to Jaiku.com -- pretending to be a web browser, in other words. That said, as the API gets revealed, I'm update the class accordingly, it the API is now used to update presence if a developer key is passed.

Source Code

You can browse the source code from a browser, or grab the latest version of the source code using Subversion at:

You can grab the latest version of the source code using Subversion at:

svn://svn.reinvented.net/Jaiku/JaikuPHP

or

http://svn.reinvented.net/Jaiku/JaikuPHP

Sample Usage

Your username and password are the same ones you use to login to Jaiku.com. Your screenname is your Jaiku "screen name," configured in the "Your Account" section of Jaiku.com. Your developerkey can be obtained from http://jaiku.com/api/key (you need to be logged to Jaiku first).

require_once("class.jaiku.php");
$j = new Jaiku("username","password","screenname","developerkey");
$j->GetPresence();
print $j->message . " in " . $j->location . "\n";
$j->UpdatePresence("Updating my presence from PHP!","My City, My Country",'333');

Assuming you have a Jaiku.com account, this code should update your Jaiku presence, location and icon: visit Jaiku.com to see if it worked.

Giving the Code a GUI

If you're running OS X, you can use Pashua to wrap a simple GUI around the class (screen shot here). I've included the source code for this; it's easy to modify to suit your application and preferences.

You can run the Pashua-based code from the command line or, if you want to go one step further, use Platypus to convert the script into a bona fide OS X application; here's a screen shot of my settings for doing so:

PlatypusJaiku.png

To get the Jaiku icon in there, I simply cut and paste it from Jaiku.com (for demonstration purposes only; if you build the app for distribution that would probably be a Bad Thing)

Known Issues

There's no error reporting at all, so if it fails, you'll never know.

Release Notes

2006-01-19 - v0.13

  • Small bugfix: the cURL method used to request the presence message JavaScript changed from POST to GET. POST stopped working.

2006-12-24 - v0.12

  • The class now uses the burgeoning Jaiku API to send a presence update if you create the Jaiku object with a developer key (if you don't pass a key, the old school method is used).
  • References to jaikuname have been changed to screenname for consistency with the website terminology.
  • The GetJaikuSession function is now called automatically by UpdatePresence.

2006-12-24 - v0.11 - Modified the GetPresence function so that it properly handles situations where the presence string parsed out of the JavaScript badge doesn't contain location information -- i.e. doesn't have "in..." at the end.

2006-12-23 - v0.10 - Added basic "presence getting" functionality by adding the GetPresence() function. This uses the same approach as JaikuAdium to grab presence information via the JavaScript "badge" that's constructed for every Jaiku user.

2006-12-22 - v0.8 - Incorporated a patch from Andy Smith to handle new Jaiku security features (have to retrieve and send back a value for '_nonce').