$ echo 'posterous' | epitaph __________________ // \ || | || | || R.I.P. | || | || posterous | || | || | || ??? - 2016 | || | || | || | || # # # # # | || | | | | | | ...|...||.||||.||.|.
This note retained for historical purposes only
I recently coughed up a PHP library (Github page here) for interacting with the Posterous API. It’s still far from complete, but provides basic support for many of the basic endpoints exposed by the API. Once valid credentials are plugged in (get your API token here) resources on Posterous may be accessed and modified using a familiar, activerecord-esque syntax:
define('POSTEROUS_API_AUTHSTRING', 'firstname.lastname@example.org:password'); define('POSTEROUS_API_TOKEN', 'YOUR-API-TOKEN'); require('posterous-php/posterous.php'); $attributes = array( 'title' => 'new post', 'body' => 'can haz cheezburger', 'display_date' => '2011-04-20' ); // POST a post to /sites/12345/posts: $post = new PosterousPostModel(array('site_id' => 12345)); $response = $post->create($attributes);
The parent-child relationships between resources may also be expressed via dynamic getter and setter methods:
// GET all posts from /sites/12345/posts $site = new PosterousSiteModel(array('id' => 12345)); $posts = $site->posts->all();
$site->posts in this way is functionally equivalent to specifying the
site_id in the
PosterousPostModel above. In other words, the following methods for updating a post are functionally equivalent:
// UPDATE post belonging to $site $site = new PosterousSiteModel(array('id' => 12345)); $response = $site->save(array( 'id' => 1234567, 'title' => 'New Post Title' )); // UPDATE post directly through a PostModel /sites/12345/posts/1234567 $response = new PosterousPostModel()->save(array( 'id' => 1234567, 'site_id' => 12345, 'title' => 'New Post Title' ));
Any of these queries will result in a JSON object being dispatched to the Posterous server. The response (in RESTful fashion, another JSON object) is caught, decoded, and returned as a PHP object. Except for returning the response, very little is done in the way of handling responses or errors. For applications where ruby is an option, it’s probably best to stick to the Official Gem. But for those looking to integrate Posterous support into PHP projects, hopefully this will save some time!