ThinkUp Upgrades to Twitter API 1.1

Posted by gina

This past week we upgraded ThinkUp to support Twitter’s API version 1.1. The transition was painless, and ThinkUp came out of it with cleaner, leaner, and smarter application code.

The API 1.1 changes affected ThinkUp in two major ways, and a few minor ones.

First, Twitter API 1.1’s per-endpoint rate limiting meant we had to revisit ThinkUp’s API usage throttling approach. Before 1.1, Twitter gave each user a flat 350 API calls per hour. To use that pool efficiently, we’d written a fair amount of code that rationed the allocation across multiple endpoints. Now that Twitter does that for us, we could delete all that complicated accounting code, its corresponding tests, and related user-facing settings. Now, ThinkUp’s new TwitterAPIEndpoint class manages each endpoint’s path and rate limit, and it decrements the remaining balance as ThinkUp makes a call. Twitter’s new rate limits are generous, and across all the endpoints ThinkUp uses, they give the application more calls per hour than it had before. Twitter also enforces the 1.1 rate limits every 15 minutes instead of every 60, which means ThinkUp users can update their data more often without maxing out.

Second, API 1.1 required ThinkUp to move from consuming XML to JSON Twitter data. This transition was a long time in coming, and the 1.1 deadline was just the nudge we needed to make it happen. Twitter API 1.1 no longer returns data in XML, only JSON, so we had to refactor how ThinkUp parses incoming tweets and users. (Why did we use XML to begin with? Back in 2009, I based the Twitter plugin on code samples from Twitter API: Up and Running by Kevin Makice. Those code samples used XML, and so has ThinkUp—until now.) The JSON switchover was simple if time-consuming, as we had to replace all of our old XML test data with new JSON-formatted data. But the switch had benefits beyond the Twitter plugin. Our new JSONDecoder class wraps PHP’s built-in procedural JSON functions in a smarter, object-oriented interface, and all the ThinkUp plugins that consume JSON can now use it to their advantage.

Finally, we made a few other minor changes to work with Twitter API 1.1 and clean things up:

  • We adjusted the visual layout of tweets in the insights stream to comply with Twitter’s Display Requirements.
  • Twitter API 1.1 deprecated paging on a method ThinkUp used to capture a user’s favorites, so we rejiggered that functionality to use tweet ID’s rather than page numbers. (This change also let us remove two more user-facing plugin settings, which makes for a simpler user interface.)
  • We deleted old code that wasn’t in use but was still hanging around which made unauthorized calls to the search API (no longer allowed without OAuth tokens in API 1.1).

In the process of refactoring, I beefed up test coverage and improved code readability, formatting, and documentation. I won’t be surprised if more adjustments and bugfixes come up once these changes start rolling out to users, but the majority of the work is done.

ThinkUp’s Twitter plugin contains the first lines of code I wrote on this project almost four years ago. Refactoring such old code made me realize just how far ThinkUp has come. These days the project has well-established testing and debugging workflows, code style guidelines, and mock classes that read test data from the local file system instead of from live API endpoints. Back in the day this kind of refactoring would have been an overwhelming undertaking, but thanks to the maturity of the platform and solid test coverage, today it was very straightforward.

Developers, you can pull the source from GitHub right now to test the changes.

Users, expect new stable and beta ThinkUp releases in the next day or two with this upgrade plus more.

ThinkUp loves you! Get more out of the time you spend online. Join ThinkUp Now

  1. akalastortas reblogged this from thinkupapp
  2. nuxnix reblogged this from thinkupapp
  3. anil reblogged this from thinkupapp
  4. thinkupapp posted this