diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f4ab2da --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "name": "vimeo/vimeo", + "description": "Vimeo", + "type": "library", + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-0": {"Vimeo": "src/"} + } +} \ No newline at end of file diff --git a/index.php b/examples/index.php similarity index 100% rename from index.php rename to examples/index.php diff --git a/upload.php b/examples/upload.php similarity index 85% rename from upload.php rename to examples/upload.php index f7582b7..da7f8b9 100644 --- a/upload.php +++ b/examples/upload.php @@ -1,7 +1,6 @@ upload('PATH_TO_VIDEO_FILE'); diff --git a/readme.textile b/readme.textile index 7ce6e3e..86b8d5e 100644 --- a/readme.textile +++ b/readme.textile @@ -2,7 +2,7 @@ h1. Vimeo Advanced API PHP Library This library is all set to go with version 2 of our API. Just create the object and call a method like this: -
$vimeo = new phpVimeo('your consumer key', 'your consumer secret');
+
$vimeo = new Vimeo('your consumer key', 'your consumer secret');
 $videos = $vimeo->call('vimeo.videos.getUploaded', array('user_id' => 'brad'));
The index.php file included will show you how to get an access token so that you can query the API for private items. To take a look at an example of how to upload a file, check out upload.php. diff --git a/vimeo.php b/src/Vimeo/Vimeo.php similarity index 95% rename from vimeo.php rename to src/Vimeo/Vimeo.php index 99f3ed9..4bb05d8 100644 --- a/vimeo.php +++ b/src/Vimeo/Vimeo.php @@ -1,5 +1,8 @@ err) { - throw new VimeoAPIException($response->err->msg, $response->err->code); + throw new \Vimeo\VimeoAPIException($response->err->msg, $response->err->code); } return false; @@ -278,7 +281,7 @@ public function call($method, $params = array(), $request_method = 'GET', $url = /** * Enable the cache. * - * @param string $type The type of cache to use (phpVimeo::CACHE_FILE is built in) + * @param string $type The type of cache to use (Vimeo::CACHE_FILE is built in) * @param string $path The path to the cache (the directory for CACHE_FILE) * @param int $expire The amount of time to cache responses (default 10 minutes) */ @@ -386,7 +389,7 @@ public function setToken($token, $token_secret, $type = 'access', $session_store public function upload($file_path, $use_multiple_chunks = false, $chunk_temp_dir = '.', $size = 2097152, $replace_id = null) { if (!file_exists($file_path)) { - return false; + throw new \Exception('File does not exist.'); } // Figure out the filename and full size @@ -397,7 +400,7 @@ public function upload($file_path, $use_multiple_chunks = false, $chunk_temp_dir // Make sure we have enough room left in the user's quota $quota = $this->call('vimeo.videos.upload.getQuota'); if ($quota->user->upload_space->free < $file_size) { - throw new VimeoAPIException('The file is larger than the user\'s remaining quota.', 707); + throw new \Vimeo\VimeoAPIException('The file is larger than the user\'s remaining quota.', 707); } // Get an upload ticket @@ -413,14 +416,14 @@ public function upload($file_path, $use_multiple_chunks = false, $chunk_temp_dir // Make sure we're allowed to upload this size file if ($file_size > $rsp->ticket->max_file_size) { - throw new VimeoAPIException('File exceeds maximum allowed size.', 710); + throw new \Vimeo\VimeoAPIException('File exceeds maximum allowed size.', 710); } // Split up the file if using multiple pieces $chunks = array(); if ($use_multiple_chunks) { if (!is_writeable($chunk_temp_dir)) { - throw new Exception('Could not write chunks. Make sure the specified folder has write access.'); + throw new \Exception('Could not write chunks. Make sure the specified folder has write access.'); } // Create pieces @@ -478,12 +481,14 @@ public function upload($file_path, $use_multiple_chunks = false, $chunk_temp_dir // Make sure our file sizes match up foreach ($verify->ticket->chunks as $chunk_check) { + if (isset($chunks[$chunk_check->id])) { $chunk = $chunks[$chunk_check->id]; if ($chunk['size'] != $chunk_check->size) { // size incorrect, uh oh echo "Chunk {$chunk_check->id} is actually {$chunk['size']} but uploaded as {$chunk_check->size}
"; } + } } // Complete the upload @@ -504,7 +509,7 @@ public function upload($file_path, $use_multiple_chunks = false, $chunk_temp_dir return $complete->ticket->video_id; } else if ($complete->err) { - throw new VimeoAPIException($complete->err->msg, $complete->err->code); + throw new \Vimeo\VimeoAPIException($complete->err->msg, $complete->err->code); } } @@ -527,7 +532,7 @@ public function uploadMulti($file_name, $size = 1048576) public static function url_encode_rfc3986($input) { if (is_array($input)) { - return array_map(array('phpVimeo', 'url_encode_rfc3986'), $input); + return array_map(array('\Vimeo\Vimeo', 'url_encode_rfc3986'), $input); } else if (is_scalar($input)) { return str_replace(array('+', '%7E'), array(' ', '~'), rawurlencode($input)); @@ -538,5 +543,3 @@ public static function url_encode_rfc3986($input) } } - -class VimeoAPIException extends Exception {} diff --git a/src/Vimeo/VimeoAPIException.php b/src/Vimeo/VimeoAPIException.php new file mode 100644 index 0000000..98cfb96 --- /dev/null +++ b/src/Vimeo/VimeoAPIException.php @@ -0,0 +1,5 @@ +