For a little less than a year, I’ve been writing code built atop Twitter, specifically Matt Gemmell’s MGTwitterEngine. I’ve got a few things running on this code, which I’ve not talked about publicly (other than minor hints on Twitter), but have been well-received by the few people who have seen it. Still, these projects have needed to extend both MGTwitterEngine and related libraries to add functionality or fix bugs. I’ll spend this blog post documenting some of those changes across the different projects.

MGTwitterEngine

Most of these changes were made to make the engine’s behavior a bit more extensible. Here’s the GitHub repository.

  • MGTwitterEngineID is a typedef for unsigned long long values. Everywhere a user ID or tweet ID is returned, it will return one of these. You will want to check your existing Twitter code to make sure there are no potential Twitpocalypse-related problems, updating old data types to the new MGTwitterEngineID.
  • Subclasses of MGTwitterEngine can now override a new method, -_sendRequest:withRequestType:responseType:, if they want to use custom networking code (such as with an NSURLRequest queue class). I use this to implement both Twitter’s password authentication and OAuth, and decide at runtime which to use.
  • Added a -connectionStarted: method to MGTwitterEngineDelegate, which can be used to update your UI.
  • Fixed a few bugs in the YAJL parser which crashed or parsed incorrectly.

Things I still need to do:

  • In my custom subclass of MGTwitterEngine, I use a class I wrote called TCDownload, which I’ll talk about below. There are still a few references to it in my MGTwitterEngine class; those should be fairly straightforward to remove. Update: Thanks to Uli Kusterer, the dependency on TCDownload has been removed. The changes have been merged from his fork into mine.
  • Add full support for Twitter lists. I have some basic Twitter list functionality working in a private subclass, but far from all of it. There are some problems with the YAJL parser that don’t appear easily fixable with the stock MGTwitterEngine (specifically, the API key for the list description is the same as the key for the user’s bio, and these are overwriting each other internally). I’m going to look into replacing the manual parsers
  • Add full support for new-style retweets. Haven’t started this yet.
  • Add support for geolocation in incoming and outgoing tweets. Haven’t started this yet.

yajl

I’ve forked yajl to support 64-bit tweet IDs, mainly by changing the callback methods and the string parser from strtol to strtoull. Here is the GitHub repository.

SSCore

This is a repository of scattered classes which serve various purposes. There are two classes which are relevant for our discussion, TCDownload and TCOAuthDownload. You will need the TCDownload class if you use the vanilla MGTwitterEngine fork, although I’ll be removing those dependencies. Here is the GitHub repository

  • TCDownload is a generic wrapper that encapsulates an HTTP request to the interwebs. It wraps NSURLRequest and NSURLConnection under the hood. It automatically queues request and gets callbacks on a background thread (although you can change either of these). I use it a few places inside my MGTwitterEngine fork, but removed most of those changes and put them in a subclass.
  • TCOAuthDownload is a subclass of TCDownload which accepts OAuth tokens and sends out requests with the correct headers. It relies on the OAuthConsumer framework, which I’ll talk about below.

OAuthConsumer

This framework deals with OAuth. Twitter has officially announced that basic auth will be dead in June 2010, so getting on the OAuth bandwagon now is a good idea. Here’s my fork of the OAuthConsumer framework on GitHub.

  • Changed the signature code to use Common Crypto instead of the C libraries’ HMAC APIs. This seems to work more consistently on both Mac and iPhone.
  • Added a -parseHTTPKey:value: method which is used to parse extended attributes in OAuth access tokens. Twitter uses this to pass some special metadata, like the username of the logged-in user. Subclasses of OAToken can extend this to parse those tokens.

OAuthery

This isn’t strictly a tool for doing Twitter development, but it can be handy when learning how to implement the OAuth login flow. I posted about it more back in January, and you can find the code and a prebuilt app over at GitHub.

Link