Add support for Feeds.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 25 Feb 2009 21:27:37 +0000 (16:27 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 25 Feb 2009 21:27:37 +0000 (16:27 -0500)
framework/Service_Facebook/lib/Horde/Service/Facebook/Feeds.php [new file with mode: 0644]
framework/Service_Facebook/package.xml

diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Feeds.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Feeds.php
new file mode 100644 (file)
index 0000000..f9b126f
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+/**
+ * Feed methods
+ */
+
+class Horde_Service_Facebook_Feeds extends Horde_Service_Facebook_Base
+{
+    const STORY_SIZE_ONE_LINE = 1;
+    const STORY_SIZE_SHORT = 2;
+    const STORY_SIZE_FULL = 4;
+
+    /**
+     * Registers a template bundle.  Template bundles are somewhat involved, so
+     * it's recommended you check out the wiki for more details:
+     *
+     *  http://wiki.developers.facebook.com/index.php/Feed.registerTemplateBundle
+     *
+     * @return string  A template bundle id
+     */
+    public function &registerTemplateBundle($oneLineStory,
+                                            $shortStory = array(),
+                                            $fullStory = null,
+                                            $actionLinks = array())
+    {
+        $oneLineStory = json_encode($oneLineStory);
+
+        if (!empty($shortStory)) {
+            $shortStory = json_encode($shortStory);
+        }
+
+        if (isset($fullStory)) {
+            $fullStory = json_encode($fullStory);
+        }
+
+        if (isset($actionLinks)) {
+            $actionLinks = json_encode($actionLinks);
+        }
+
+        return $this->_facebook->call_method('facebook.feed.registerTemplateBundle',
+            array('one_line_story_templates' => $oneLineStory,
+                  'short_story_templates' => $shortStory,
+                  'full_story_template' => $fullStory,
+                  'action_links' => $actionLinks));
+    }
+
+    /**
+     * Retrieves the full list of active template bundles registered by the
+     * requesting application.
+     *
+     * @return array  An array of template bundles
+     */
+    public function &getRegisteredTemplateBundles()
+    {
+        return $this->_facebook->call_method('facebook.feed.getRegisteredTemplateBundles');
+    }
+
+    /**
+     * Retrieves information about a specified template bundle previously
+     * registered by the requesting application.
+     *
+     * @param string $id  The template bundle id
+     *
+     * @return array  Template bundle
+     */
+    public function &getRegisteredTemplateBundleByID($id)
+    {
+        return $this->_facebook->call_method('facebook.feed.getRegisteredTemplateBundleByID',
+            array('template_bundle_id' => $id));
+    }
+
+    /**
+     * Deactivates a previously registered template bundle.
+     *
+     * @param string $template_bundle_id  The template bundle id
+     *
+     * @return bool  true on success
+     */
+    public function &deactivateTemplateBundleByID($id)
+    {
+        return $this->_facebook->call_method('facebook.feed.deactivateTemplateBundleByID',
+            array('template_bundle_id' => $id));
+    }
+
+    /**
+     * Publishes a story on behalf of the user owning the session, using the
+     * specified template bundle. This method requires an active session key in
+     * order to be called.
+     *
+     * The parameters to this method ($templata_data in particular) are somewhat
+     * involved.  It's recommended you visit the wiki for details:
+     *
+     *  http://wiki.developers.facebook.com/index.php/Feed.publishUserAction
+     *
+     * @param int $bundleId     A template bundle id previously registered
+     * @param array $data       See wiki article for syntax
+     * @param array $targetIds  (Optional) An array of friend uids of the user
+     *                          who shared in this action.
+     * @param string $body      (Optional) Additional markup that extends
+     *                          the body of a short story.
+     * @param int $size         (Optional) A story size (see above)
+     *
+     * @return bool  true on success
+     */
+    public function &publishUserAction($bundleId, $data, $targetIds = '',
+                                       $body = '', $size = self::STORY_SIZE_ONE_LINE)
+    {
+        // Pass in JSON or an assoc that we JSON for them
+        if (is_array($data)) {
+            $data = json_encode($data);
+        }
+        if (is_array($targetIds)) {
+            $targetIds = json_encode($targetIds);
+            // No brackets
+            $targetIds = trim($targetIds, "[]");
+        }
+
+        return $this->_facebook->call_method('facebook.feed.publishUserAction',
+            array('template_bundle_id' => $bundleId,
+                  'template_data' => $data,
+                  'target_ids' => $targetIds,
+                  'body_general' => $body,
+                  'story_size' => $size));
+    }
+
+    /**
+     * For the current user, retrieves stories generated by the user's friends
+     * while using this application.  This can be used to easily create a
+     * "News Feed" like experience.
+     *
+     * @return array  An array of feed story objects.
+     */
+    public function &feed_getAppFriendStories()
+    {
+        return $this->_facebook->call_method('facebook.feed.getAppFriendStories');
+    }
+
+}
\ No newline at end of file
index eb5ddb2..4596bc9 100644 (file)
@@ -41,6 +41,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
        <file name="Request.php" role="php" />
        <file name="BatchRequest.php" role="php" />
        <file name="Auth.php" role="php" />
+       <file name="Feeds.php" role="php" />
        <file name="Exception.php" role="php" />
        <file name="ErrorCodes.php" role="php" />
       </dir> <!-- /lib/Horde/Service/Facebook -->
@@ -74,6 +75,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <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/Feeds.php" as="Horde/Service/Facebook/Feeds.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" />