Move Friends methods to a dedicated class, fix class header in Fql.php
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 24 Feb 2009 16:00:54 +0000 (11:00 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 25 Feb 2009 19:13:11 +0000 (14:13 -0500)
framework/Service_Facebook/lib/Horde/Service/Facebook.php
framework/Service_Facebook/lib/Horde/Service/Facebook/Fql.php
framework/Service_Facebook/lib/Horde/Service/Facebook/Friends.php [new file with mode: 0644]
framework/Service_Facebook/package.xml

index 89e83af..bfcf779 100644 (file)
@@ -270,59 +270,6 @@ class Horde_Service_Facebook
     }
 
     /**
-     * Returns whether or not pairs of users are friends.
-     * Note that the Facebook friend relationship is symmetric.
-     *
-     * @param string $uids1  comma-separated list of ids (id_1, id_2,...)
-     *                       of some length X
-     * @param string $uids2  comma-separated list of ids (id_A, id_B,...)
-     *                       of SAME length X
-     *
-     * @return array  An array with uid1, uid2, and bool if friends, e.g.:
-     *   array(0 => array('uid1' => id_1, 'uid2' => id_A, 'are_friends' => 1),
-     *         1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
-     *         ...)
-     * @error
-     *    API_EC_PARAM_USER_ID_LIST
-     */
-    public function &friends_areFriends($uids1, $uids2)
-    {
-        return $this->call_method('facebook.friends.areFriends',
-            array('uids1' => $uids1, 'uids2' => $uids2));
-    }
-
-    /**
-     * Returns the friends of the current session user.
-     *
-     * @param int $flid  (Optional) Only return friends on this friend list.
-     * @param int $uid   (Optional) Return friends for this user.
-     *
-     * @return array  An array of friends
-     */
-    public function &friends_get($flid=null, $uid = null)
-    {
-        $params = array();
-        if ($uid) {
-          $params['uid'] = $uid;
-        }
-        if ($flid) {
-          $params['flid'] = $flid;
-        }
-
-        return $this->call_method('facebook.friends.get', $params);
-    }
-
-    /**
-     * Returns the set of friend lists for the current session user.
-     *
-     * @return array  An array of friend list objects
-     */
-    public function &friends_getLists()
-    {
-        return $this->call_method('facebook.friends.getLists');
-    }
-
-    /**
      * Returns groups according to the filters specified.
      *
      * @param int $uid     (Optional) User associated with groups.  A null
index 497b357..e995a8a 100644 (file)
@@ -1,6 +1,12 @@
 <?php
 /**
  * Execute FQL  queries
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org)
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @category Horde
+ * @package Horde_Service_Facebook
  */
 class Horde_Service_Facebook_Fql extends Horde_Service_Facebook_Base
 {
diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Friends.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Friends.php
new file mode 100644 (file)
index 0000000..7d249fa
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Friends methods for Horde_Service_Facebook
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org)
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @category Horde
+ * @package Horde_Service_Facebook
+ */
+class Horde_Servce_Facebook_Friends extends Horde_Service_Facebook_Base
+{
+    /**
+     * Returns whether or not pairs of users are friends.
+     * Note that the Facebook friend relationship is symmetric.
+     *
+     * @param string $uids1  comma-separated list of ids (id_1, id_2,...)
+     *                       of some length X
+     * @param string $uids2  comma-separated list of ids (id_A, id_B,...)
+     *                       of SAME length X
+     *
+     * @return array  An array with uid1, uid2, and bool if friends, e.g.:
+     *   array(0 => array('uid1' => id_1, 'uid2' => id_A, 'are_friends' => 1),
+     *         1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
+     *         ...)
+     * @error
+     *    API_EC_PARAM_USER_ID_LIST
+     */
+    public function &areFriends($uids1, $uids2)
+    {
+        // Session key is *required*
+        if (empty($this->_sessionKey)) {
+            throw new Horde_FaceBook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+
+        return $this->_facebook->call_method('facebook.friends.areFriends',
+            array('uids1' => $uids1,
+                  'uids2' => $uids2,
+                  'session_key' => $this->_sessionKey));
+    }
+
+    /**
+     * Returns the friends of the current session user.
+     *
+     * @param int $flid  (Optional) Only return friends on this friend list.
+     * @param int $uid   (Optional) Return friends for this user.
+     *
+     * @return array  An array of friends
+     */
+    public function &get($flid = null, $uid = null)
+    {
+        // Session key is *required*
+        if (empty($this->_sessionKey)) {
+            throw new Horde_FaceBook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        $params = array();
+        if ($uid) {
+          $params['uid'] = $uid;
+        }
+        if ($flid) {
+          $params['flid'] = $flid;
+        }
+
+        return $this->_facebook->call_method('facebook.friends.get', $params);
+    }
+
+    /**
+     * Returns the set of friend lists for the current session user.
+     *
+     * @return array  An array of friend list objects
+     */
+    public function &getLists()
+    {
+        // Session key is *required*
+        if (empty($this->_sessionKey)) {
+            throw new Horde_FaceBook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        return $this->_facebook->call_method('facebook.friends.getLists',
+             array('session_key' => $this->_sessionKey));
+    }
+
+}
\ No newline at end of file
index 0484780..d69bc34 100644 (file)
@@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
       <dir name="Facebook">
        <file name="Base.php" role="php" />
        <file name="Fql.php" role="php" />
+       <file name="Friends.php" role="php" />
        <file name="Exception.php" role="php" />
        <file name="ErrorCodes.php" role="php" />
        <file name="Request.php" role="php" />
@@ -65,13 +66,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <filelist>
    <install name="lib/Horde/Service/Facebook/Base.php" as="Horde/Service/Facebook/Base.php" />
    <install name="lib/Horde/Service/Facebook/Fql.php" as="Horde/Service/Facebook/Fql.php" />
+   <install name="lib/Horde/Service/Facebook/Friends.php" as="Horde/Service/Facebook/Friends.php" />
    <install name="lib/Horde/Service/Facebook/Exception.php" as="Horde/Service/Facebook/Exception.php" />
    <install name="lib/Horde/Service/Facebook/ErrorCodes.php" as="Horde/Service/Facebook/ErrorCodes.php" />
    <install name="lib/Horde/Service/Facebook/Request.php" as="Horde/Service/Facebook/Request.php" />
    <install name="lib/Horde/Service/Facebook/BatchRequest.php" as="Horde/Service/Facebook/BatchRequest.php" />
    <install name="lib/Horde/Service/Facebook/Auth.php" as="Horde/Service/Facebook/Auth.php" />
    <install name="lib/Horde/Service/Facebook.php" as="Horde/Service/Facebook.php" />
-   
   </filelist>
  </phprelease>
 </package>