Tracking some basic twitter stats is easy using the grackle ruby library. Without needing any authentication, you can track the number of followers, the number of followings, and the number of statuses for any user. Here's some code to check @stathat twitter stats:
#!/usr/bin/env ruby

require 'rubygems'
require 'stathat'
require 'grackle'
require 'json'

class OpenStruct
        def fields
                @table.keys
        end
end

class TwitterStats
        def initialize
                @client = Grackle::Client.new
                @user_info = {}
        end

        def uinfo(username)
                unless @user_info.has_key?(username)
                        @user_info[username] = @client.users.show.json?(:screen_name => username)
                end
                return @user_info[username]
        end

        def followers(username)
                uinfo(username).followers_count
        end

        def following(username)
                uinfo(username).friends_count
        end

        def statuses_count(username)
                uinfo(username).statuses_count
        end

        def favourites_count(username)
                uinfo(username).favourites_count
        end
end

tstats = TwitterStats.new

StatHat::API.ez_post_value('twitter stathat followers', 'you@example.com', tstats.followers('stathat'))
StatHat::API.ez_post_value('twitter stathat following', 'you@example.com', tstats.following('stathat'))
StatHat::API.ez_post_value('twitter stathat statuses', 'you@example.com', tstats.statuses_count('stathat'))
You can download the code here: twitter.rb.

No comments yet...