Building a Tumblelog with Gimme Bar and PHP
One of the coolest things about working on Gimme Bar has been the opportunity to build a platform. While most folks interact with our service via the web site, the site is just one application built on top of the Gimme Bar content collection and curation system. Our web site interacts with the system via our HTTP API, which is open to everyone, not just our internal team. That means that anyone can build applications on top of our platform to suit their own needs or interests.
To demonstrate this, I built GimmeMe, a simple tumblelog-type web app that's powered by Gimme Bar. It uses methods in our API that don't require authentication, so you don't need to register with us to use it. And it's a drop-in, set-one-option-and-go install, so you don't need to fiddle with a bunch of stuff to use it (but you can if you want).
To install the web app yourself, you'll need a web server with:
- PHP 5.2.x or above
- APC 3.0.8 or above
Install as follows:
- Download the source code as a .zip or .tar.gz from the project's download page
- Decompress the files somewhere under your web server's document root
- Edit the $config['username'] value in index.php 4 .Optionally set the $config['gb_addthis_pubid'] value to include AddThis widgets, if you're into that kind of thing
- Load the appropriate URL in your web browser to view the install on your web server
If you're a developer type, you'll probably want to poke around the source code in the GitHub repo. The main work is done by libs/GimmeMe.php, which handles grabbing data from the API, caching it, and rendering the html.
We load the data using the GET /public/assets/:username method. This returns a JSON object with an array of asset data in the records propert. We decode the response JSON into a PHP object (the $assets variable), and add a couple properties that we'll use in the html template. Then we cache the object in APC, and return it. Next time around, if the cached object has not expired, it will just pull it from APC and return it, so we don't make more requests to the API than necessary.
The GimmeMe::render() method loops through the assets we retrieved and makes each one into a GimmeAsset object. GimmeAssets are view objects used by the Mustache templating library to encapsulate display logic, so we set up special methods or data massage in there. After we set those up for each asset, the entire data structure is passed to the Mustache library for rendering, using the a€˜page' template defined in templates\templates.php.
Right now I also am including a a simple router class at vendors\Router.php. We'll need this for stuff that would involve different URLs, like paging back through assets or loading single-asset pages, but I haven't quite gotten that far.
I'd be remiss in not mentioning http://hereslookingathue.com/, a collection of beautiful imagery collected and organized by Gimme Bar user hereslookingathue. It's another cool example powered by our public API methods.
Hopefully this gives you a taste of what's possible with the Gimme Bar API. Most read-only things, like embeddable w
Truncated by Planet PHP, read more at the original (another 879 bytes)