Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
index 44661f3..56e3f17 100644 (file)
@@ -1,9 +1,15 @@
+from facebook import Facebook, FacebookError
+import gnome.gconf
 import org.maemo.hermes.engine.provider
 import org.maemo.hermes.engine.facebook.service
 
 class Provider(org.maemo.hermes.engine.provider.Provider):
     """Facebook provider for Hermes. 
 
+       This requires two gconf paths to contain Facebook application keys:
+           /apps/maemo/hermes/key_app
+           /apps/maemo/hermes/key_secret
+       
        Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
        Released under the Artistic Licence."""
 
@@ -28,16 +34,65 @@ class Provider(org.maemo.hermes.engine.provider.Provider):
         """Open the preferences for this provider as a child of the 'parent' widget."""
 
         print "Err, open preferences. OK. Err, right. Hmm."
+        
+        
+    # -----------------------------------------------------------------------
+    def prepare_service(self):
+        # -- Check the environment is going to work...
+        #
+        if (self._gc.get_string('/desktop/gnome/url-handlers/http/command') == 'epiphany %s'):
+            raise Exception('Browser in gconf invalid (see NB#136012). Installation error.')
+
+        key_app    = self._gc.get_string('/apps/maemo/hermes/key_app')
+        key_secret = self._gc.get_string('/apps/maemo/hermes/key_secret')
+        if key_app is None or key_secret is None:
+            raise Exception('No Facebook application keys found. Installation error.')
+        
+        self.fb = Facebook(key_app, key_secret)
+        self.fb.desktop = True
+
+        if self.fb.session_key is None:
+            self.fb.session_key = self._gc.get_string('/apps/maemo/hermes/session_key')
+            self.fb.secret = self._gc.get_string('/apps/maemo/hermes/secret_key')
+            self.fb.uid = self._gc.get_string('/apps/maemo/hermes/uid')
+        
+        # Check the available session is still valid...
+        while True:
+            try:
+                if self.fb.users.getLoggedInUser() and self.fb.session_key:
+                    break
+            except FacebookError:
+                pass
+            self._do_fb_login()
+
 
     
     # -----------------------------------------------------------------------
     def service(self, gui_callback):
-        """Return the service backend. This must be a class which implements the
-           following methods:
-               * get_friends
-               * process_contact
-               * finalise
+        return org.maemo.hermes.engine.facebook.service.Service(self.fb)
+
+
+    # -----------------------------------------------------------------------
+    def _do_fb_login(self):
+        """Perform authentication against Facebook and store the result in gconf
+             for later use. Uses the 'need_auth' and 'block_for_auth' methods on
+             the callback class. The former allows a message to warn the user
+             about what is about to happen to be shown; the second is to wait
+             for the user to confirm they have logged in."""
+        self.fb.session_key = None
+        self.fb.secret = None
+        self.fb.uid = None
         
-           See Service for more details."""
-           
-        return org.maemo.hermes.engine.facebook.service.Service()
+        if self._gui:
+            self._gui.need_auth()
+            
+        self.fb.auth.createToken()
+        self.fb.login()
+        
+        if self._gui:
+            self._gui.block_for_auth()
+          
+        session = self.fb.auth.getSession()
+        self._gc.set_string('/apps/maemo/hermes/session_key', session['session_key'])
+        self._gc.set_string('/apps/maemo/hermes/secret_key', session['secret'])
+        self._gc.set_string('/apps/maemo/hermes/uid', str(session['uid']))

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment