Thursday, June 30, 2011

BC Strawberries - socialized

The Fraser Valley Strawberry Growers Association had some very specific changes in mind, with regard to their website.  Just some of these changes were the additions of a Twitter and Blog feed to their BC Strawberries home page.

The great thing about Twitter, and Blogger (really the great part about developing now) is that they both offer their feeds as JSON.  JSON can be a pleasure to work with, especially when using PHP or Javascript.  I tend to make heavy use of both, so learning this - well, it felt a little like my birthday.

Twitter, you may not know, imposes a limit on its feed requests.  It's something rather small — 150 requests per hour or so.  Probably you did know this, and you're wondering why I brought it up.

As you can guess, this limit became a problem during testing (during the modify, save, refresh cycle).  Foreseeabley (who knows if that's a word?), it could become a problem during production as well.

An obvious solution is caching the response.  When a solution is obvious, there's often no real reason to look further.  I wrote a Twitter class which did the following:

First, it checked the users session for a response.  If one was stored, that was used.  If not, it requested the feed from Twitter.  There were two usual outcomes here.  The first is that Twitter returned an error message.  Should that be the case, a stored response was retrieved from the database.
If Twitter returned a valid feed, it was then stored in the database and in the user's session, and that response was used.

It seemed to work fairly well.  I did the same for Blogger - though I have encountered no such request limit. (There may well be one. Who knows?)  If there is, this should prevent ugly errors from distracting from the home page's content.

I set up their Blogger account, and skinned it so as to match their website.  When put into production, I removed the session caching as it seemed unnecessary.

But there was one more thing that needed doing, and it was neat.  The FVSGA requested the addition of a video gallery, but only required the inclusion of a very limited number of videos which I'm told wouldn't often change.
Something easy to manage, but which didn't require elaborate back-end integration into their CMS (to keep costs down and save them money) was the goal.  What I did was write some code to convert a list of Youtube links into a video gallery, which you can learn more about here:

The idea is that when managing the content, they need only update a list of links and everything else will happen automatically.  Or as we so often say on the internet, automagically.

Your friend,

No comments:

Post a Comment