Back in April 2010, I released a CodeIgniter library for bit.ly and the API has changed quite a bit in the last eighteen months, so I figured it may be time for an update of the library. Eric Barnes did a refactor back in December 2010 to match some of the internal coding standards of CodeIgniter, which I’ve just merged in. That was a small feat unto itself, seeing as I have not touched git, well, since I committed that repo to github.
I’ve gone ahead and updated all of the API’s endpoints that don’t require either XAuth or OAuth, since those require either special access (XAuth) or a more complex flow than a simple API call (OAuth). Stay tuned for when I’ll be adding those in at a later date.
$this->load->library('bitly'); echo $this->bitly->shorten('http://www.example.com/bitly'); result: http://bit.ly/uKkRVR
There are a number of endpoints and different options on how to use the library, so read the README file and if you need more information on the API itself, go read bit.ly’s API documentation. You can get the library from the repo or download the latest version directly.
While the library was built for use in CodeIgniter, it can be used for non-CodeIgniter applications as well, you’d just need to remove the references to CodeIgniter (the “_ci” instance reference and log_message() usage in the constructor, and the “defined(‘BASEPATH’)” reference at the top) and keep the settings either in a separately loaded config file or at the top of the library’s class declaration. Then, instead of using the CI loader, you would simply ‘include’ the library’s class.
UPDATE 2012-07-24: the library was converted into a Spark for CodeIgniter and the repo’s name and link changed.