From 17f0a223b0c3dbc16bbafa4082376463c1a4cb13 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 26 Dec 2008 12:15:10 -0500 Subject: [PATCH] VERY initial code for a Services_VimeoSimple library. Interfaces with vimeo's simple API and oEmbed interfaces. Right now can only retrieve list of user's clips and can retrieve the JSON code needed to embed any clip on a page. --- service/doc/vimeo_example.php | 19 ++++++++ service/lib/VimeoSimple.php | 106 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 service/doc/vimeo_example.php create mode 100644 service/lib/VimeoSimple.php diff --git a/service/doc/vimeo_example.php b/service/doc/vimeo_example.php new file mode 100644 index 000000000..ebce6f7c0 --- /dev/null +++ b/service/doc/vimeo_example.php @@ -0,0 +1,19 @@ +getClips(array('userClips' => 'user1015172'))); + +// Get first video to embed +$latest = $results[0]; + +// Get the code to embed it +$embed = $v->getEmbedJSON($latest['url']); + +// Decode the data and print out the HTML +$results = Horde_Serialize::unserialize($embed, SERIALIZE_JSON); +echo $results->html; diff --git a/service/lib/VimeoSimple.php b/service/lib/VimeoSimple.php new file mode 100644 index 000000000..285684528 --- /dev/null +++ b/service/lib/VimeoSimple.php @@ -0,0 +1,106 @@ + + */ +class Service_VimeoSimple { + + protected $_api_endpoint = 'http://www.vimeo.com/api/'; + protected $_oembed_endpoint = 'http://www.vimeo.com/api/oembed.json'; + protected $_format = 'php'; + + + public function setReturnFormat($format) + { + // TODO: Validate (json, php, xml) + $this->_format = $format; + } + + /** + * 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 + * + * + * + * @param unknown_type $criteria + */ + public function getClips($criteria) + { + $key = array_pop(array_keys($criteria)); + + switch ($key) { + case 'userClips': + $method = $criteria['userClips'] . '/clips.' . $this->_format; + break; + } + + $req = new HTTP_Request($this->_api_endpoint . $method); + if (is_a($req, 'PEAR_Error')) { + return $req; + } + $req->sendRequest(); + return $req->getResponseBody(); + } + + public function getActivity($criteria) + { + } + + /** + * Group: + * User: + * Album: + * Channel: + * + * + * @param unknown_type $criteria + */ + public function getInfo($criteria) + { + } + + + /** + * Get the raw JSON response containing the data to embed a single video. + * + * @param string $clipUrl The URL of the video to embed. + * + * @return JSON encoded data + */ + public function getEmbedJSON($clipUrl) + { + $url = $this->_oembed_endpoint . '?url=' . rawurlencode($clipUrl); + $req = new HTTP_Request($url); + //@TODO: We should probably throw an exception here. + if (is_a($req, 'PEAR_Error')) { + return $req; + } + $req->sendRequest(); + $response = $req->getResponseBody(); + return $response; + } + +} \ No newline at end of file -- 2.11.0