Twitter is the new RSS Reader
In 2008 I thought RSS was an awesome way to stay abreast of what’s going on, but now its 2011 and I find myself using Twitter more often than Google Reader to find new and interesting articles people have written. Readers tweet and retweet articles they find interesting which seems a lower barrier than leaving an “I like this” comment. As an author Twitter also gives you some idea of who is reading your posts and a way to connect with them.
Back in 2008 I created a blog aggregator site http://waywework.it to group the all the people I work with and promote others to share their thoughts. I was so excited I even wrote an article about it.
Now that its 2011, I’ve been asking myself how could I update http://waywework.it for the twitter world of today?
I decide that if we’re going to follow people on twitter that’s what my site should facilitate. When new posts come in it should tweet them letting you see them if you follow @WayWeWorkIT.
Enabling API access to twitter
Once I had this I added the twitter gem to my application. I have to give a shout out John Nunemaker for writing this fantastic gem which made my task so simple.
In the Gemfile
I created a new twitter account @WayWeWorkIT and registered an application at https://dev.twitter.com/apps so I had my OAuth and access tokens.
The only trick was I had to go Application Settings
tab and configure it for Read and Write
access
then regenerate the tokens.
Now that I had the keys and tokens from twitter I had to tell my application to use them without hardcoding them in my code.
This took two steps.
First, configuring the app to read the tokens from the environment in config/initializers/twitter.rb
.
Yes I am somewhat paranoid about accidentally tweeting from development but that if Rails.env.production?
should save me.
Secondly, setting the tokens on the heroku environment (I typed the real tokens instead of the XXXXXXXX’s).
We can test it out (after deploying with git push heroku
)
Great we just tweeted our first tweet for the world to see.
Updating WayWeWork.IT to tweet new posts
The app periodically scans the rss feeds it tracks and when it sees a new post it creates it in the app’s database.
First we add a twitter_username to each feed we’re tracking
Then, add an after_create
callback to tweet each time we create a new post.
Again with the “if Rails.env.production?” paranoia? You do know that you can never be too paranoid :)
With the twitter gem its one line to tweet Twitter.update(tweet)
.
The rest of it is to shorten the title so twitter’s 140 character limit wont cut off the url or the author’s name.
Once this is in we’ll start seeing tweets like
Go ahead and follow @WayWeWorkIT on twitter and you’ll start seeing these blog posts.