conduit r1243 - in trunk: . conduit/modules/FacebookModule conduit/modules/FacebookModule/pyfacebook scripts



Author: jstowers
Date: Thu Jan 17 20:57:13 2008
New Revision: 1243
URL: http://svn.gnome.org/viewvc/conduit?rev=1243&view=rev

Log:
2008-01-18  John Stowers  <john stowers gmail com>

	* conduit/modules/FacebookModule/FacebookModule.py:
	* conduit/modules/FacebookModule/pyfacebook/__init__.py:
	* conduit/modules/FacebookModule/pyfacebook/no-print-at-import.patch:
	* scripts/update-3rdparty-libs.sh: Update to new pyfacebook



Added:
   trunk/conduit/modules/FacebookModule/pyfacebook/no-print-at-import.patch
Modified:
   trunk/ChangeLog
   trunk/conduit/modules/FacebookModule/FacebookModule.py
   trunk/conduit/modules/FacebookModule/pyfacebook/__init__.py
   trunk/scripts/update-3rdparty-libs.sh

Modified: trunk/conduit/modules/FacebookModule/FacebookModule.py
==============================================================================
--- trunk/conduit/modules/FacebookModule/FacebookModule.py	(original)
+++ trunk/conduit/modules/FacebookModule/FacebookModule.py	Thu Jan 17 20:57:13 2008
@@ -15,11 +15,17 @@
 from conduit.datatypes import Rid
 import conduit.datatypes.File as File
 
-Utils.dataprovider_add_dir_to_path(__file__)
-from pyfacebook import Facebook, FacebookError
-
 from gettext import gettext as _
 
+try:
+    from pyfacebook import Facebook, FacebookError, VERSION
+except ImportError:
+    Utils.dataprovider_add_dir_to_path(__file__)
+    from pyfacebook import Facebook, FacebookError, VERSION
+    
+if VERSION < '0.1':
+    raise Exceptions.NotSupportedError("Incorrect pyfacebook version")
+    
 MODULES = {
     "FacebookSink" :          { "type": "dataprovider" }        
 }

Modified: trunk/conduit/modules/FacebookModule/pyfacebook/__init__.py
==============================================================================
--- trunk/conduit/modules/FacebookModule/pyfacebook/__init__.py	(original)
+++ trunk/conduit/modules/FacebookModule/pyfacebook/__init__.py	Thu Jan 17 20:57:13 2008
@@ -38,8 +38,12 @@
     import simplejson
     RESPONSE_FORMAT = 'JSON'
 except ImportError:
-    from xml.dom import minidom
-    RESPONSE_FORMAT = 'XML'
+    try:
+        from django.utils import simplejson
+        RESPONSE_FORMAT = 'JSON'
+    except ImportError:
+        from xml.dom import minidom
+        RESPONSE_FORMAT = 'XML'
 
 __all__ = ['Facebook']
 
@@ -139,13 +143,22 @@
             ('image', str, []),
             ('invite', bool, []),
         ],
+
+        'sendEmail': [
+            ('recipients', list, []),
+            ('subject', str, []),
+            ('text', str, ['optional']),
+            ('fbml', str, ['optional']),
+        ]
     },
 
     # profile methods
     'profile': {
         'setFBML': [
-            ('markup', str, []),
             ('uid', int, ['optional']),
+            ('profile', str, ['optional']),
+            ('profile_action', str, ['optional']),
+            ('mobile_fbml', str, ['optional']),
         ],
 
         'getFBML': [
@@ -318,8 +331,9 @@
         self._client = client
         self._name = name
 
-    def __call__(self, method, args=None):
-        self._client._add_session_args(args)
+    def __call__(self, method, args=None, add_session_args=True):
+        if add_session_args:
+            self._client._add_session_args(args)
 
         return self._client('%s.%s' % (self._name, method), args)
 
@@ -603,7 +617,7 @@
         """Hashes arguments by joining key=value pairs, appending a secret, and then taking the MD5 hex digest."""
         hasher = md5.new(''.join(['%s=%s' % (x, args[x]) for x in sorted(args.keys())]))
         if secret:
-            hasher.updated(secret)
+            hasher.update(secret)
         elif self.secret:
             hasher.update(self.secret)
         else:
@@ -683,7 +697,7 @@
             raise RuntimeError('Session key not set. Make sure auth.getSession has been called.')
 
         args['session_key'] = self.session_key
-        args['call_id'] = str(int(time.time()) * 1000)
+        args['call_id'] = str(int(time.time() * 1000))
 
         return args
 
@@ -734,6 +748,14 @@
         return 'http://www.facebook.com/%s.php?%s' % (page, urllib.urlencode(args))
 
 
+    def get_app_url(self, path=''):
+        """
+        Returns the URL for this app's canvas page, according to app_name.
+        
+        """
+        return 'http://apps.facebook.com/%s/%s' % (self.app_name, path)
+
+
     def get_add_url(self, next=None):
         """
         Returns the URL that the user should be redirected to in order to add the application.
@@ -786,11 +808,81 @@
 
         return self.get_url('login', **args)
 
+
     def login(self, popup=False):
         """Open a web browser telling the user to login to Facebook."""
         import webbrowser
         webbrowser.open(self.get_login_url(popup=popup))
 
+
+    def check_session(self, request):
+        """
+        Checks the given Django HttpRequest for Facebook parameters such as
+        POST variables or an auth token. If the session is valid, returns True
+        and this object can now be used to access the Facebook API. Otherwise,
+        it returns False, and the application should take the appropriate action
+        (either log the user in or have him add the application).
+
+        """
+        self.in_canvas = (request.POST.get('fb_sig_in_canvas') == '1')
+
+        if self.session_key and (self.uid or self.page_id):
+            return True
+
+        if request.method == 'POST':
+            params = self.validate_signature(request.POST)
+        else:
+            if 'installed' in request.GET:
+                self.added = True
+
+            if 'fb_page_id' in request.GET:
+                self.page_id = request.GET['fb_page_id']
+
+            if 'auth_token' in request.GET:
+                self.auth_token = request.GET['auth_token']
+
+                try:
+                    self.auth.getSession()
+                except FacebookError, e:
+                    self.auth_token = None
+                    return False
+
+                return True
+
+            params = self.validate_signature(request.GET)
+
+        if not params:
+            return False
+
+        if params.get('in_canvas') == '1':
+            self.in_canvas = True
+
+        if params.get('added') == '1':
+            self.added = True
+
+        if params.get('expires'):
+            self.session_key_expires = int(params['expires'])
+
+        if 'friends' in params:
+            if params['friends']:
+                self._friends = params['friends'].split(',')
+            else:
+                self._friends = []
+
+        if 'session_key' in params:
+            self.session_key = params['session_key']
+            if 'user' in params:
+                self.uid = params['user']
+            elif 'page_id' in params:
+                self.page_id = params['page_id']
+            else:
+                return False
+        else:
+            return False
+
+        return True
+
+
     def validate_signature(self, post, prefix='fb_sig', timeout=None):
         """
         Validate parameters passed to an internal Facebook app from Facebook.

Added: trunk/conduit/modules/FacebookModule/pyfacebook/no-print-at-import.patch
==============================================================================
--- (empty file)
+++ trunk/conduit/modules/FacebookModule/pyfacebook/no-print-at-import.patch	Thu Jan 17 20:57:13 2008
@@ -0,0 +1,16 @@
+--- conduit/modules/FacebookModule/pyfacebook/__init__.py	2007-12-30 22:37:14.000000000 +1300
++++ conduit/modules/FacebookModule/pyfacebook/__init__.py	2008-01-18 09:44:47.000000000 +1300
+@@ -42,13 +42,6 @@
+         from django.utils import simplejson
+         RESPONSE_FORMAT = 'JSON'
+     except ImportError:
+-        print 'NOTE: PyFacebook can use simplejson if it is installed, which'
+-        print 'is much faster than XML and also uses less bandwith. Go to'
+-        print 'http://undefined.org/python/#simplejson to download it, or do'
+-        print 'apt-get install python-simplejson on a Debian-like system.'
+-        print ''
+-        print 'Falling back to XML...'
+-
+         from xml.dom import minidom
+         RESPONSE_FORMAT = 'XML'
+ 

Modified: trunk/scripts/update-3rdparty-libs.sh
==============================================================================
--- trunk/scripts/update-3rdparty-libs.sh	(original)
+++ trunk/scripts/update-3rdparty-libs.sh	Thu Jan 17 20:57:13 2008
@@ -12,6 +12,7 @@
 
 #update pyfacebook
 svn export --force http://pyfacebook.googlecode.com/svn/trunk/facebook/__init__.py conduit/modules/FacebookModule/pyfacebook/__init__.py
+patch -p0 < conduit/modules/FacebookModule/pyfacebook/no-print-at-import.patch
 
 #update pybackpack
 wget -qO - http://hg.west.spy.net/hg/python/backpack/archive/tip.tar.gz | tar --wildcards -xzOf - */backpack.py > conduit/modules/BackpackModule/backpack/backpack.py



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]