Sha256: 1f18570e1e8fcb87a8e0cabd40fa11c311f92a67290cae39af825444572ed45d

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

require 'date'
module Twitterland
  class TwitterCounter
    include HTTParty
    base_uri 'http://twittercounter.com/api'
    format :json
  
    def self.show(username, results=365)
      stats =  get("/", :query => {:username => username, :output => 'json', :results => results})
      totals = stats.delete('followersperdate')
      stats = Mash.new stats
      # map values to integers because strings are a PIA for stats
      [
        "tomorrow_2w", 
        "followers_2w_ago", 
        "followers_yesterday", 
        "followers_current", 
        "friends_current", 
        "next_month", 
        "growth_since_2w",  
        "started_followers", 
        "rank", 
        "user_id", 
        "growth_since", 
        "follow_days", 
        "tomorrow", 
        "next_month_2w", 
        "average_growth", 
        "average_growth_2w"
      ].each do |field|
        stats[field] = stats[field].to_i
      end
      # alias user_name because it's named funky
      stats.username = stats.screen_name = stats.user_name
      stats.totals = totals.map{|key, value| [key.gsub('date', ''), value.to_i]}.sort_by{|date, total| Date.parse(date)}.reverse
      stats
    end
  
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
squeejee-twitterland-0.0.1 lib/twitterland/twitter_counter.rb
squeejee-twitterland-0.0.2 lib/twitterland/twitter_counter.rb
squeejee-twitterland-0.1.1 lib/twitterland/twitter_counter.rb
twitterland-0.1.0 lib/twitterland/twitter_counter.rb
twitterland-0.1.1 lib/twitterland/twitter_counter.rb
twitterland-0.0.1 lib/twitterland/twitter_counter.rb
twitterland-0.0.2 lib/twitterland/twitter_counter.rb
twitterland-0.0.3 lib/twitterland/twitter_counter.rb