Allow passing *real* arrays to methods that take a "facebook array"
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 6 Mar 2009 21:27:03 +0000 (16:27 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 6 Mar 2009 21:28:07 +0000 (16:28 -0500)
and make sure we json encode the array before sending it up.

framework/Service_Facebook/lib/Horde/Service/Facebook/Notifications.php
framework/Service_Facebook/lib/Horde/Service/Facebook/Request.php

index e0e8671..1b33d46 100644 (file)
@@ -33,9 +33,13 @@ class Horde_Service_Facebook_Notifications extends Horde_Service_Facebook_Base
     /**
      * Sends a notification to the specified users.
      *
+     * @param mixed $to_ids         Either an array of uids or a string
+     *                              delimited list of uids.
+     * @param string $notification  A FBML string for the notification.
+     * @param string $type          Either 'user_to_user' or 'app_to_user'
+     *
      * @throws Horde_Service_Facebook_Exception
      * @return A comma separated list of successful recipients
-     * @error  API_EC_PARAM_USER_ID_LIST
      */
     public function &send($to_ids, $notification, $type)
     {
@@ -45,7 +49,7 @@ class Horde_Service_Facebook_Notifications extends Horde_Service_Facebook_Base
                                                Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
         }
 
-        return $this->callMethod('facebook.notifications.send',
+        return $this->_facebook->callMethod('facebook.notifications.send',
             array('to_ids' => $to_ids,
                   'notification' => $notification,
                   'type' => $type,
@@ -72,7 +76,7 @@ class Horde_Service_Facebook_Notifications extends Horde_Service_Facebook_Base
             throw new Horde_Service_Facebook_Exception('session_key is required',
                                                Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
         }
-        return $this->callMethod('facebook.notifications.sendEmail',
+        return $this->_facebook->callMethod('facebook.notifications.sendEmail',
             array('recipients' => $recipients,
                   'subject' => $subject,
                   'text' => $text,
index fffeb1f..157d13e 100644 (file)
@@ -86,6 +86,15 @@ class Horde_Service_Facebook_Request
      */
     protected function _finalizeParams($method, &$params)
     {
+        // Run through the params and see if any of them are arrays. If so,
+        // json encode them, as per the new Facebook API guidlines.
+        // http://www.facebook.com/developers/message.php#msg_351
+        foreach ($params as &$param) {
+            if (is_array($parm)) {
+                $param = json_endcode($param);
+            }
+        }
+
         $this->_addStandardParams($method, $params);
         // we need to do this before signing the params
         $this->_convertToCsv($params);