My second Composer package is now available on Packagist.
Bitbucket: Hampel Twitter
This library is a PHP wrapper for the Twitter API and uses the Guzzle HTTP Client library rather than calling cURL directly.
I do quite a lot of work integrating with online services via their APIs and so have used cURL quite extensively. I found myself writing wrappers for cURL and then using those libraries in my API wrappers which were then used in my projects – it all became a bit cumbersome to maintain. Hiding the messiness of cURL by using Guzzle, combined with the neatness of Composer packages, makes life a lot easier.
The built-in mocking capability in Guzzle makes unit testing a breeze too – I’m able to queue pre-generated JSON files (complete with HTTP headers) ready for Guzzle to consume when asked to make API calls – so I can exercise my library without actually making calls over the network or hitting the remote API.
There are plenty of PHP wrappers for the Twitter API out there already, but they are all mostly simple cURL wrappers and don’t add a lot of value beyond hiding the complexity of cURL. I was looking for some higher level functionality from a PHP library, so I’ve written my own.
I have previously written a Twitter library to do most of what I need, but now that I’m using Guzzle and Composer, I’ve taken the opportunity to re-write it from scratch. The main value comes from processing the complex data structures returned by the Twitter API and parsing them into manageable object-based structures with helper functions to give me what I need.
My first attempt was okay, but when I started thinking about how I was going to integrated that into my Laravel applications, I started considering the Eloquent ORM and so re-architected the data structure handling to make life easier in an Eloquent world.
I haven’t yet had a chance to start coding my Laravel application which will use my Twitter library, so it’s too early to tell if I’ve achieved what I was setting out to do.