diff --git a/README.md b/README.md index 25a100b..eaba01f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,61 @@ Zencoder API PHP Library ========================== +Company: [Brightcove/Zencoder](http://www.zencoder.com) + +Version: 2.2.4 + +Date: 2019-09-05 + +Repository: + +HTTP headers are handled in a case-insensitve manner so that they are compatible with HTTP2. + + +Author: [Nathan Sutton] (nsutton (a) brightcove (.) com) + +Company: [Brightcove/Zencoder](http://www.zencoder.com) + +Version: 2.2.3 + +Date: 2014-07-29 + +Repository: + +To help address problems where users cannot modify php.ini to point cURL to their system CA bundle path, or are using a PHP release before 5.3.7, we have extended this library to allow users to set CURLOPT\_CAPATH and CURLOPT\_CAINFO on the cURL connection used to submit requests. + +```php +$zencoder = new Services_Zencoder($my_api_key, 'v2', 'https://app.zencoder.com', false, $my_curlopt_capath, $my_curlopt_cainfo); +``` + +See also the constructor for `Services_Zencoder` for more information on the available arguments. + +See [the cURL CA bundle extraction page](http://curl.haxx.se/docs/caextract.html) for information on obtaining a CA bundle. We recommend using the HTTPS link to download the CA bundle. + + +Author: [Zac Shenker] (zshenker (a) brightcove (.) com) + +Company: [Brightcove/Zencoder](http://www.zencoder.com) + +Version: 2.2.0 + +Date: 2014-07-24 + +Repository: + +The Zencoder CA chain certificate has been removed from the library as the bundled cert will be expiring on July 26 2014, +and should not be required as PHP/curl should be able to use the built in CA chain. +Please contact us at help@zencoder.com with an issues. + + Author: [Michael Christopher] (mchristopher (a) brightcove (.) com) + Company: [Zencoder - Online Video Encoder](http://www.zencoder.com) + Version: 2.1.1 + Date: 2012-08-02 + Repository: Parts of this library are based on @@ -13,23 +64,27 @@ For more details on v2 of the Zencoder API visit For more details on the Zencoder API requirements visit - + To start working with the library, create a new instance of the Services_Zencoder class, passing your API Key as the 1st parameter. - $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3'); +```php +$zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3'); +``` Once you have created the object, you can use it to interact with the API. For full information, see the Documentation folder, but here is a quick overview of some of the functions that can be called: - $zencoder->accounts->create($array); - $zencoder->jobs->create($array); - $zencoder->jobs->progress($job_id); - $zencoder->inputs->details($input_id); - $zencoder->outputs->details($output_id); - $zencoder->notifications->parseIncoming(); +```php +$zencoder->accounts->create($array); +$zencoder->jobs->create($array); +$zencoder->jobs->progress($job_id); +$zencoder->inputs->details($input_id); +$zencoder->outputs->details($output_id); +$zencoder->notifications->parseIncoming(); +``` Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception and it will return any errors received from the Zencoder API. @@ -37,119 +92,134 @@ and it will return any errors received from the Zencoder API. ENCODING JOB ------------ -The ZencoderJob object creates an encoding job using [cURL](http://zencoder.com/docs/glossary/curl/) -to send [JSON](http://zencoder.com/docs/glossary/json/) formatted parameters to Zencoder's encoding API. + +The ZencoderJob object creates an encoding job using cURL +to send JSON formatted parameters to Zencoder's encoding API. ### Step 1 + Visit the [API builder](https://app.zencoder.com/api_builder) in your account, and execute a successful encoding job. ### Step 2 + Copy the successful JSON string, starting with the first curly brace "{", and pass it as the parameters for a new ZencoderJob object. Execute the script on your server to test that it works. #### Example -
-    jobs->create(
+try {
+  // Initialize the Services_Zencoder class
+  $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
+
+  // New Encoding Job
+  $encoding_job = $zencoder->jobs->create(
+    array(
+      "input" => "s3://bucket-name/file-name.avi",
+      "outputs" => array(
         array(
-          "input" => "s3://bucket-name/file-name.avi",
-          "outputs" => array(
-            array(
-              "label" => "web"
-            )
-          )
+          "label" => "web"
         )
-      );
-
-      // Success if we got here
-      echo "w00t! \n\n";
-      echo "Job ID: ".$encoding_job->id."\n";
-      echo "Output ID: ".$encoding_job->outputs['web']->id."\n";
-      // Store Job/Output IDs to update their status when notified or to check their progress.
-    } catch (Services_Zencoder_Exception $e) {
-      // If were here, an error occured
-      echo "Fail :(\n\n";
-      echo "Errors:\n";
-      foreach ($e->getErrors() as $error) echo $error."\n";
-      echo "Full exception dump:\n\n";
-      print_r($e);
-    }
-
-    echo "\nAll Job Attributes:\n";
-    var_dump($encoding_job);
-
-    ?>
-    
+ ) + ) + ); + + // Success if we got here + echo "w00t! \n\n"; + echo "Job ID: ".$encoding_job->id."\n"; + echo "Output ID: ".$encoding_job->outputs['web']->id."\n"; + // Store Job/Output IDs to update their status when notified or to check their progress. +} catch (Services_Zencoder_Exception $e) { + // If were here, an error occurred + echo "Fail :(\n\n"; + echo "Errors:\n"; + foreach ($e->getErrors() as $error) echo $error."\n"; + echo "Full exception dump:\n\n"; + print_r($e); +} + +echo "\nAll Job Attributes:\n"; +var_dump($encoding_job); + +?> +``` ### Step 3 + Modify the above script to meet your needs. + Your [API Request History](https://app.zencoder.com/api_requests) may come in handy. + You can revisit your [API builder](https://app.zencoder.com/api_builder) to add/update parameters of the JSON. You can translate the JSON string into nested associative arrays so that you can dynamically change attributes like "input". The previous JSON example would become: - $encoding_job = $zencoder->jobs->create(array( - "input" => "s3://bucket-name/file-name.avi", - "outputs" => array( - array( - "label" => "web" - ) - ) - )); +```php +$encoding_job = $zencoder->jobs->create(array( + "input" => "s3://bucket-name/file-name.avi", + "outputs" => array( + array( + "label" => "web" + ) + ) +)); +``` NOTIFICATION HANDLING ---------------------- + The ZencoderOutputNotification class is used to capture and parse JSON data sent from Zencoder to your app when an output file has been completed. ### Step 1 + Create a script to receive notifications, and upload it to a location on your server that is publicly accessible. #### Example - notifications->parseIncoming(); +// Initialize the Services_Zencoder class +$zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3'); - // Check output/job state - if($notification->job->outputs[0]->state == "finished") { - echo "w00t!\n"; +// Catch notification +$notification = $zencoder->notifications->parseIncoming(); - // If you're encoding to multiple outputs and only care when all of the outputs are finished - // you can check if the entire job is finished. - if($notification->job->state == "finished") { - echo "Dubble w00t!"; - } - } elseif ($notification->job->outputs[0]->state == "cancelled") { - echo "Cancelled!\n"; - } else { - echo "Fail!\n"; - echo $notification->job->outputs[0]->error_message."\n"; - echo $notification->job->outputs[0]->error_link; - } +// Check output/job state +if($notification->job->outputs[0]->state == "finished") { + echo "w00t!\n"; - ?> + // If you're encoding to multiple outputs and only care when all of the outputs are finished + // you can check if the entire job is finished. + if($notification->job->state == "finished") { + echo "Dubble w00t!"; + } +} elseif ($notification->job->outputs[0]->state == "cancelled") { + echo "Cancelled!\n"; +} else { + echo "Fail!\n"; + echo $notification->job->outputs[0]->error_message."\n"; + echo $notification->job->outputs[0]->error_link; +} + +?> +``` ### Step 2 + In the parameters for an encoding job, add the URL for your script to the notifications array of each output you want to be notified for. Then submit the job to test if it works. @@ -157,26 +227,36 @@ Then submit the job to test if it works. #### Example - ... - "outputs" => array( - array( - "label" => "web", - "notifications" => array("http://example.com.com/encoding/notification.php") - ), - array( - "label" => "iPhone", - "notifications" => array("http://example.com.com/encoding/notification.php") - ) - ) - ... +```php +... +"outputs" => array( + array( + "label" => "web", + "notifications" => array("http://example.com.com/encoding/notification.php") + ), + array( + "label" => "iPhone", + "notifications" => array("http://example.com.com/encoding/notification.php") + ) +) +... +``` ### Step 3 + Modify the above script to meet your needs. + Your [notifications page](https://app.zencoder.com/notifications) will come in handy. VERSIONS --------- + + Version 2.2.4 - 2019-09-05 HTTP headers are handled in a case-insensitve manner so that they are compatible with HTTP2. + Version 2.2.3 - 2014-07-29 Fixed the versions listed in the user agent and throughout the code + Version 2.2.2 - 2014-07-29 Fixed a bug where api_key was set as api_version in the http connection options + Version 2.2.1 - 2014-07-29 Support setting CURLOPT_CAPATH and CURLOPT_CAINFO on cURL connections. + Version 2.2.0 - 2014-07-24 Removing the bundled CA chain to address expiring intermediate certificate Version 2.1.1 - 2012-08-02 Fixing issue where jobs index call didn't return jobs as individual objects Version 2.1.0 - 2012-06-05 Adding support for job-level notifications & merging output with job in notification object Version 2.0.2 - 2012-01-11 Fixed job creation response object, added documentation to variables diff --git a/Services/Zencoder.php b/Services/Zencoder.php index e5bf879..6e8447c 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -5,7 +5,7 @@ * @category Services * @package Services_Zencoder * @author Michael Christopher - * @version Release: 2.1.2 + * @version Release: 2.2.4 * @license http://creativecommons.org/licenses/MIT/MIT * @link http://github.com/zencoder/zencoder-php * @access private @@ -26,14 +26,14 @@ function Services_Zencoder_autoload($className) * @category Services * @package Services_Zencoder * @author Michael Christopher - * @version Release: 2.1.2 + * @version Release: 2.2.4 * @license http://creativecommons.org/licenses/MIT/MIT * @link http://github.com/zencoder/zencoder-php */ class Services_Zencoder extends Services_Zencoder_Base { - const USER_AGENT = 'ZencoderPHP v2.1.2'; + const USER_AGENT = 'ZencoderPHP v2.2.4'; /** * Contains the HTTP communication class @@ -96,12 +96,16 @@ class Services_Zencoder extends Services_Zencoder_Base * @param string $api_version API version * @param string $api_host API host * @param bool $debug Enable debug mode + * @param string $ca_path Path to a directory that holds multiple CA certificates + * @param string $ca_file Path to a file holding one or more certificates to verify the peer with */ public function __construct( $api_key = NULL, $api_version = 'v2', $api_host = 'https://app.zencoder.com', - $debug = false + $debug = false, + $ca_path = NULL, + $ca_file = NULL ) { // Check that library dependencies are met @@ -114,14 +118,18 @@ public function __construct( if (!function_exists('curl_init')) { throw new Services_Zencoder_Exception('cURL extension must be enabled.'); } + $this->version = $api_version; - $this->http = new Services_Zencoder_Http( - $api_host, - array("curlopts" => array( - CURLOPT_USERAGENT => self::USER_AGENT, - CURLOPT_CAINFO => dirname(__FILE__) . "/Zencoder/zencoder_ca_chain.crt", - ), "api_key" => $api_key, "debug" => $debug) - ); + + $http_options = array("api_key" => $api_key, "debug" => $debug, "curlopts" => array(CURLOPT_USERAGENT => self::USER_AGENT)); + if (isset($ca_path)) { + $http_options["curlopts"][CURLOPT_CAPATH] = realpath($ca_path); + } + if (isset($ca_file)) { + $http_options["curlopts"][CURLOPT_CAINFO] = realpath($ca_file); + } + + $this->http = new Services_Zencoder_Http($api_host, $http_options); $this->accounts = new Services_Zencoder_Accounts($this); $this->inputs = new Services_Zencoder_Inputs($this); $this->jobs = new Services_Zencoder_Jobs($this); @@ -223,10 +231,10 @@ private function _processResponse($response) if ( $status == 204 || (($status == 200 || $status == 201) && trim($body) == "")) { return TRUE; } - if (empty($headers['Content-Type'])) { + if (empty($headers['content-type'])) { throw new Services_Zencoder_Exception('Response header is missing Content-Type', $body); } - switch ($headers['Content-Type']) { + switch ($headers['content-type']) { case 'application/json': case 'application/json; charset=utf-8': return $this->_processJsonResponse($status, $headers, $body); diff --git a/Services/Zencoder/Http.php b/Services/Zencoder/Http.php index eed8c7d..0a27a95 100644 --- a/Services/Zencoder/Http.php +++ b/Services/Zencoder/Http.php @@ -115,7 +115,8 @@ public function __call($name, $args) { array_shift($header_lines); foreach ($header_lines as $line) { list($key, $value) = explode(":", $line, 2); - $headers[$key] = trim($value); + // Ensure headers are lowercase per https://tools.ietf.org/html/rfc2616#section-4.2 + $headers[strtolower($key)] = trim($value); } curl_close($curl); if (isset($buf) && is_resource($buf)) fclose($buf); diff --git a/Services/Zencoder/zencoder_ca_chain.crt b/Services/Zencoder/zencoder_ca_chain.crt deleted file mode 100644 index f064d81..0000000 --- a/Services/Zencoder/zencoder_ca_chain.crt +++ /dev/null @@ -1,62 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkEx -FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD -VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv -biBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhhd3RlIFByZW1pdW0gU2Vy -dmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZlckB0aGF3dGUuY29t -MB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYTAlpB -MRUwEwYDVQQIEwxXZXN0ZX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+O7AWXX1uw16OFNMQkpw0P -lZPvy5TYnh+dXIVtx6quTx8itc2VrbqnzPmrC3p/ ------END CERTIFICATE----- diff --git a/composer.json b/composer.json index 32bfcb8..c8fcfdd 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "zencoder/zencoder-php", - "homepage": "http://github.com/zencoder/zencoder-php", + "homepage": "https://github.com/zencoder/zencoder-php", "description":"Zencoder integration library for PHP", "keywords":["zencoder", "encoding", "encoder", "cloud"], "type":"library", @@ -16,7 +16,7 @@ "authors":[ { "name":"Zencoder", - "homepage":"http://zencoder.com" + "homepage":"https://zencoder.com" } ] }