twitter snippets

How to get Facebook like and Twitter share counts with Ruby

Tagged facebook, like, twitter, share  Languages ruby
def facebook_likes(url)
    data = open("http://graph.facebook.com/?ids=#{URI.escape(url)}").read
    data = JSON.parse(data)
    data[url]['shares']
  end

  def twitter_shares(url)
    data = open("http://urls.api.twitter.com/1/urls/count.json?url=#{URI.escape(url)}").read
    data = JSON.parse(data)
    data['count']
  end

Twitter type "followers, following database schema" for Rails/ActiveRecord

Tagged active_record, twitter, schema, follower, following  Languages ruby

Draft schema for Twitter type followers, following functionality:

create_table "followers", :force => true do |t|
    t.integer "leader_id"
    t.integer "follower_id"
end

add_index "followers", ["leader_id", "follower_id"], :name => "index_followers_on_leader_id_and_follower_id", :unique => true

Just an idea, haven't tested this yet.

Update: railscasts.com has published an article on how to use self-referential associations for this purpose: http://railscasts.com/episodes/163-self-referential-association