Add Friends, Groups, Links, Notes, and Video support. Mostly untested.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 28 Feb 2009 17:21:20 +0000 (12:21 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 28 Feb 2009 17:21:20 +0000 (12:21 -0500)
framework/Service_Facebook/lib/Horde/Service/Facebook.php
framework/Service_Facebook/lib/Horde/Service/Facebook/Friends.php
framework/Service_Facebook/lib/Horde/Service/Facebook/Groups.php [new file with mode: 0644]
framework/Service_Facebook/lib/Horde/Service/Facebook/Links.php [new file with mode: 0644]
framework/Service_Facebook/lib/Horde/Service/Facebook/Notes.php [new file with mode: 0644]
framework/Service_Facebook/lib/Horde/Service/Facebook/Videos.php [new file with mode: 0644]
framework/Service_Facebook/package.xml

index 8a1224f..13a68ad 100644 (file)
@@ -3,9 +3,9 @@
  * Horde_Service_Facebook class abstracts communication with Facebook's
  * rest interface.
  *
- * Code is basically a refactored version of Facebook's
- * facebookapi_php5_restclient.php library, completely ripped apart and put
- * back together in a Horde friendly way.
+ * This code was originally a Hordified version of Facebook's official PHP
+ * client. However, very little of the original code or design is left. I left
+ * the original copyright notice intact below.
  *
  * Copyright 2009 The Horde Project (http://www.horde.org)
  *
@@ -302,177 +302,6 @@ class Horde_Service_Facebook
         return $old;
     }
 
-
-    /**
-     * Returns groups according to the filters specified.
-     *
-     * @param int $uid     (Optional) User associated with groups.  A null
-     *                     parameter will default to the session user.
-     * @param string $gids (Optional) Comma-separated group ids to query. A null
-     *                     parameter will get all groups for the user.
-     *
-     * @return array  An array of group objects
-     */
-    public function &groups_get($uid, $gids)
-    {
-        return $this->call_method('facebook.groups.get',
-            array('uid' => $uid, 'gids' => $gids));
-    }
-
-    /**
-     * Returns the membership list of a group.
-     *
-     * @param int $gid  Group id
-     *
-     * @return array  An array with four membership lists, with keys 'members',
-     *                'admins', 'officers', and 'not_replied'
-     */
-    public function &groups_getMembers($gid)
-    {
-        return $this->call_method('facebook.groups.getMembers', array('gid' => $gid));
-    }
-
-    /**
-     * Retrieves links posted by the given user.
-     *
-     * @param int    $uid      The user whose links you wish to retrieve
-     * @param int    $limit    The maximimum number of links to retrieve
-     * @param array $link_ids (Optional) Array of specific link
-     *                          IDs to retrieve by this user
-     *
-     * @return array  An array of links.
-     */
-    public function &links_get($uid, $limit, $link_ids = null)
-    {
-        return $this->call_method('links.get',
-            array('uid' => $uid,
-                  'limit' => $limit,
-                  'link_ids' => json_encode($link_ids)));
-    }
-
-    /**
-     * Posts a link on Facebook.
-     *
-     * @param string $url     URL/link you wish to post
-     * @param string $comment (Optional) A comment about this link
-     * @param int    $uid     (Optional) User ID that is posting this link;
-     *                        defaults to current session user
-     *
-     * @return bool
-     */
-    public function &links_post($url, $comment='', $uid = null)
-    {
-        return $this->call_method('links.post',
-            array('uid' => $uid,
-                  'url' => $url,
-                  'comment' => $comment));
-    }
-
-
-    /**
-     * Creates a note with the specified title and content.
-     *
-     * @param string $title   Title of the note.
-     * @param string $content Content of the note.
-     * @param int    $uid     (Optional) The user for whom you are creating a
-     *                        note; defaults to current session user
-     *
-     * @return int   The ID of the note that was just created.
-     */
-    public function &notes_create($title, $content, $uid = null)
-    {
-        return $this->call_method('notes.create',
-            array('uid' => $uid,
-                  'title' => $title,
-                  'content' => $content));
-    }
-
-    /**
-     * Deletes the specified note.
-     *
-     * @param int $note_id  ID of the note you wish to delete
-     * @param int $uid      (Optional) Owner of the note you wish to delete;
-     *                      defaults to current session user
-     *
-     * @return bool
-     */
-    public function &notes_delete($note_id, $uid = null)
-    {
-        return $this->call_method('notes.delete',
-            array('uid' => $uid,
-                  'note_id' => $note_id));
-    }
-
-    /**
-    * Edits a note, replacing its title and contents with the title
-    * and contents specified.
-    *
-    * @param int    $note_id  ID of the note you wish to edit
-    * @param string $title    Replacement title for the note
-    * @param string $content  Replacement content for the note
-    * @param int    $uid      (Optional) Owner of the note you wish to edit;
-    *                         defaults to current session user
-    *
-    * @return bool
-    */
-    public function &notes_edit($note_id, $title, $content, $uid = null) {
-        return $this->call_method('notes.edit',
-            array('uid' => $uid,
-                  'note_id' => $note_id,
-                  'title' => $title,
-                  'content' => $content));
-    }
-
-    /**
-     * Retrieves all notes by a user. If note_ids are specified,
-     * retrieves only those specific notes by that user.
-     *
-     * @param int    $uid      User whose notes you wish to retrieve
-     * @param array  $note_ids (Optional) List of specific note
-     *                         IDs by this user to retrieve
-     *
-     * @return array A list of all of the given user's notes, or an empty list
-     *               if the viewer lacks permissions or if there are no visible
-     *               notes.
-     */
-    public function &notes_get($uid, $note_ids = null)
-    {
-        return $this->call_method('notes.get',
-            array('uid' => $uid,
-                  'note_ids' => json_encode($note_ids)));
-    }
-
-
-
-    /**
-     * Uploads a video.
-     *
-     * @param  string $file        The location of the video on the local filesystem.
-     * @param  string $title       (Optional) A title for the video. Titles over 65 characters in length will be truncated.
-     * @param  string $description (Optional) A description for the video.
-     *
-     * @return array  An array with the video's ID, title, description, and a link to view it on Facebook.
-     */
-    public function video_upload($file, $title = null, $description = null)
-    {
-        return $this->call_upload_method('facebook.video.upload',
-            array('title' => $title,
-                  'description' => $description),
-            $file, self::get_facebook_url('api-video') . '/restserver.php');
-    }
-
-    /**
-     * Returns an array with the video limitations imposed on the current session's
-     * associated user. Maximum length is measured in seconds; maximum size is
-     * measured in bytes.
-     *
-     * @return array  Array with "length" and "size" keys
-     */
-    public function &video_getUploadLimits()
-    {
-        return $this->call_method('facebook.video.getUploadLimits');
-    }
-
     /**
      * Calls the specified normal POST method with the specified parameters.
      *
@@ -559,7 +388,7 @@ class Horde_Service_Facebook
     }
 
     /**
-     * TODO: This will probably be replace
+     * TODO: This will probably be replaced
      * @param $method
      * @param $params
      * @param $file
index 3ea85ab..6bb3c2a 100644 (file)
@@ -29,7 +29,7 @@ class Horde_Service_Facebook_Friends extends Horde_Service_Facebook_Base
     public function &areFriends($uids1, $uids2)
     {
         // Session key is *required*
-        if (!$this->_facebook->auth->getSessionKey()) {
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
             throw new Horde_Service_Facebook_Exception('session_key is required',
                                                Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
         }
@@ -37,7 +37,7 @@ class Horde_Service_Facebook_Friends extends Horde_Service_Facebook_Base
         return $this->_facebook->call_method('facebook.friends.areFriends',
             array('uids1' => $uids1,
                   'uids2' => $uids2,
-                  'session_key' => $this->_facebook->auth->getSessionKey()));
+                  'session_key' => $skey));
     }
 
     /**
diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Groups.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Groups.php
new file mode 100644 (file)
index 0000000..6d1ea0c
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Groups methods
+ *
+ * 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_Groups extends Horde_Service_Facebook_Base
+{
+    /**
+     * Returns groups according to the filters specified.
+     *
+     * @param int $uid     (Optional) User associated with groups.  A null
+     *                     parameter will default to the session user.
+     * @param string $gids (Optional) Comma-separated group ids to query. A null
+     *                     parameter will get all groups for the user.
+     *
+     * @return array  An array of group objects
+     */
+    public function &get($uid, $gids)
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        return $this->_facebook->call_method('facebook.groups.get',
+            array('uid' => $uid, 'gids' => $gids, 'session_key' => $skey));
+    }
+
+    /**
+     * Returns the membership list of a group.
+     *
+     * @param int $gid  Group id
+     *
+     * @return array  An array with four membership lists, with keys 'members',
+     *                'admins', 'officers', and 'not_replied'
+     */
+    public function &getMembers($gid)
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        return $this->_facebook->call_method('facebook.groups.getMembers',
+             array('gid' => $gid, 'session_key' => $skey));
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Links.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Links.php
new file mode 100644 (file)
index 0000000..e99bd49
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Links methods
+ *
+ * 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_Links extends Horde_Service_Facebook_Base
+{
+    /**
+     * Retrieves links posted by the given user.
+     *
+     * @param int    $uid      The user whose links you wish to retrieve
+     * @param int    $limit    The maximimum number of links to retrieve
+     * @param array $link_ids (Optional) Array of specific link
+     *                          IDs to retrieve by this user
+     *
+     * @return array  An array of links.
+     */
+    public function &get($uid, $limit, $link_ids = null)
+    {
+        // Require a session
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        return $this->_facebook->call_method('links.get',
+            array('uid' => $uid,
+                  'limit' => $limit,
+                  'link_ids' => json_encode($link_ids),
+                  'session_key' => $skey));
+    }
+
+    /**
+     * Posts a link on Facebook.
+     *
+     * @param string $url     URL/link you wish to post
+     * @param string $comment (Optional) A comment about this link
+     * @param int    $uid     (Optional) User ID that is posting this link;
+     *                        defaults to current session user
+     *
+     * @return bool
+     */
+    public function &post($url, $comment = '', $uid = null)
+    {
+        // Require a session
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        return $this->_facebook->call_method('links.post',
+            array('uid' => $uid,
+                  'url' => $url,
+                  'comment' => $comment,
+                  'session_key' => $skey));
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Notes.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Notes.php
new file mode 100644 (file)
index 0000000..84508f4
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Notes methods.
+ *
+ * Note that these api calls are marked as BETA in the facebook docs.
+ *
+ * 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_Notes extends Horde_Service_Facebook_Base
+{
+    /**
+     * Creates a note with the specified title and content.
+     *
+     * @param string $title   Title of the note.
+     * @param string $content Content of the note.
+     * @param int    $uid     (Optional) The user for whom you are creating a
+     *                        note; defaults to current session user
+     *
+     * @return int   The ID of the note that was just created.
+     */
+    public function &create($title, $content, $uid = null)
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        return $this->_facebook->call_method('notes.create',
+            array('uid' => $uid,
+                  'title' => $title,
+                  'content' => $content,
+                  'session_key' => $skey));
+    }
+
+    /**
+     * Deletes the specified note.
+     *
+     * @param int $note_id  ID of the note you wish to delete
+     * @param int $uid      (Optional) Owner of the note you wish to delete;
+     *                      defaults to current session user
+     *
+     * @return bool
+     */
+    public function &delete($note_id, $uid = null)
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+        return $this->_facebook->call_method('notes.delete',
+            array('uid' => $uid,
+                  'note_id' => $note_id,
+                  'session_key' => $skey));
+    }
+
+    /**
+     * Edits a note, replacing its title and contents with the title
+     * and contents specified.
+     *
+     * @param int    $note_id  ID of the note you wish to edit
+     * @param string $title    Replacement title for the note
+     * @param string $content  Replacement content for the note
+     *
+     * @return bool
+     */
+    public function &edit($note_id, $title, $content)
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+
+        return $this->_facebook->call_method('notes.edit',
+            array('note_id' => $note_id,
+                  'title' => $title,
+                  'content' => $content,
+                  'session_key' => $skey));
+    }
+
+    /**
+     * Retrieves all notes by a user. If note_ids are specified,
+     * retrieves only those specific notes by that user.
+     *
+     * @param int    $uid      User whose notes you wish to retrieve
+     * @param array  $note_ids (Optional) List of specific note
+     *                         IDs by this user to retrieve
+     *
+     * @return array A list of all of the given user's notes, or an empty list
+     *               if the viewer lacks permissions or if there are no visible
+     *               notes.
+     */
+    public function &get($uid, $note_ids = null)
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+
+        return $this->_facebook->call_method('notes.get',
+            array('session_key' => $skey,
+                  'uid' => $uid,
+                  'note_ids' => json_encode($note_ids)));
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Videos.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Videos.php
new file mode 100644 (file)
index 0000000..64d9706
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Videos methods
+ *
+ * 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_Videos extends Horde_Service_Facebook_Base
+{
+    /**
+     * Uploads a video.
+     *
+     * @param  string $file        The location of the video on the local filesystem.
+     * @param  string $title       (Optional) A title for the video. Titles over 65 characters in length will be truncated.
+     * @param  string $description (Optional) A description for the video.
+     *
+     * @return array  An array with the video's ID, title, description, and a link to view it on Facebook.
+     */
+    public function upload($file, $title = null, $description = null)
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+
+        return $this->_facebook->call_upload_method('facebook.video.upload',
+            array('title' => $title,
+                  'description' => $description,
+                  'session_key' => $skey),
+            $file,
+            Horde_Service_Facebook::get_facebook_url('api-video') . '/restserver.php');
+    }
+
+    /**
+     * Returns an array with the video limitations imposed on the current session's
+     * associated user. Maximum length is measured in seconds; maximum size is
+     * measured in bytes.
+     *
+     * @return array  Array with "length" and "size" keys
+     */
+    public function &getUploadLimits()
+    {
+        // Session key is *required*
+        if (!$skey = $this->_facebook->auth->getSessionKey()) {
+            throw new Horde_Service_Facebook_Exception('session_key is required',
+                                               Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
+        }
+
+        return $this->_facebook->call_method('facebook.video.getUploadLimits',
+            array('session_key' => $skey));
+    }
+
+}
\ No newline at end of file
index 25f282f..53717e2 100644 (file)
@@ -43,6 +43,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
        <file name="Auth.php" role="php" />
        <file name="Feeds.php" role="php" />
        <file name="Photos.php" role="php" />
+       <file name="Groups.php" role="php" />
+       <file name="Links.php" role="php" />
+          <file name="Notes.php" role="php" />
+       <file name="Videos.php" role="php" />
        <file name="Exception.php" role="php" />
        <file name="ErrorCodes.php" role="php" />
       </dir> <!-- /lib/Horde/Service/Facebook -->
@@ -78,6 +82,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Service/Facebook/Auth.php" as="Horde/Service/Facebook/Auth.php" />   
    <install name="lib/Horde/Service/Facebook/Feeds.php" as="Horde/Service/Facebook/Feeds.php" />   
    <install name="lib/Horde/Service/Facebook/Photos.php" as="Horde/Service/Facebook/Photos.php" />
+   <install name="lib/Horde/Service/Facebook/Groups.php" as="Horde/Service/Facebook/Groups.php" />
+   <install name="lib/Horde/Service/Facebook/Links.php" as="Horde/Service/Facebook/Links.php" />
+   <install name="lib/Horde/Service/Facebook/Notes.php" as="Horde/Service/Facebook/Notes.php" />
+   <install name="lib/Horde/Service/Facebook/Videos.php" as="Horde/Service/Facebook/Videos.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.php" as="Horde/Service/Facebook.php" />