diff --git a/bc-mapi.php b/BC/MAPI.php similarity index 88% rename from bc-mapi.php rename to BC/MAPI.php index d68817b..758aa68 100644 --- a/bc-mapi.php +++ b/BC/MAPI.php @@ -41,7 +41,7 @@ * SUPPORT OF ANY KIND IS PROVIDED FOR THE SOFTWARE. */ -class BCMAPI +class BC_MAPI { const ERROR_API_ERROR = 1; const ERROR_DEPRECATED = 99; @@ -62,26 +62,27 @@ class BCMAPI public $page_size = NULL; public $total_count = NULL; - private $api_calls = 0; - private $bit32 = FALSE; - private $media_delivery = 'default'; - private $secure = FALSE; - private $show_notices = FALSE; - private $timeout_attempts = 100; - private $timeout_current = 0; - private $timeout_delay = 1; - private $timeout_retry = FALSE; - private $token_read = NULL; - private $token_write = NULL; - private $url_read = 'api.brightcove.com/services/library?'; - private $url_write = 'api.brightcove.com/services/post'; - private $valid_types = array( + protected $api_calls = 0; + protected $bit32 = FALSE; + protected $media_delivery = 'default'; + protected $secure = FALSE; + protected $show_notices = FALSE; + protected $timeout = 15; + protected $timeout_attempts = 100; + protected $timeout_current = 0; + protected $timeout_delay = 1; + protected $timeout_retry = FALSE; + protected $token_read = NULL; + protected $token_write = NULL; + protected $url_read = 'api.brightcove.com/services/library?'; + protected $url_write = 'api.brightcove.com/services/post'; + protected $valid_types = array( 'playlist', 'video' ); /** - * The constructor for the BCMAPI class. + * The constructor for the BC_MAPI class. * @access Public * @since 0.1.0 * @param string [$token_read] The read API token for the Brightcove account @@ -95,7 +96,7 @@ public function __construct($token_read = NULL, $token_write = NULL) } /** - * Sets a property of the BCMAPI class. + * Sets a property of the BC_MAPI class. * @access Public * @since 1.0.0 * @param string [$key] The property to set @@ -108,12 +109,12 @@ public function __set($key, $value) { $this->$key = $value; } else { - throw new BCMAPIInvalidProperty($this, self::ERROR_INVALID_PROPERTY); + throw new BC_MAPIInvalidProperty($this, self::ERROR_INVALID_PROPERTY); } } /** - * Retrieves a property of the BCMAPI class. + * Retrieves a property of the BC_MAPI class. * @access Public * @since 1.0.0 * @param string [$key] The property to retrieve @@ -125,7 +126,7 @@ public function __get($key) { return $this->$key; } else { - throw new BCMAPIInvalidProperty($this, self::ERROR_INVALID_PROPERTY); + throw new BC_MAPIInvalidProperty($this, self::ERROR_INVALID_PROPERTY); } } @@ -247,7 +248,7 @@ public function find($call, $params = NULL) $get_item_count = TRUE; break; default: - throw new BCMAPIInvalidMethod($this, self::ERROR_INVALID_METHOD); + throw new BC_MAPIInvalidMethod($this, self::ERROR_INVALID_METHOD); break; } @@ -371,7 +372,7 @@ public function search($type = 'video', $terms = NULL, $params = NULL) { if(!isset($terms) || !is_array($terms)) { - throw new BCMAPISearchTermsNotProvided($this, self::ERROR_SEARCH_TERMS_NOT_PROVIDED); + throw new BC_MAPISearchTermsNotProvided($this, self::ERROR_SEARCH_TERMS_NOT_PROVIDED); } if(!isset($params)) @@ -450,21 +451,21 @@ public function createMedia($type = 'video', $file = NULL, $meta, $options = NUL { unset($options['encode_to']); - throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); + throw new BC_MAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); } if(isset($options['create_multiple_renditions'])) { $options['create_multiple_renditions'] = 'FALSE'; - throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); + throw new BC_MAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); } if(isset($options['preserve_source_rendition'])) { unset($options['preserve_source_rendition']); - throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); + throw new BC_MAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); } } @@ -472,11 +473,11 @@ public function createMedia($type = 'video', $file = NULL, $meta, $options = NUL { unset($options['H264NoProcessing']); - throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); + throw new BC_MAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION); } } } else { - throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE); + throw new BC_MAPIInvalidType($this, self::ERROR_INVALID_TYPE); } $request = array(); @@ -556,7 +557,7 @@ public function createPlaylist($type = 'video', $meta) $params['playlist'] = $media; $post['method'] = 'create_playlist'; } else { - throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE); + throw new BC_MAPIInvalidType($this, self::ERROR_INVALID_TYPE); } $params['token'] = $this->token_write; @@ -591,7 +592,7 @@ public function createImage($type = 'video', $file = NULL, $meta, $id = NULL, $r { $post['method'] = 'add_image'; } else { - throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE); + throw new BC_MAPIInvalidType($this, self::ERROR_INVALID_TYPE); } foreach($meta as $key => $value) @@ -605,7 +606,7 @@ public function createImage($type = 'video', $file = NULL, $meta, $id = NULL, $r } elseif(isset($ref_id)) { $params[strtolower($type) . '_reference_id'] = $ref_id; } else { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } if($resize) @@ -660,7 +661,7 @@ public function createOverlay($file = NULL, $meta, $id = NULL, $ref_id = NULL) } elseif(isset($ref_id)) { $params['video_reference_id'] = $ref_id; } else { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } $params['token'] = $this->token_write; @@ -708,7 +709,7 @@ public function deleteOverlay($id = NULL, $ref_id = NULL, $options = NULL) } elseif(isset($ref_id)) { $params['video_reference_id'] = $ref_id; } else { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } $post['method'] = strtolower('remove_logo_overlay'); @@ -785,7 +786,7 @@ public function delete($type = 'video', $id = NULL, $ref_id = NULL, $options = N } elseif(isset($ref_id)) { $params['reference_id'] = $ref_id; } else { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } $post['method'] = strtolower('delete_' . $type); @@ -809,7 +810,7 @@ public function getStatus($type = 'video', $id = NULL, $ref_id = TRUE) { if(!isset($id) && !isset($ref_id)) { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } $request = array(); @@ -832,7 +833,7 @@ public function getStatus($type = 'video', $id = NULL, $ref_id = TRUE) { $post['method'] = 'get_upload_status'; } else { - throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE); + throw new BC_MAPIInvalidType($this, self::ERROR_INVALID_TYPE); } $post['params'] = $params; @@ -857,7 +858,7 @@ public function shareMedia($type = 'video', $id, $account_ids, $accept = FALSE, { if(!isset($id)) { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } if(!is_array($account_ids)) @@ -891,7 +892,7 @@ public function shareMedia($type = 'video', $id, $account_ids, $accept = FALSE, $params['video_id'] = $id; $post['method'] = 'share_video'; } else { - throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE); + throw new BC_MAPIInvalidType($this, self::ERROR_INVALID_TYPE); } $post['params'] = $params; @@ -913,7 +914,7 @@ public function removeFromPlaylist($playlist_id, $video_ids) { if(!isset($playlist_id)) { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } if(!is_array($video_ids)) @@ -932,7 +933,7 @@ public function removeFromPlaylist($playlist_id, $video_ids) if(!isset($playlist)) { - throw new BCMAPIDtoDoesNotExist($this, self::ERROR_DTO_DOES_NOT_EXIST); + throw new BC_MAPIDtoDoesNotExist($this, self::ERROR_DTO_DOES_NOT_EXIST); } foreach($playlist->videoIds as $video) @@ -963,7 +964,7 @@ public function addToPlaylist($playlist_id, $video_ids) { if(!isset($playlist_id)) { - throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); + throw new BC_MAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } if(!is_array($video_ids)) @@ -980,7 +981,7 @@ public function addToPlaylist($playlist_id, $video_ids) if(!isset($playlist)) { - throw new BCMAPIDtoDoesNotExist($this, self::ERROR_DTO_DOES_NOT_EXIST); + throw new BC_MAPIDtoDoesNotExist($this, self::ERROR_DTO_DOES_NOT_EXIST); } foreach($video_ids as $video) @@ -1171,7 +1172,7 @@ public function sef($name) * @param string [$type] The type of URL to retrieve, read or write * @return string The appropriate API URL */ - private function getUrl($type = 'read') + protected function getUrl($type = 'read') { if($this->secure) { @@ -1186,7 +1187,7 @@ private function getUrl($type = 'read') } elseif(strtolower($type) == 'write') { $url .= $this->url_write; } else { - throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE); + throw new BC_MAPIInvalidType($this, self::ERROR_INVALID_TYPE); } return $url; @@ -1201,7 +1202,7 @@ private function getUrl($type = 'read') * @param string [$default] The default API parameter if only 1 provided * @return string The complete API request URL */ - private function appendParams($method, $params = NULL, $default = NULL) + protected function appendParams($method, $params = NULL, $default = NULL) { $url = $this->getUrl('read') . 'token=' . $this->token_read . '&command=' . $method; @@ -1228,11 +1229,11 @@ private function appendParams($method, $params = NULL, $default = NULL) * @param string [$url] The complete API request URL * @return object An object containing all API return data */ - private function getData($url) + protected function getData($url) { - if(class_exists('BCMAPICache')) + if(class_exists('BC_MAPICache',false)) { - $cache = BCMAPICache::get($url); + $cache = BC_MAPICache::get($url); if($cache !== FALSE) { @@ -1257,7 +1258,7 @@ private function getData($url) if(!isset($this->token_read)) { - throw new BCMAPITokenError($this, self::ERROR_READ_TOKEN_NOT_PROVIDED); + throw new BC_MAPITokenError($this, self::ERROR_READ_TOKEN_NOT_PROVIDED); } $response = $this->curlRequest($url, TRUE); @@ -1282,12 +1283,12 @@ private function getData($url) return $this->getData($url); } else { - throw new BCMAPIApiError($this, self::ERROR_API_ERROR, $response_object); + throw new BC_MAPIApiError($this, self::ERROR_API_ERROR, $response_object); } } else { - if(class_exists('BCMAPICache')) + if(class_exists('BC_MAPICache',false)) { - $cache = BCMAPICache::set($url, $response_object); + $cache = BC_MAPICache::set($url, $response_object); } if(isset($response_object->items)) @@ -1304,7 +1305,7 @@ private function getData($url) return $data; } } else { - throw new BCMAPIApiError($this, self::ERROR_API_ERROR); + throw new BC_MAPIApiError($this, self::ERROR_API_ERROR); } } @@ -1316,11 +1317,11 @@ private function getData($url) * @param bool [$return_json] Whether we should return any data or not * @return object An object containing all API return data */ - private function putData($request, $return_json = TRUE) + protected function putData($request, $return_json = TRUE) { if(!isset($this->token_write)) { - throw new BCMAPITokenError($this, self::ERROR_WRITE_TOKEN_NOT_PROVIDED); + throw new BC_MAPITokenError($this, self::ERROR_WRITE_TOKEN_NOT_PROVIDED); } $response = $this->curlRequest($request, FALSE); @@ -1331,7 +1332,7 @@ private function putData($request, $return_json = TRUE) if(!isset($response_object->result)) { - throw new BCMAPIApiError($this, self::ERROR_API_ERROR, $response_object); + throw new BC_MAPIApiError($this, self::ERROR_API_ERROR, $response_object); } return $response_object; @@ -1346,7 +1347,7 @@ private function putData($request, $return_json = TRUE) * @param boolean [$get_request] If false, send POST params * @return void */ - private function curlRequest($request, $get_request = FALSE) + protected function curlRequest($request, $get_request = FALSE) { $curl = curl_init(); @@ -1358,7 +1359,8 @@ private function curlRequest($request, $get_request = FALSE) curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $request); } - + // Add curl timeout + curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curl); @@ -1377,9 +1379,9 @@ private function curlRequest($request, $get_request = FALSE) { if($get_request) { - throw new BCMAPITransactionError($this, self::ERROR_READ_API_TRANSACTION_FAILED, $curl_error); + throw new BC_MAPITransactionError($this, self::ERROR_READ_API_TRANSACTION_FAILED, $curl_error); } else { - throw new BCMAPITransactionError($this, self::ERROR_WRITE_API_TRANSACTION_FAILED, $curl_error); + throw new BC_MAPITransactionError($this, self::ERROR_WRITE_API_TRANSACTION_FAILED, $curl_error); } } @@ -1393,7 +1395,7 @@ private function curlRequest($request, $get_request = FALSE) * @param string [$response] The response from a cURL request * @return string The cleansed string if using a 32-bit machine. */ - private function bit32Clean($response) + protected function bit32Clean($response) { if($this->bit32) { @@ -1409,11 +1411,11 @@ private function bit32Clean($response) * @since 1.0.0 * @param string [$type] The type */ - private function validType($type) + protected function validType($type) { if(!in_array(strtolower($type), $this->valid_types)) { - throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE); + throw new BC_MAPIInvalidType($this, self::ERROR_INVALID_TYPE); } else { return TRUE; } @@ -1455,7 +1457,7 @@ public function time($ms, $seconds = FALSE) */ public function embed($a = NULL, $b = NULL, $c = NULL, $d = NULL, $e = NULL) { - throw new BCMAPIDeprecated($this, self::ERROR_DEPRECATED); + throw new BC_MAPIDeprecated($this, self::ERROR_DEPRECATED); return FALSE; } @@ -1517,17 +1519,17 @@ public function getErrorAsString($error_code) } } -class BCMAPIException extends Exception +class BC_MAPIException extends Exception { /** - * The constructor for the BCMAPIException class + * The constructor for the BC_MAPIException class * @access Public * @since 1.0.0 - * @param object [$obj] A pointer to the BCMAPI class + * @param object [$obj] A pointer to the BC_MAPI class * @param int [$error_code] The error code * @param string [$raw_error] Any additional error information */ - public function __construct(BCMAPI $obj, $error_code, $raw_error = NULL) + public function __construct(BC_MAPI $obj, $error_code, $raw_error = NULL) { $error = $obj->getErrorAsString($error_code); @@ -1547,17 +1549,17 @@ public function __construct(BCMAPI $obj, $error_code, $raw_error = NULL) } } -class BCMAPIApiError extends BCMAPIException{} -class BCMAPIDeprecated extends BCMAPIException{} -class BCMAPIDtoDoesNotExist extends BCMAPIException{} -class BCMAPIIdNotProvided extends BCMAPIException{} -class BCMAPIInvalidFileType extends BCMAPIException{} -class BCMAPIInvalidMethod extends BCMAPIException{} -class BCMAPIInvalidProperty extends BCMAPIException{} -class BCMAPIInvalidType extends BCMAPIException{} -class BCMAPIInvalidUploadOption extends BCMAPIException{} -class BCMAPISearchTermsNotProvided extends BCMAPIException{} -class BCMAPITokenError extends BCMAPIException{} -class BCMAPITransactionError extends BCMAPIException{} - -?> \ No newline at end of file +class BC_MAPIApiError extends BC_MAPIException{} +class BC_MAPIDeprecated extends BC_MAPIException{} +class BC_MAPIDtoDoesNotExist extends BC_MAPIException{} +class BC_MAPIIdNotProvided extends BC_MAPIException{} +class BC_MAPIInvalidFileType extends BC_MAPIException{} +class BC_MAPIInvalidMethod extends BC_MAPIException{} +class BC_MAPIInvalidProperty extends BC_MAPIException{} +class BC_MAPIInvalidType extends BC_MAPIException{} +class BC_MAPIInvalidUploadOption extends BC_MAPIException{} +class BC_MAPISearchTermsNotProvided extends BC_MAPIException{} +class BC_MAPITokenError extends BC_MAPIException{} +class BC_MAPITransactionError extends BC_MAPIException{} + +?> diff --git a/bc-mapi-cache.php b/BC/MAPICache.php similarity index 98% rename from bc-mapi-cache.php rename to BC/MAPICache.php index 2c08d9c..abd0719 100644 --- a/bc-mapi-cache.php +++ b/BC/MAPICache.php @@ -36,7 +36,7 @@ * SUPPORT OF ANY KIND IS PROVIDED FOR THE SOFTWARE. */ -class BCMAPICache +class BC_MAPICache { public static $extension = NULL; public static $location = NULL; @@ -46,7 +46,7 @@ class BCMAPICache public static $type = NULL; /** - * The constructor for the BCMAPICache class. + * The constructor for the BC_MAPICache class. * @access Public * @since 1.0.0 * @param string [$type] The type of caching method to use, either 'file' or 'memcached' diff --git a/README.md b/README.md index cb1780e..3a51d4a 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,12 @@ Then, after instantiating the core class, you can instantiate the caching extension. // Using flat files - $bc = new BCMAPI(API_READ_TOKEN, API_WRITE_TOKEN); - $bc_cache = new BCMAPICache('file', 600, '/var/www/myWebSite/cache/', '.cache'); + $bc = new BC_MAPI(API_READ_TOKEN, API_WRITE_TOKEN); + $bc_cache = new BC_MAPICache('file', 600, '/var/www/myWebSite/cache/', '.cache'); // Using Memcached - $bc = new BCMAPI(API_READ_TOKEN, API_WRITE_TOKEN); - $bc_cache = new BCMAPICache('memcached', 600, 'localhost', NULL, 11211); + $bc = new BC_MAPI(API_READ_TOKEN, API_WRITE_TOKEN); + $bc_cache = new BC_MAPICache('memcached', 600, 'localhost', NULL, 11211); The parameters for the constructor are: