Re-implement Facebook service to use OAuth2 and Graph API. This allows
[hermes] / package / src / org / maemo / hermes / engine / facebook / service.py
index d9b0b4c..ff46c26 100644 (file)
@@ -32,7 +32,7 @@ class Service(org.maemo.hermes.engine.service.Service):
         friends = []
         if self._create_birthday_only:
             for friend in self._friends_without_contact:
-                if friend.has_birthday_date():
+                if friend.is_interesting():
                     friends.append(friend)
                     
         return friends
@@ -78,20 +78,20 @@ class Service(org.maemo.hermes.engine.service.Service):
             if key in data and data[key]:
                 callback(data[key])
         
-        friends_data = self._get_friends_data()
+        friends_data = self.fb.get_friends()
         for data in friends_data:
             friend = Friend(data['name'])
         
-            if 'profile_url' not in data:
-                data['profile_url'] = "http://www.facebook.com/profile.php?id=" + str(data['uid'])
+            if 'link' not in data:
+                data['link'] = "http://www.facebook.com/profile.php?id=" + str(data['id'])
         
             if_defined(data, 'website', friend.add_url)
-            if_defined(data, 'profile_url', friend.add_url)
-            if_defined(data, 'birthday_date', friend.set_birthday_date)
+            if_defined(data, 'link', friend.add_url)
+            if_defined(data, 'birthday', friend.set_birthday_date)
 
-            if_defined(data, 'pic_big', friend.set_photo_url)
+            if_defined(data, 'picture', friend.set_photo_url)
             
-            url = data['profile_url']
+            url = data['link']
             friend.add_url(url)
             self._register_friend(friend)
 
@@ -129,7 +129,8 @@ class Service(org.maemo.hermes.engine.service.Service):
         self._friends_without_contact.add(friend)
         
         for url in friend.get_urls():
-            self._friends_by_url[url] = friend
+            if self.is_profile_url(url):
+                self._friends_by_url[url] = friend
 
         if self._allow_friend_to_match_by_name(friend):
             key = canonical(friend.get_name())
@@ -137,6 +138,13 @@ class Service(org.maemo.hermes.engine.service.Service):
 
 
     # -----------------------------------------------------------------------
+    def is_profile_url(self, url):
+        """Return True if this is a URL for this service."""
+
+        return url and "facebook.com" in url
+
+
+    # -----------------------------------------------------------------------
     def _allow_friend_to_match_by_name(self, friend):
         for url in friend.get_urls():
             if url in self._known_urls:
@@ -150,11 +158,3 @@ class Service(org.maemo.hermes.engine.service.Service):
         self._friends_without_contact.discard(friend)
         self._friends_by_contact[contact] = friend
         self._contacts_by_friend[friend] = contact
-
-
-    # -----------------------------------------------------------------------
-    def _get_friends_data(self):
-        """Returns a list of dicts, where each dict represents the raw data
-           of a friend"""
-        
-        return self.fb.users.getInfo(self.fb.friends.get(), Service.attrs)