Class: Twitterland::TwitterCounter

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/twitterland/twitter_counter.rb

Class Method Summary collapse

Class Method Details

.show(username, results = 365) ⇒ Object

Get Twitter follower stats for a user

Twitterland::TwitterCounter.show('bradleyjoyce')

returns:

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


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/twitterland/twitter_counter.rb', line 29

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