SimpleBackpack: PHP wrapper class for Backpack API

Development of this software has ceased. There won’t be any updates for this in the future.

SimpleBackpack is a simple PHP wrapper class for the Backpack API. It uses curl for API calls and can return SimpleXML objects or the plain xml response. It wraps up almost all available API calls except for two: “Share page with people” and “Unshare yourself from a friend’s page”.
This class was inspired by David Heinemeier Hansson’s ruby wrapper. The curl_exec code originally comes from packagethief’s API wrapper.

Disclaimer

This class comes without any kind of warranty. I hacked this together pretty quickly, so consider it alpha-quality at best. Error handling is abysmal when present at all and i bet there’s some ugly code in there. Please let me know if you encounter problems or have any wishes.

Download

v0.1.2: SimpleBackpack.txt

Version History

  • 0.1.2 – 05/06/05: added support for the “Move item” and “Email page to yourself” api calls, minor code clean-up
  • 0.1.1 – 05/05/21: fixed a bug with “Update title” related to an unexpected linebreak
  • 0.1 – 05/05/20: first public release

Example

The SimpleBackpack constructor takes three parameters: your username, your token and an optional parameter specifying whether to return a SimpleXML object or raw XML. The default setting for the third parameter is raw XML.
Here’s a brief example for how to use this class:

<?php
include('SimpleBackpack.php');
$bp = new SimpleBackpack('username', 'token');
$result = $bp->export_backpack();
echo $result;
?>

This instantiates a new SimpleBackpack object, makes an API call to the export function and echos the result.
If you want a SimpleXML object instead of raw XML returned, instantiate the class like this:

<?php
include('SimpleBackpack.php');
$bp = new SimpleBackpack('username', 'token', 'simplexml');
?>

I’m afraid you’ll have to comb through the source for more details for now, but i’ll try to add more examples and documentation later.

10 Responses

  1. Very nice. I hacked up something similar but far less complete a few days ago which I posted in Backpack — but I’m linking to yours now.

    Comment by Packagethief on May. 22nd, 2005, at 5:58 #

  2. FYI: I added some XML parsing for it — http://blog.mattwalters.net/extending-backpacksimplebackpack-wrapper/

    Comment by matt on Jul. 30th, 2005, at 20:11 #

  3. Does this support SSL usage for the paid plans? I just upgraded and now I’m getting redirects. Tried a few quick code hacks but no luck.

    Comment by Andy on Jul. 31st, 2005, at 1:14 #

  4. SimpleBackpack.php doesn’t appear to use SSL, but if you edit the file, around line 47 you should see where it starts to construct the request URL. You SHOULD be able to just change that from http:// to https:// and have it work. I don’t have one of the SSL accounts though, so can’t test it.

    Hope that helps.

    Comment by matt on Jul. 31st, 2005, at 8:05 #

  5. Matt, many thanks for the XML-parsing layer.
    Andy, no, this class doesn’t support SSL so far. I meant to look into it, but as i don’t have a plan with SSL-support that’s kinda difficult. The class uses curl for api calls, if using https:// instead of http:// as Matt suggested doesn’t work you might find useful information at the php.net curl function reference page.

    Comment by christoph on Aug. 1st, 2005, at 1:32 #

  6. Thanks guys. I think I tried the substitution, but I don’t remember it working. I will look into it further, as I was rushed out the door.

    I hacked together a quick WML page using SimpleBackpack, it was working great until I upgraded my account ;-) So thanks guys.

    If I figure a fix I will let you know.

    Comment by Andy on Aug. 3rd, 2005, at 16:17 #

  7. Is there any way to know if the request fails? Right now, it appears that even if it fails, it still “succeeds”, in the sense that you can’t do something like $bp->create_item($content,$pageid) or die; … that will NEVER die, no matter what.

    Comment by Daniel Drucker on Dec. 11th, 2005, at 4:48 #

  8. Yeah, error handling is pretty much non-existant so far. I’ll have to update this sooner than later anyway with the new backpack features like multiple lists per page &c but i highly doubt that i will get around to this before christmas…

    Comment by christoph on Dec. 13th, 2005, at 0:17 #

  9. FYI: I’ve added in the undocumented multiple lists features in an extension of your class. Let me know if you’re interested in it. I’m still working on getting it cleaned up and published.

    Comment by Core.B on Jun. 12th, 2006, at 14:55 #

  10. Hey … it’s September 2006 now … any hope of updating this to return an error if the request fails?

    Comment by Daniel Drucker on Sep. 13th, 2006, at 18:48 #