Created
June 12, 2012 11:40
-
-
Save cgallagher/2917030 to your computer and use it in GitHub Desktop.
Match friends who are also using an app and see if they are also installed in the db.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def match_friends | |
# now just find the friends of the user who are also using the app. | |
begin | |
res = Bookface::Graph.request("fql", { :q=> "SELECT uid, name, pic_square FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())", :access_token => access_token }) | |
rescue | |
res = nil | |
end | |
friend_ids = [] | |
# retrieve friend list from graph and compile a list of friends who are registered - aww friend | |
unless res.nil? or res["data"].nil? | |
res["data"].map do |friend| | |
user = User.find_by_fbid(friend["uid"]) | |
friend_ids << user.id unless user.nil? | |
end | |
end | |
# clear existing friends - aww NO friend | |
Friendship.where("user_id = ? or friend_id = ?", self.id, self.id).destroy_all | |
# create friendships - aww NEW friend | |
friend_ids.each do |friend_id| | |
Friendship.create( { :user_id => self.id, :friend_id => friend_id } ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment