Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to PSR-0 #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "vimeo/vimeo",
"description": "Vimeo",
"type": "library",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {"Vimeo": "src/"}
}
}
File renamed without changes.
3 changes: 1 addition & 2 deletions upload.php → examples/upload.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
include 'vimeo.php';

$vimeo = new phpVimeo('CONSUMER_KEY', 'CONSUMER_SECRET', 'ACCESS_TOKEN', 'ACCESS_TOKEN_SECRET');
$vimeo = new \Vimeo\Vimeo('CONSUMER_KEY', 'CONSUMER_SECRET', 'ACCESS_TOKEN', 'ACCESS_TOKEN_SECRET');

try {
$video_id = $vimeo->upload('PATH_TO_VIDEO_FILE');
Expand Down
2 changes: 1 addition & 1 deletion readme.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<pre>$vimeo = new phpVimeo('your consumer key', 'your consumer secret');
<pre>$vimeo = new Vimeo('your consumer key', 'your consumer secret');
$videos = $vimeo->call('vimeo.videos.getUploaded', array('user_id' => 'brad'));</pre>

The <code>index.php</code> 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 <code>upload.php</code>.
Expand Down
25 changes: 14 additions & 11 deletions vimeo.php → src/Vimeo/Vimeo.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
class phpVimeo

namespace Vimeo;

class Vimeo
{
const API_REST_URL = 'http://vimeo.com/api/rest/v2';
const API_AUTH_URL = 'http://vimeo.com/oauth/authorize';
Expand Down Expand Up @@ -236,7 +239,7 @@ private function _request($method, $call_params = array(), $request_method = 'GE
return $response;
}
else if ($response->err) {
throw new VimeoAPIException($response->err->msg, $response->err->code);
throw new \Vimeo\VimeoAPIException($response->err->msg, $response->err->code);
}

return false;
Expand Down Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}<br>";
}
}
}

// Complete the upload
Expand All @@ -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);
}
}

Expand All @@ -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));
Expand All @@ -538,5 +543,3 @@ public static function url_encode_rfc3986($input)
}

}

class VimeoAPIException extends Exception {}
5 changes: 5 additions & 0 deletions src/Vimeo/VimeoAPIException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Vimeo;

class VimeoAPIException extends \Exception {}