Module | FacebookFriends |
In: |
facebook_bot/friends.rb
|
Who doesnt love friends? We all love friends. I hope.
Sends a friend request to the given FacebookFriend. Usually used in conjunction with find_friend or find_random_friend, but you can call it all on your own if you want. You can specify a message to send to the friend as well.
fb.add_friend FacebookFriend.new('32423423','Mark Zuckerberg','http://blah.facebook.com/profile.php?id=23423423'), 'i like you' fb.add_friend fb.find_random_friend
# File facebook_bot/friends.rb, line 43 43: def add_friend friend, message='' 44: login 45: url = "/addfriend.php?id=#{friend.id}" 46: post_form_id = get_ids_from_url(url, ['post_form_id'])['post_form_id'] 47: 48: req = @http.post2(url,"post_form_id=#{post_form_id}&message=#{message}&confirmed=1",@opts[:headers]) 49: 50: if req.body.include?('A friend request will now be sent') 51: puts "Successfully sent a friend request to #{friend.name}."; 52: elsif req.body.include?('There is already a friend request') 53: puts "There is already a friend request for #{friend.name}!" 54: else 55: puts "Failed to add #{friend.name} as my friend!" 56: log req 57: end 58: end
Connect to the proper host like emerson.facebook.com, so we can view their profile and do things like post on their wall.
# File facebook_bot/friends.rb, line 62 62: def connect_to_friend friend 63: login 64: connect friend.network_domain 65: end
Finds a friend given a search term (like, uh, their name.) and returns that FacebookFriend If more than one result is found, it will choose one result at random. If you have someone specific in mind, just add_friend directly.
# File facebook_bot/friends.rb, line 32 32: def find_friend term 33: login 34: 35: end
Find a random friend in your networks and returns that FacebookFriend.
fb.find_random_friend
# File facebook_bot/friends.rb, line 20 20: def find_random_friend 21: login 22: doc = hpricot_get_url '/b.php?k=10010' 23: friend_row = (doc/"div.result//dd.result_name/a").random 24: parse_friend_row friend_row 25: end
Gets all of your friends. Returns a Array full of FaceBookFriends. Seeing is believing:
friends = fb.get_friends
Use your imagination.
# File facebook_bot/friends.rb, line 6 6: def get_friends 7: login 8: friends = [] 9: doc = hpricot_get_url '/friends.php' 10: 11: # loop through the friends and collect'em all! pokemon style. 12: (doc/"td.name/a").each do |friend_row| 13: friends << parse_friend_row(friend_row) 14: end 15: friends 16: end