Add a S_V_Request class and use some PHP5 magic to make this a more
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 28 Dec 2008 22:36:52 +0000 (17:36 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 28 Dec 2008 22:36:52 +0000 (17:36 -0500)
robust, horde-4ish interface.

framework/Service_Vimeo/lib/Horde/Service/Vimeo.php
framework/Service_Vimeo/lib/Horde/Service/Vimeo/Simple.php

index 3d7fd0c..923f434 100644 (file)
@@ -16,7 +16,7 @@ require_once 'HTTP/Request.php';
  */
 class Horde_Service_Vimeo {
 
-    protected $_format = 'php';
+    protected static $_format = 'php';
 
     /**
      * HTTP client object to use for accessing the Vimeo API.
@@ -51,6 +51,11 @@ class Horde_Service_Vimeo {
         return self::$_httpClient;
     }
 
+    public static function getFormat()
+    {
+        return self::$_format;
+    }
+
     /**
      * Get the raw JSON response containing the data to embed a single video.
      *
index a61aa8a..797039e 100644 (file)
@@ -15,36 +15,6 @@ class Horde_Service_Vimeo_Simple extends Horde_Service_Vimeo {
     protected $_api_endpoint = 'http://www.vimeo.com/api/';
     protected $_oembed_endpoint = 'http://www.vimeo.com/api/oembed.json';
 
-    /**
-     * Return an array of clips data based on the search criteria.
-     *
-     * @param array $criteria  The search criteria:
-     *     Users
-     *       userClips:
-     *       userLikes:
-     *       userIn:
-     *       userAll:
-     *       userSubscriptions:
-     *       contactsClips:
-     *       contactsLikes:
-     *
-     *     Groups
-     *       groupClips: clips in this group
-     */
-    public function getClips($criteria)
-    {
-        $key = array_pop(array_keys($criteria));
-
-        switch ($key) {
-        case 'userClips':
-            $method = $criteria['userClips'] . '/clips.' . $this->_format;
-            break;
-        }
-
-        $req = $this->getHttpClient();
-        $response = $req->request('GET', $this->_api_endpoint . $method);
-        return $response->getBody();
-    }
 
     public function getActivity($criteria)
     {
@@ -63,4 +33,41 @@ class Horde_Service_Vimeo_Simple extends Horde_Service_Vimeo {
     {
     }
 
+    public function __call($name, $args)
+    {
+        switch ($name) {
+        case 'user';
+            $request = new Horde_Service_Vimeo_Request(array('type' => $args[0]));
+            return $request;
+        }
+    }
+
+}
+
+class Horde_Service_Vimeo_Request {
+    protected $_api_endpoint = 'http://www.vimeo.com/api';
+    protected $_oembed_endpoint = 'http://www.vimeo.com/api/oembed.json';
+    protected $_identifier;
+    protected $_method;
+
+    public function __construct($args)
+    {
+        $this->_identifier = $args['type'];
+    }
+
+    public function __call($name, $args)
+    {
+        switch ($name) {
+        case 'clips':
+            $this->_method = $name;
+            return $this;
+       }
+    }
+
+    public function run()
+    {
+        $req = Horde_Service_Vimeo::getHttpClient();
+        $response = $req->request('GET', $this->_api_endpoint . '/' . $this->_identifier . '/' . $this->_method . '.' . Horde_Service_Vimeo::getFormat());
+        return $response->getBody();
+    }
 }
\ No newline at end of file