From f91060de9575db7df89a728104b7edfaf8dc3899 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 10:43:27 +0200 Subject: [PATCH 01/24] add access to reports api --- Services/Zencoder/Report.php | 114 ++++++++++++++++++ Services/Zencoder/Report/LiveStatistic.php | 15 +++ Services/Zencoder/Report/LiveTotal.php | 15 +++ Services/Zencoder/Report/MinutesStatistic.php | 15 +++ Services/Zencoder/Report/MinutesTotal.php | 15 +++ Services/Zencoder/Report/VodStatistic.php | 15 +++ Services/Zencoder/Report/VodTotal.php | 15 +++ Services/Zencoder/Reports.php | 58 +++++++++ 8 files changed, 262 insertions(+) create mode 100644 Services/Zencoder/Report.php create mode 100644 Services/Zencoder/Report/LiveStatistic.php create mode 100644 Services/Zencoder/Report/LiveTotal.php create mode 100644 Services/Zencoder/Report/MinutesStatistic.php create mode 100644 Services/Zencoder/Report/MinutesTotal.php create mode 100644 Services/Zencoder/Report/VodStatistic.php create mode 100644 Services/Zencoder/Report/VodTotal.php create mode 100644 Services/Zencoder/Reports.php diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php new file mode 100644 index 0000000..2354cc1 --- /dev/null +++ b/Services/Zencoder/Report.php @@ -0,0 +1,114 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ +class Services_Zencoder_Report extends Services_Zencoder_Object { + + /** + * Array for statistics of the report + * + * @var array + */ + public $statistics = array(); + + /** + * Holds the totals in case of single type of report + * + * @var mixed (Services_Zencoder_Report_VodTotal|Services_Zencoder_Report_LiveTotal) + */ + public $total; + + /** + * A copy of the raw API response for debug purposes + * + * @var mixed + */ + protected $raw_response; + + /** + * Flag to check if you will be filling array of arrays (when type = 'all') + * + * @var boolean + */ + protected $is_multiple = false; + + /** + * The type of report that is being fetched ('live', 'vod' 'minutes' or 'all') + * + * @var string + */ + protected $type; + + /** + * Create a new Services_Zencoder_Job object. + * + * @param mixed $params API response + * @param string $type The type of statistic we are fetching + */ + public function __construct($params, $type) { + $this->raw_response = $params; + $this->type = $type; + $this->is_multiple = $this->type === "all"; + $this->_update_attributes($params); + } + + private function _update_attributes($attributes = array()) { + foreach ($attributes as $attr_name => $attr_value) { + if (($attr_name == "statistics")) { + if (!$this->is_multiple) { + $this->_create_statistics($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_statistics($attrs, $type); + } + } + } elseif (($attr_name == "total")) { + if (!$this->is_multiple) { + $this->_create_totals($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_totals($attrs, $type); + } + } + + } + } + } + + private function _create_statistics($statistics = array(), $type = null) { + $class = $this->_get_report_class('statistic', $type); + if ($this->is_multiple) { + $this->statistics[$type] = array(); + } + + foreach ($statistics as $stat_attrs) { + if ($this->is_multiple) { + $this->statistics[$type][] = new $class($stat_attrs); + } else { + $this->statistics[] = new $class($stat_attrs); + } + } + } + + private function _create_totals($totals, $type = null) { + $class = $this->_get_report_class('total', $type); + if ($this->is_multiple) { + $this->total[$type] = new $class($totals); + } else { + $this->total = new $class($totals); + } + } + + private function _get_report_class($attr_name, $type) { + return 'Services_Zencoder_Report_' . ucwords($type) . ucwords($attr_name); + } + +} diff --git a/Services/Zencoder/Report/LiveStatistic.php b/Services/Zencoder/Report/LiveStatistic.php new file mode 100644 index 0000000..693a952 --- /dev/null +++ b/Services/Zencoder/Report/LiveStatistic.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_LiveStatistic extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/LiveTotal.php b/Services/Zencoder/Report/LiveTotal.php new file mode 100644 index 0000000..b4615ce --- /dev/null +++ b/Services/Zencoder/Report/LiveTotal.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_LiveTotal extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/MinutesStatistic.php b/Services/Zencoder/Report/MinutesStatistic.php new file mode 100644 index 0000000..2739e70 --- /dev/null +++ b/Services/Zencoder/Report/MinutesStatistic.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_MinutesStatistic extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/MinutesTotal.php b/Services/Zencoder/Report/MinutesTotal.php new file mode 100644 index 0000000..5464982 --- /dev/null +++ b/Services/Zencoder/Report/MinutesTotal.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_MinutesTotal extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/VodStatistic.php b/Services/Zencoder/Report/VodStatistic.php new file mode 100644 index 0000000..d38c922 --- /dev/null +++ b/Services/Zencoder/Report/VodStatistic.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_VodStatistic extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/VodTotal.php b/Services/Zencoder/Report/VodTotal.php new file mode 100644 index 0000000..64fbdb6 --- /dev/null +++ b/Services/Zencoder/Report/VodTotal.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_VodTotal extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php new file mode 100644 index 0000000..ad09cfe --- /dev/null +++ b/Services/Zencoder/Reports.php @@ -0,0 +1,58 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ +class Services_Zencoder_Reports extends Services_Zencoder_Base { + + /** + * A list of valid 'methods' to be trapped in __call() + * + * @link @link https://app.zencoder.com/docs/api/reports/ + * @var array + */ + protected $methods = array('vod', 'live', 'minutes', 'all'); + + /** + * Return all reports for VOD + * + * @link https://app.zencoder.com/docs/api/reports + * + * @param string $method The method name indicates the type of report we want to get + * @param array $args A list of arguments for the overriden methods. Each methods takes 2 arguements. + * The first being an associative array of query string parameters and the second + * an associative array of option overrides + * + * @throws Services_Zencoder_Exception + * + * @return Services_Zencoder_Report The object representation of the resource + */ + public function __call($method, $args) { + if (!in_array($method, $this->methods)) { + throw new Services_Zencoder_Exception("Unsupported method call '$method' for Services_Zencoder_Reports"); + } + + // initialize query string parameters and optional overrides + $params = $opts = array(); + + // set query string parameters + if (isset($args[0]) && is_array($args[0])) { + $params = $args[0]; + } + + // set optional overrides + if (isset($args[1]) && is_array($args[1])) { + $opts = $args[1]; + } + + return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$method", $params, $opts), $method); + } + +} From 7396e99d7ed7398e55a072c0176a35348f768b31 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 10:47:43 +0200 Subject: [PATCH 02/24] add reports object to zencoder api --- Services/Zencoder.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Services/Zencoder.php b/Services/Zencoder.php index e5bf879..02b1953 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -88,6 +88,14 @@ class Services_Zencoder extends Services_Zencoder_Base * @var Services_Zencoder_Outputs */ public $outputs; + /** + * Provides access to the Zencoder Reports API + * + * Valid functions: vod, live, minutes, all + * + * @var Services_Zencoder_Reports + */ + public $reports; /** * Initialize the Services_Zencoder class and sub-classes. @@ -127,6 +135,7 @@ public function __construct( $this->jobs = new Services_Zencoder_Jobs($this); $this->notifications = new Services_Zencoder_Notifications($this); $this->outputs = new Services_Zencoder_Outputs($this); + $this->reports = new Services_Zencoder_Reports($this); } /** From c41ee1b72e8903533832daf27680ed6e1a322311 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 10:56:25 +0200 Subject: [PATCH 03/24] typo fixes --- Services/Zencoder.php | 4 ++-- Services/Zencoder/Reports.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Services/Zencoder.php b/Services/Zencoder.php index 02b1953..14f7e62 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -88,7 +88,7 @@ class Services_Zencoder extends Services_Zencoder_Base * @var Services_Zencoder_Outputs */ public $outputs; - /** + /** * Provides access to the Zencoder Reports API * * Valid functions: vod, live, minutes, all @@ -135,7 +135,7 @@ public function __construct( $this->jobs = new Services_Zencoder_Jobs($this); $this->notifications = new Services_Zencoder_Notifications($this); $this->outputs = new Services_Zencoder_Outputs($this); - $this->reports = new Services_Zencoder_Reports($this); + $this->reports = new Services_Zencoder_Reports($this); } /** diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index ad09cfe..fe82b00 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -15,7 +15,7 @@ class Services_Zencoder_Reports extends Services_Zencoder_Base { /** * A list of valid 'methods' to be trapped in __call() * - * @link @link https://app.zencoder.com/docs/api/reports/ + * @link https://app.zencoder.com/docs/api/reports/ * @var array */ protected $methods = array('vod', 'live', 'minutes', 'all'); From e433b13a08d090ee564898d509116763a5cad15f Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 16:32:27 +0200 Subject: [PATCH 04/24] auto-format --- Services/Zencoder/Report.php | 175 +++++++++++++++++----------------- Services/Zencoder/Reports.php | 88 ++++++++--------- 2 files changed, 131 insertions(+), 132 deletions(-) diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php index 2354cc1..48a7f75 100644 --- a/Services/Zencoder/Report.php +++ b/Services/Zencoder/Report.php @@ -12,103 +12,102 @@ */ class Services_Zencoder_Report extends Services_Zencoder_Object { - /** - * Array for statistics of the report - * - * @var array - */ - public $statistics = array(); + /** + * Array for statistics of the report + * + * @var array + */ + public $statistics = array(); - /** - * Holds the totals in case of single type of report - * - * @var mixed (Services_Zencoder_Report_VodTotal|Services_Zencoder_Report_LiveTotal) - */ - public $total; + /** + * Holds the totals in case of single type of report + * + * @var mixed (Services_Zencoder_Report_VodTotal|Services_Zencoder_Report_LiveTotal) + */ + public $total; - /** - * A copy of the raw API response for debug purposes - * - * @var mixed - */ - protected $raw_response; + /** + * A copy of the raw API response for debug purposes + * + * @var mixed + */ + protected $raw_response; - /** - * Flag to check if you will be filling array of arrays (when type = 'all') - * - * @var boolean - */ - protected $is_multiple = false; + /** + * Flag to check if you will be filling array of arrays (when type = 'all') + * + * @var boolean + */ + protected $is_multiple = false; - /** - * The type of report that is being fetched ('live', 'vod' 'minutes' or 'all') - * - * @var string - */ - protected $type; + /** + * The type of report that is being fetched ('live', 'vod' 'minutes' or 'all') + * + * @var string + */ + protected $type; - /** - * Create a new Services_Zencoder_Job object. - * - * @param mixed $params API response - * @param string $type The type of statistic we are fetching - */ - public function __construct($params, $type) { - $this->raw_response = $params; - $this->type = $type; - $this->is_multiple = $this->type === "all"; - $this->_update_attributes($params); - } + /** + * Create a new Services_Zencoder_Job object. + * + * @param mixed $params API response + * @param string $type The type of statistic we are fetching + */ + public function __construct($params, $type) { + $this->raw_response = $params; + $this->type = $type; + $this->is_multiple = $this->type === "all"; + $this->_update_attributes($params); + } - private function _update_attributes($attributes = array()) { - foreach ($attributes as $attr_name => $attr_value) { - if (($attr_name == "statistics")) { - if (!$this->is_multiple) { - $this->_create_statistics($attr_value, $this->type); - } else { - foreach ($attr_value as $type => $attrs) { - $this->_create_statistics($attrs, $type); - } - } - } elseif (($attr_name == "total")) { - if (!$this->is_multiple) { - $this->_create_totals($attr_value, $this->type); - } else { - foreach ($attr_value as $type => $attrs) { - $this->_create_totals($attrs, $type); - } - } - - } - } - } + private function _update_attributes($attributes = array()) { + foreach ($attributes as $attr_name => $attr_value) { + if (($attr_name == "statistics")) { + if (!$this->is_multiple) { + $this->_create_statistics($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_statistics($attrs, $type); + } + } + } elseif (($attr_name == "total")) { + if (!$this->is_multiple) { + $this->_create_totals($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_totals($attrs, $type); + } + } + } + } + } - private function _create_statistics($statistics = array(), $type = null) { - $class = $this->_get_report_class('statistic', $type); - if ($this->is_multiple) { - $this->statistics[$type] = array(); - } + private function _create_statistics($statistics = array(), $type = null) { + $class = $this->_get_report_class('statistic', $type); + if ($this->is_multiple) { + $this->statistics[$type] = array(); + } - foreach ($statistics as $stat_attrs) { - if ($this->is_multiple) { - $this->statistics[$type][] = new $class($stat_attrs); - } else { - $this->statistics[] = new $class($stat_attrs); - } - } - } + foreach ($statistics as $stat_attrs) { + if ($this->is_multiple) { + $this->statistics[$type][] = new $class($stat_attrs); + } else { + $this->statistics[] = new $class($stat_attrs); + } + } + } - private function _create_totals($totals, $type = null) { - $class = $this->_get_report_class('total', $type); - if ($this->is_multiple) { - $this->total[$type] = new $class($totals); - } else { - $this->total = new $class($totals); - } - } + private function _create_totals($totals, $type = null) { + $class = $this->_get_report_class('total', $type); + if ($this->is_multiple) { + $this->total[$type] = new $class($totals); + } else { + $this->total = new $class($totals); + } + } - private function _get_report_class($attr_name, $type) { - return 'Services_Zencoder_Report_' . ucwords($type) . ucwords($attr_name); - } + private function _get_report_class($attr_name, $type) { + return 'Services_Zencoder_Report_' . ucwords($type) . ucwords($attr_name); + } } diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index fe82b00..2019980 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -10,49 +10,49 @@ * @license http://creativecommons.org/licenses/MIT/MIT * @link http://github.com/zencoder/zencoder-php */ -class Services_Zencoder_Reports extends Services_Zencoder_Base { - - /** - * A list of valid 'methods' to be trapped in __call() - * - * @link https://app.zencoder.com/docs/api/reports/ - * @var array - */ - protected $methods = array('vod', 'live', 'minutes', 'all'); - - /** - * Return all reports for VOD - * - * @link https://app.zencoder.com/docs/api/reports - * - * @param string $method The method name indicates the type of report we want to get - * @param array $args A list of arguments for the overriden methods. Each methods takes 2 arguements. - * The first being an associative array of query string parameters and the second - * an associative array of option overrides - * - * @throws Services_Zencoder_Exception - * - * @return Services_Zencoder_Report The object representation of the resource - */ - public function __call($method, $args) { - if (!in_array($method, $this->methods)) { - throw new Services_Zencoder_Exception("Unsupported method call '$method' for Services_Zencoder_Reports"); - } - - // initialize query string parameters and optional overrides - $params = $opts = array(); - - // set query string parameters - if (isset($args[0]) && is_array($args[0])) { - $params = $args[0]; - } - - // set optional overrides - if (isset($args[1]) && is_array($args[1])) { - $opts = $args[1]; - } - - return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$method", $params, $opts), $method); - } +class Services_Zencoder_Reports extends Services_Zencoder_Base +{ + /** + * A list of valid 'methods' to be trapped in __call() + * + * @link https://app.zencoder.com/docs/api/reports/ + * @var array + */ + protected $methods = array('vod', 'live', 'minutes', 'all'); + + /** + * Return all reports for VOD + * + * @link https://app.zencoder.com/docs/api/reports + * + * @param string $method The method name indicates the type of report we want to get + * @param array $args A list of arguments for the overriden methods. Each methods takes 2 arguements. + * The first being an associative array of query string parameters and the second + * an associative array of option overrides + * + * @throws Services_Zencoder_Exception + * + * @return Services_Zencoder_Report The object representation of the resource + */ + public function __call($method, $args) { + if (!in_array($method, $this->methods)) { + throw new Services_Zencoder_Exception("Unsupported method call '$method' for Services_Zencoder_Reports"); + } + + // initialize query string parameters and optional overrides + $params = $opts = array(); + + // set query string parameters + if (isset($args[0]) && is_array($args[0])) { + $params = $args[0]; + } + + // set optional overrides + if (isset($args[1]) && is_array($args[1])) { + $opts = $args[1]; + } + + return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$method", $params, $opts), $method); + } } From 6798ce4a331ab3bb6b44929fdad113b148e92b6f Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 17:01:26 +0200 Subject: [PATCH 05/24] update README with reports api --- README.md | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/README.md b/README.md index 25a100b..66cef69 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ called: $zencoder->inputs->details($input_id); $zencoder->outputs->details($output_id); $zencoder->notifications->parseIncoming(); + $zencoder->reports->vod($array); + $zencoder->reports->all($array); 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. @@ -175,6 +177,78 @@ Then submit the job to test if it works. Modify the above script to meet your needs. Your [notifications page](https://app.zencoder.com/notifications) will come in handy. +REPORTS +---------------------- +The ZencoderReports class is used to get reports over the zencoder api. +See [reports api doc](https://app.zencoder.com/docs/api/reports) for required/optional parameters. + +### Get usage for VOD +Create a script to get usage for VOD + +#### Example + '2014-02-01', + 'to' => '2014-02-28', + ) + $reports = $zencoder->reports->vod($params); + // for live reports you just call the 'live' method i.e $reports = $zencoder->reports->live($params) ($params is optional) + + if ($reports->statistics) { + foreach ($reports->statistics as $statistic) { + print_r($statistic); + } + print_r($reports->total); + } else { + echo "no statistics found"; + } + + ?> + +### Get usage for VOD & Live +Get reports containing a breakdown of VOD and live-streaming usage. + +**see return structure at:** + + +#### Example + '2014-02-01', + 'to' => '2014-02-28', + ) + $reports = $zencoder->reports->all($params); + + // $reports->statistics if not empty will be an array with keys 'vod' and 'live' (same for $reports->total) + + if (!empty($reports->statistics['vod'])) { + foreach ($reports->statistics['vod'] as $statistic) { + print_r($statistic); + } + print_r($reports->total['vod']); + } else { + echo "no vod statistics found"; + } + + ?> + + VERSIONS --------- Version 2.1.1 - 2012-08-02 Fixing issue where jobs index call didn't return jobs as individual objects From dfe27dc2b0f1461f59a9a8b7647b4be8bf911635 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 17:14:57 +0200 Subject: [PATCH 06/24] use doc space format --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66cef69..0b99b00 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ called: $zencoder->inputs->details($input_id); $zencoder->outputs->details($output_id); $zencoder->notifications->parseIncoming(); - $zencoder->reports->vod($array); - $zencoder->reports->all($array); + $zencoder->reports->vod($array); + $zencoder->reports->all($array); 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. From 237615a70bdc699185d4abd8d2ce2f9743284bce Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Wed, 12 Mar 2014 10:00:03 +0200 Subject: [PATCH 07/24] update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0b99b00..5882e4b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ called: $zencoder->outputs->details($output_id); $zencoder->notifications->parseIncoming(); $zencoder->reports->vod($array); + $zencoder->reports->live($array); $zencoder->reports->all($array); Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception From 4607c612ecd87c4249202d2d21358d0d99e17162 Mon Sep 17 00:00:00 2001 From: Nathan Sutton Date: Mon, 28 Jul 2014 19:10:50 -0500 Subject: [PATCH 08/24] Update README.md for formatting --- README.md | 205 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 119 insertions(+), 86 deletions(-) diff --git a/README.md b/README.md index 5846df7..3a010a1 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ Zencoder API PHP Library ========================== 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, @@ -13,9 +17,13 @@ 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 @@ -29,18 +37,22 @@ 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. @@ -48,119 +60,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. ### 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(
+  // 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 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); + +?> +``` ### 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(); +// Catch notification +$notification = $zencoder->notifications->parseIncoming(); - // Check output/job state - if($notification->job->outputs[0]->state == "finished") { - echo "w00t!\n"; +// 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; - } + // 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. @@ -168,26 +195,32 @@ 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.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 From e03988cb0acac15c17769d882b89245430662985 Mon Sep 17 00:00:00 2001 From: Nathan Sutton Date: Mon, 28 Jul 2014 19:32:21 -0500 Subject: [PATCH 09/24] Make it so that you can set curl opts for CA paths and files --- Services/Zencoder.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Services/Zencoder.php b/Services/Zencoder.php index 6d453d7..d11a182 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -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,13 +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 - ), "api_key" => $api_key, "debug" => $debug) - ); + + $http_options = array("api_version" => $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); From 7673c4b2f3635e9b1999be16d309722ab01c2e48 Mon Sep 17 00:00:00 2001 From: Nathan Sutton Date: Tue, 29 Jul 2014 14:44:33 -0500 Subject: [PATCH 10/24] Bump version to 2.2.1 and add docs --- README.md | 22 ++++++++++++++++++++++ Services/Zencoder.php | 6 +++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3a010a1..152362d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,27 @@ Zencoder API PHP Library ========================== +Author: [Nathan Sutton] (nsutton (a) brightcove (.) com) + +Company: [Brightcove/Zencoder](http://www.zencoder.com) + +Version: 0.2.1 + +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) @@ -220,6 +241,7 @@ Your [notifications page](https://app.zencoder.com/notifications) will come in h VERSIONS --------- + Version 2.2.1 - 2014-07-29 Surrport 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 diff --git a/Services/Zencoder.php b/Services/Zencoder.php index d11a182..671380a 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -5,7 +5,7 @@ * @category Services * @package Services_Zencoder * @author Michael Christopher - * @version Release: 2.2.0 + * @version Release: 2.2.1 * @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.2.0 + * @version Release: 2.2.1 * @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.2.0'; + const USER_AGENT = 'ZencoderPHP v2.2.1'; /** * Contains the HTTP communication class From b3046f21747f7f5699da08cf66e8a488271760c8 Mon Sep 17 00:00:00 2001 From: Nathan Sutton Date: Tue, 29 Jul 2014 17:40:11 -0500 Subject: [PATCH 11/24] Fixing a bug where api_key was set as api_version in the http connection options --- Services/Zencoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Services/Zencoder.php b/Services/Zencoder.php index 671380a..be1cd0a 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -121,7 +121,7 @@ public function __construct( $this->version = $api_version; - $http_options = array("api_version" => $api_key, "debug" => $debug, "curlopts" => array(CURLOPT_USERAGENT => self::USER_AGENT)); + $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); } From f50a04534053bac0ea40b84c30f6c7760d29eddf Mon Sep 17 00:00:00 2001 From: Nathan Sutton Date: Tue, 29 Jul 2014 17:41:33 -0500 Subject: [PATCH 12/24] Documenting the changes in 2.2.2 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 152362d..b6bf454 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Author: [Nathan Sutton] (nsutton (a) brightcove (.) com) Company: [Brightcove/Zencoder](http://www.zencoder.com) -Version: 0.2.1 +Version: 2.2.2 Date: 2014-07-29 @@ -241,7 +241,8 @@ Your [notifications page](https://app.zencoder.com/notifications) will come in h VERSIONS --------- - Version 2.2.1 - 2014-07-29 Surrport setting CURLOPT_CAPATH and CURLOPT_CAINFO on cURL connections. + 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 From e2604c441163c36fd27097d8d9a22fcdf16d1ee4 Mon Sep 17 00:00:00 2001 From: Nathan Sutton Date: Tue, 29 Jul 2014 17:43:19 -0500 Subject: [PATCH 13/24] Fixed the versions listed in the user agent and throughout the code --- README.md | 3 ++- Services/Zencoder.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b6bf454..c002732 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Author: [Nathan Sutton] (nsutton (a) brightcove (.) com) Company: [Brightcove/Zencoder](http://www.zencoder.com) -Version: 2.2.2 +Version: 2.2.3 Date: 2014-07-29 @@ -241,6 +241,7 @@ Your [notifications page](https://app.zencoder.com/notifications) will come in h VERSIONS --------- + 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 diff --git a/Services/Zencoder.php b/Services/Zencoder.php index be1cd0a..ba8e209 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -5,7 +5,7 @@ * @category Services * @package Services_Zencoder * @author Michael Christopher - * @version Release: 2.2.1 + * @version Release: 2.2.3 * @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.2.1 + * @version Release: 2.2.3 * @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.2.1'; + const USER_AGENT = 'ZencoderPHP v2.2.3'; /** * Contains the HTTP communication class From 3fab4c9c9f0b8a13a15d82c009bcf6ebba50f0f2 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 10:43:27 +0200 Subject: [PATCH 14/24] add access to reports api --- Services/Zencoder/Report.php | 114 ++++++++++++++++++ Services/Zencoder/Report/LiveStatistic.php | 15 +++ Services/Zencoder/Report/LiveTotal.php | 15 +++ Services/Zencoder/Report/MinutesStatistic.php | 15 +++ Services/Zencoder/Report/MinutesTotal.php | 15 +++ Services/Zencoder/Report/VodStatistic.php | 15 +++ Services/Zencoder/Report/VodTotal.php | 15 +++ Services/Zencoder/Reports.php | 58 +++++++++ 8 files changed, 262 insertions(+) create mode 100644 Services/Zencoder/Report.php create mode 100644 Services/Zencoder/Report/LiveStatistic.php create mode 100644 Services/Zencoder/Report/LiveTotal.php create mode 100644 Services/Zencoder/Report/MinutesStatistic.php create mode 100644 Services/Zencoder/Report/MinutesTotal.php create mode 100644 Services/Zencoder/Report/VodStatistic.php create mode 100644 Services/Zencoder/Report/VodTotal.php create mode 100644 Services/Zencoder/Reports.php diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php new file mode 100644 index 0000000..2354cc1 --- /dev/null +++ b/Services/Zencoder/Report.php @@ -0,0 +1,114 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ +class Services_Zencoder_Report extends Services_Zencoder_Object { + + /** + * Array for statistics of the report + * + * @var array + */ + public $statistics = array(); + + /** + * Holds the totals in case of single type of report + * + * @var mixed (Services_Zencoder_Report_VodTotal|Services_Zencoder_Report_LiveTotal) + */ + public $total; + + /** + * A copy of the raw API response for debug purposes + * + * @var mixed + */ + protected $raw_response; + + /** + * Flag to check if you will be filling array of arrays (when type = 'all') + * + * @var boolean + */ + protected $is_multiple = false; + + /** + * The type of report that is being fetched ('live', 'vod' 'minutes' or 'all') + * + * @var string + */ + protected $type; + + /** + * Create a new Services_Zencoder_Job object. + * + * @param mixed $params API response + * @param string $type The type of statistic we are fetching + */ + public function __construct($params, $type) { + $this->raw_response = $params; + $this->type = $type; + $this->is_multiple = $this->type === "all"; + $this->_update_attributes($params); + } + + private function _update_attributes($attributes = array()) { + foreach ($attributes as $attr_name => $attr_value) { + if (($attr_name == "statistics")) { + if (!$this->is_multiple) { + $this->_create_statistics($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_statistics($attrs, $type); + } + } + } elseif (($attr_name == "total")) { + if (!$this->is_multiple) { + $this->_create_totals($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_totals($attrs, $type); + } + } + + } + } + } + + private function _create_statistics($statistics = array(), $type = null) { + $class = $this->_get_report_class('statistic', $type); + if ($this->is_multiple) { + $this->statistics[$type] = array(); + } + + foreach ($statistics as $stat_attrs) { + if ($this->is_multiple) { + $this->statistics[$type][] = new $class($stat_attrs); + } else { + $this->statistics[] = new $class($stat_attrs); + } + } + } + + private function _create_totals($totals, $type = null) { + $class = $this->_get_report_class('total', $type); + if ($this->is_multiple) { + $this->total[$type] = new $class($totals); + } else { + $this->total = new $class($totals); + } + } + + private function _get_report_class($attr_name, $type) { + return 'Services_Zencoder_Report_' . ucwords($type) . ucwords($attr_name); + } + +} diff --git a/Services/Zencoder/Report/LiveStatistic.php b/Services/Zencoder/Report/LiveStatistic.php new file mode 100644 index 0000000..693a952 --- /dev/null +++ b/Services/Zencoder/Report/LiveStatistic.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_LiveStatistic extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/LiveTotal.php b/Services/Zencoder/Report/LiveTotal.php new file mode 100644 index 0000000..b4615ce --- /dev/null +++ b/Services/Zencoder/Report/LiveTotal.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_LiveTotal extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/MinutesStatistic.php b/Services/Zencoder/Report/MinutesStatistic.php new file mode 100644 index 0000000..2739e70 --- /dev/null +++ b/Services/Zencoder/Report/MinutesStatistic.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_MinutesStatistic extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/MinutesTotal.php b/Services/Zencoder/Report/MinutesTotal.php new file mode 100644 index 0000000..5464982 --- /dev/null +++ b/Services/Zencoder/Report/MinutesTotal.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_MinutesTotal extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/VodStatistic.php b/Services/Zencoder/Report/VodStatistic.php new file mode 100644 index 0000000..d38c922 --- /dev/null +++ b/Services/Zencoder/Report/VodStatistic.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_VodStatistic extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Report/VodTotal.php b/Services/Zencoder/Report/VodTotal.php new file mode 100644 index 0000000..64fbdb6 --- /dev/null +++ b/Services/Zencoder/Report/VodTotal.php @@ -0,0 +1,15 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ + +class Services_Zencoder_Report_VodTotal extends Services_Zencoder_Object +{ +} diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php new file mode 100644 index 0000000..ad09cfe --- /dev/null +++ b/Services/Zencoder/Reports.php @@ -0,0 +1,58 @@ + + * @version Release: 2.1.2 + * @license http://creativecommons.org/licenses/MIT/MIT + * @link http://github.com/zencoder/zencoder-php + */ +class Services_Zencoder_Reports extends Services_Zencoder_Base { + + /** + * A list of valid 'methods' to be trapped in __call() + * + * @link @link https://app.zencoder.com/docs/api/reports/ + * @var array + */ + protected $methods = array('vod', 'live', 'minutes', 'all'); + + /** + * Return all reports for VOD + * + * @link https://app.zencoder.com/docs/api/reports + * + * @param string $method The method name indicates the type of report we want to get + * @param array $args A list of arguments for the overriden methods. Each methods takes 2 arguements. + * The first being an associative array of query string parameters and the second + * an associative array of option overrides + * + * @throws Services_Zencoder_Exception + * + * @return Services_Zencoder_Report The object representation of the resource + */ + public function __call($method, $args) { + if (!in_array($method, $this->methods)) { + throw new Services_Zencoder_Exception("Unsupported method call '$method' for Services_Zencoder_Reports"); + } + + // initialize query string parameters and optional overrides + $params = $opts = array(); + + // set query string parameters + if (isset($args[0]) && is_array($args[0])) { + $params = $args[0]; + } + + // set optional overrides + if (isset($args[1]) && is_array($args[1])) { + $opts = $args[1]; + } + + return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$method", $params, $opts), $method); + } + +} From 589c7c5d8065c2ba9bbac3fc655f78795eadd7bd Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 10:47:43 +0200 Subject: [PATCH 15/24] add reports object to zencoder api --- Services/Zencoder.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Services/Zencoder.php b/Services/Zencoder.php index ba8e209..795d9f2 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -88,6 +88,14 @@ class Services_Zencoder extends Services_Zencoder_Base * @var Services_Zencoder_Outputs */ public $outputs; + /** + * Provides access to the Zencoder Reports API + * + * Valid functions: vod, live, minutes, all + * + * @var Services_Zencoder_Reports + */ + public $reports; /** * Initialize the Services_Zencoder class and sub-classes. @@ -135,6 +143,7 @@ public function __construct( $this->jobs = new Services_Zencoder_Jobs($this); $this->notifications = new Services_Zencoder_Notifications($this); $this->outputs = new Services_Zencoder_Outputs($this); + $this->reports = new Services_Zencoder_Reports($this); } /** From c028c532cafc2db548f1e1b848c411a333bd5eda Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 10:56:25 +0200 Subject: [PATCH 16/24] typo fixes --- Services/Zencoder.php | 4 ++-- Services/Zencoder/Reports.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Services/Zencoder.php b/Services/Zencoder.php index 795d9f2..050bd64 100644 --- a/Services/Zencoder.php +++ b/Services/Zencoder.php @@ -88,7 +88,7 @@ class Services_Zencoder extends Services_Zencoder_Base * @var Services_Zencoder_Outputs */ public $outputs; - /** + /** * Provides access to the Zencoder Reports API * * Valid functions: vod, live, minutes, all @@ -143,7 +143,7 @@ public function __construct( $this->jobs = new Services_Zencoder_Jobs($this); $this->notifications = new Services_Zencoder_Notifications($this); $this->outputs = new Services_Zencoder_Outputs($this); - $this->reports = new Services_Zencoder_Reports($this); + $this->reports = new Services_Zencoder_Reports($this); } /** diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index ad09cfe..fe82b00 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -15,7 +15,7 @@ class Services_Zencoder_Reports extends Services_Zencoder_Base { /** * A list of valid 'methods' to be trapped in __call() * - * @link @link https://app.zencoder.com/docs/api/reports/ + * @link https://app.zencoder.com/docs/api/reports/ * @var array */ protected $methods = array('vod', 'live', 'minutes', 'all'); From bde0dd2d3729dfd0fb94d3e0790456ee65e2acd5 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 16:32:27 +0200 Subject: [PATCH 17/24] auto-format --- Services/Zencoder/Report.php | 175 +++++++++++++++++----------------- Services/Zencoder/Reports.php | 88 ++++++++--------- 2 files changed, 131 insertions(+), 132 deletions(-) diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php index 2354cc1..48a7f75 100644 --- a/Services/Zencoder/Report.php +++ b/Services/Zencoder/Report.php @@ -12,103 +12,102 @@ */ class Services_Zencoder_Report extends Services_Zencoder_Object { - /** - * Array for statistics of the report - * - * @var array - */ - public $statistics = array(); + /** + * Array for statistics of the report + * + * @var array + */ + public $statistics = array(); - /** - * Holds the totals in case of single type of report - * - * @var mixed (Services_Zencoder_Report_VodTotal|Services_Zencoder_Report_LiveTotal) - */ - public $total; + /** + * Holds the totals in case of single type of report + * + * @var mixed (Services_Zencoder_Report_VodTotal|Services_Zencoder_Report_LiveTotal) + */ + public $total; - /** - * A copy of the raw API response for debug purposes - * - * @var mixed - */ - protected $raw_response; + /** + * A copy of the raw API response for debug purposes + * + * @var mixed + */ + protected $raw_response; - /** - * Flag to check if you will be filling array of arrays (when type = 'all') - * - * @var boolean - */ - protected $is_multiple = false; + /** + * Flag to check if you will be filling array of arrays (when type = 'all') + * + * @var boolean + */ + protected $is_multiple = false; - /** - * The type of report that is being fetched ('live', 'vod' 'minutes' or 'all') - * - * @var string - */ - protected $type; + /** + * The type of report that is being fetched ('live', 'vod' 'minutes' or 'all') + * + * @var string + */ + protected $type; - /** - * Create a new Services_Zencoder_Job object. - * - * @param mixed $params API response - * @param string $type The type of statistic we are fetching - */ - public function __construct($params, $type) { - $this->raw_response = $params; - $this->type = $type; - $this->is_multiple = $this->type === "all"; - $this->_update_attributes($params); - } + /** + * Create a new Services_Zencoder_Job object. + * + * @param mixed $params API response + * @param string $type The type of statistic we are fetching + */ + public function __construct($params, $type) { + $this->raw_response = $params; + $this->type = $type; + $this->is_multiple = $this->type === "all"; + $this->_update_attributes($params); + } - private function _update_attributes($attributes = array()) { - foreach ($attributes as $attr_name => $attr_value) { - if (($attr_name == "statistics")) { - if (!$this->is_multiple) { - $this->_create_statistics($attr_value, $this->type); - } else { - foreach ($attr_value as $type => $attrs) { - $this->_create_statistics($attrs, $type); - } - } - } elseif (($attr_name == "total")) { - if (!$this->is_multiple) { - $this->_create_totals($attr_value, $this->type); - } else { - foreach ($attr_value as $type => $attrs) { - $this->_create_totals($attrs, $type); - } - } - - } - } - } + private function _update_attributes($attributes = array()) { + foreach ($attributes as $attr_name => $attr_value) { + if (($attr_name == "statistics")) { + if (!$this->is_multiple) { + $this->_create_statistics($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_statistics($attrs, $type); + } + } + } elseif (($attr_name == "total")) { + if (!$this->is_multiple) { + $this->_create_totals($attr_value, $this->type); + } else { + foreach ($attr_value as $type => $attrs) { + $this->_create_totals($attrs, $type); + } + } + } + } + } - private function _create_statistics($statistics = array(), $type = null) { - $class = $this->_get_report_class('statistic', $type); - if ($this->is_multiple) { - $this->statistics[$type] = array(); - } + private function _create_statistics($statistics = array(), $type = null) { + $class = $this->_get_report_class('statistic', $type); + if ($this->is_multiple) { + $this->statistics[$type] = array(); + } - foreach ($statistics as $stat_attrs) { - if ($this->is_multiple) { - $this->statistics[$type][] = new $class($stat_attrs); - } else { - $this->statistics[] = new $class($stat_attrs); - } - } - } + foreach ($statistics as $stat_attrs) { + if ($this->is_multiple) { + $this->statistics[$type][] = new $class($stat_attrs); + } else { + $this->statistics[] = new $class($stat_attrs); + } + } + } - private function _create_totals($totals, $type = null) { - $class = $this->_get_report_class('total', $type); - if ($this->is_multiple) { - $this->total[$type] = new $class($totals); - } else { - $this->total = new $class($totals); - } - } + private function _create_totals($totals, $type = null) { + $class = $this->_get_report_class('total', $type); + if ($this->is_multiple) { + $this->total[$type] = new $class($totals); + } else { + $this->total = new $class($totals); + } + } - private function _get_report_class($attr_name, $type) { - return 'Services_Zencoder_Report_' . ucwords($type) . ucwords($attr_name); - } + private function _get_report_class($attr_name, $type) { + return 'Services_Zencoder_Report_' . ucwords($type) . ucwords($attr_name); + } } diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index fe82b00..2019980 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -10,49 +10,49 @@ * @license http://creativecommons.org/licenses/MIT/MIT * @link http://github.com/zencoder/zencoder-php */ -class Services_Zencoder_Reports extends Services_Zencoder_Base { - - /** - * A list of valid 'methods' to be trapped in __call() - * - * @link https://app.zencoder.com/docs/api/reports/ - * @var array - */ - protected $methods = array('vod', 'live', 'minutes', 'all'); - - /** - * Return all reports for VOD - * - * @link https://app.zencoder.com/docs/api/reports - * - * @param string $method The method name indicates the type of report we want to get - * @param array $args A list of arguments for the overriden methods. Each methods takes 2 arguements. - * The first being an associative array of query string parameters and the second - * an associative array of option overrides - * - * @throws Services_Zencoder_Exception - * - * @return Services_Zencoder_Report The object representation of the resource - */ - public function __call($method, $args) { - if (!in_array($method, $this->methods)) { - throw new Services_Zencoder_Exception("Unsupported method call '$method' for Services_Zencoder_Reports"); - } - - // initialize query string parameters and optional overrides - $params = $opts = array(); - - // set query string parameters - if (isset($args[0]) && is_array($args[0])) { - $params = $args[0]; - } - - // set optional overrides - if (isset($args[1]) && is_array($args[1])) { - $opts = $args[1]; - } - - return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$method", $params, $opts), $method); - } +class Services_Zencoder_Reports extends Services_Zencoder_Base +{ + /** + * A list of valid 'methods' to be trapped in __call() + * + * @link https://app.zencoder.com/docs/api/reports/ + * @var array + */ + protected $methods = array('vod', 'live', 'minutes', 'all'); + + /** + * Return all reports for VOD + * + * @link https://app.zencoder.com/docs/api/reports + * + * @param string $method The method name indicates the type of report we want to get + * @param array $args A list of arguments for the overriden methods. Each methods takes 2 arguements. + * The first being an associative array of query string parameters and the second + * an associative array of option overrides + * + * @throws Services_Zencoder_Exception + * + * @return Services_Zencoder_Report The object representation of the resource + */ + public function __call($method, $args) { + if (!in_array($method, $this->methods)) { + throw new Services_Zencoder_Exception("Unsupported method call '$method' for Services_Zencoder_Reports"); + } + + // initialize query string parameters and optional overrides + $params = $opts = array(); + + // set query string parameters + if (isset($args[0]) && is_array($args[0])) { + $params = $args[0]; + } + + // set optional overrides + if (isset($args[1]) && is_array($args[1])) { + $opts = $args[1]; + } + + return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$method", $params, $opts), $method); + } } From c09bf2ca3692c13f7a8bdc02686638cbecd5d369 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 17:01:26 +0200 Subject: [PATCH 18/24] update README with reports api --- .gitignore | 1 + README.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/.gitignore b/.gitignore index f7c5815..7056076 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ test.php build_docs.sh .DS_Store +/nbproject/ \ No newline at end of file diff --git a/README.md b/README.md index c002732..434a116 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,78 @@ Modify the above script to meet your needs. Your [notifications page](https://app.zencoder.com/notifications) will come in handy. +REPORTS +---------------------- +The ZencoderReports class is used to get reports over the zencoder api. +See [reports api doc](https://app.zencoder.com/docs/api/reports) for required/optional parameters. + +### Get usage for VOD +Create a script to get usage for VOD + +#### Example + '2014-02-01', + 'to' => '2014-02-28', + ) + $reports = $zencoder->reports->vod($params); + // for live reports you just call the 'live' method i.e $reports = $zencoder->reports->live($params) ($params is optional) + + if ($reports->statistics) { + foreach ($reports->statistics as $statistic) { + print_r($statistic); + } + print_r($reports->total); + } else { + echo "no statistics found"; + } + + ?> + +### Get usage for VOD & Live +Get reports containing a breakdown of VOD and live-streaming usage. + +**see return structure at:** + + +#### Example + '2014-02-01', + 'to' => '2014-02-28', + ) + $reports = $zencoder->reports->all($params); + + // $reports->statistics if not empty will be an array with keys 'vod' and 'live' (same for $reports->total) + + if (!empty($reports->statistics['vod'])) { + foreach ($reports->statistics['vod'] as $statistic) { + print_r($statistic); + } + print_r($reports->total['vod']); + } else { + echo "no vod statistics found"; + } + + ?> + + VERSIONS --------- From 9463c66ba9b0c774c4e00e16109f22d69d8847c2 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Wed, 8 Jul 2015 14:53:24 +0200 Subject: [PATCH 19/24] fix merge error --- README.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4ea45d0..a3325d2 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,6 @@ Once you have created the object, you can use it to interact with the API. For f see the Documentation folder, but here is a quick overview of some of the functions that can be called: -<<<<<<< HEAD ```php $zencoder->accounts->create($array); $zencoder->jobs->create($array); @@ -74,18 +73,10 @@ $zencoder->jobs->progress($job_id); $zencoder->inputs->details($input_id); $zencoder->outputs->details($output_id); $zencoder->notifications->parseIncoming(); +$zencoder->reports->vod($array); +$zencoder->reports->live($array); +$zencoder->reports->all($array); ``` -======= - $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(); - $zencoder->reports->vod($array); - $zencoder->reports->live($array); - $zencoder->reports->all($array); ->>>>>>> 237615a70bdc699185d4abd8d2ce2f9743284bce 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. From 7b745621d3e5740a82966a1ac531512218810ba1 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Wed, 8 Jul 2015 16:10:42 +0200 Subject: [PATCH 20/24] remove casting to different types of reports --- .gitignore | 3 +- Services/Zencoder/Report.php | 87 +++---------------- Services/Zencoder/Report/LiveStatistic.php | 15 ---- Services/Zencoder/Report/LiveTotal.php | 15 ---- Services/Zencoder/Report/MinutesStatistic.php | 15 ---- Services/Zencoder/Report/MinutesTotal.php | 15 ---- Services/Zencoder/Report/VodStatistic.php | 15 ---- Services/Zencoder/Report/VodTotal.php | 15 ---- Services/Zencoder/Reports.php | 47 +++------- 9 files changed, 24 insertions(+), 203 deletions(-) delete mode 100644 Services/Zencoder/Report/LiveStatistic.php delete mode 100644 Services/Zencoder/Report/LiveTotal.php delete mode 100644 Services/Zencoder/Report/MinutesStatistic.php delete mode 100644 Services/Zencoder/Report/MinutesTotal.php delete mode 100644 Services/Zencoder/Report/VodStatistic.php delete mode 100644 Services/Zencoder/Report/VodTotal.php diff --git a/.gitignore b/.gitignore index 7056076..042245b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ test.php build_docs.sh .DS_Store - -/nbproject/ \ No newline at end of file +/nbproject/ diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php index 48a7f75..dac7977 100644 --- a/Services/Zencoder/Report.php +++ b/Services/Zencoder/Report.php @@ -13,16 +13,16 @@ class Services_Zencoder_Report extends Services_Zencoder_Object { /** - * Array for statistics of the report + * Statistics of a report * - * @var array + * @var object */ - public $statistics = array(); + public $statistics; /** - * Holds the totals in case of single type of report + * Totals of a of report * - * @var mixed (Services_Zencoder_Report_VodTotal|Services_Zencoder_Report_LiveTotal) + * @var object */ public $total; @@ -34,80 +34,17 @@ class Services_Zencoder_Report extends Services_Zencoder_Object { protected $raw_response; /** - * Flag to check if you will be filling array of arrays (when type = 'all') - * - * @var boolean - */ - protected $is_multiple = false; - - /** - * The type of report that is being fetched ('live', 'vod' 'minutes' or 'all') - * - * @var string - */ - protected $type; - - /** - * Create a new Services_Zencoder_Job object. + * Create a new Services_Zencoder_Report object. + * For attributes of the various kinds of reports, see + * @link https://app.zencoder.com/docs/api/reports/vod + * @link https://app.zencoder.com/docs/api/reports/live + * @link https://app.zencoder.com/docs/api/reports/all * * @param mixed $params API response * @param string $type The type of statistic we are fetching */ - public function __construct($params, $type) { + public function __construct($params) { $this->raw_response = $params; - $this->type = $type; - $this->is_multiple = $this->type === "all"; - $this->_update_attributes($params); - } - - private function _update_attributes($attributes = array()) { - foreach ($attributes as $attr_name => $attr_value) { - if (($attr_name == "statistics")) { - if (!$this->is_multiple) { - $this->_create_statistics($attr_value, $this->type); - } else { - foreach ($attr_value as $type => $attrs) { - $this->_create_statistics($attrs, $type); - } - } - } elseif (($attr_name == "total")) { - if (!$this->is_multiple) { - $this->_create_totals($attr_value, $this->type); - } else { - foreach ($attr_value as $type => $attrs) { - $this->_create_totals($attrs, $type); - } - } - } - } + parent::__construct($params); } - - private function _create_statistics($statistics = array(), $type = null) { - $class = $this->_get_report_class('statistic', $type); - if ($this->is_multiple) { - $this->statistics[$type] = array(); - } - - foreach ($statistics as $stat_attrs) { - if ($this->is_multiple) { - $this->statistics[$type][] = new $class($stat_attrs); - } else { - $this->statistics[] = new $class($stat_attrs); - } - } - } - - private function _create_totals($totals, $type = null) { - $class = $this->_get_report_class('total', $type); - if ($this->is_multiple) { - $this->total[$type] = new $class($totals); - } else { - $this->total = new $class($totals); - } - } - - private function _get_report_class($attr_name, $type) { - return 'Services_Zencoder_Report_' . ucwords($type) . ucwords($attr_name); - } - } diff --git a/Services/Zencoder/Report/LiveStatistic.php b/Services/Zencoder/Report/LiveStatistic.php deleted file mode 100644 index 693a952..0000000 --- a/Services/Zencoder/Report/LiveStatistic.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @version Release: 2.1.2 - * @license http://creativecommons.org/licenses/MIT/MIT - * @link http://github.com/zencoder/zencoder-php - */ - -class Services_Zencoder_Report_LiveStatistic extends Services_Zencoder_Object -{ -} diff --git a/Services/Zencoder/Report/LiveTotal.php b/Services/Zencoder/Report/LiveTotal.php deleted file mode 100644 index b4615ce..0000000 --- a/Services/Zencoder/Report/LiveTotal.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @version Release: 2.1.2 - * @license http://creativecommons.org/licenses/MIT/MIT - * @link http://github.com/zencoder/zencoder-php - */ - -class Services_Zencoder_Report_LiveTotal extends Services_Zencoder_Object -{ -} diff --git a/Services/Zencoder/Report/MinutesStatistic.php b/Services/Zencoder/Report/MinutesStatistic.php deleted file mode 100644 index 2739e70..0000000 --- a/Services/Zencoder/Report/MinutesStatistic.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @version Release: 2.1.2 - * @license http://creativecommons.org/licenses/MIT/MIT - * @link http://github.com/zencoder/zencoder-php - */ - -class Services_Zencoder_Report_MinutesStatistic extends Services_Zencoder_Object -{ -} diff --git a/Services/Zencoder/Report/MinutesTotal.php b/Services/Zencoder/Report/MinutesTotal.php deleted file mode 100644 index 5464982..0000000 --- a/Services/Zencoder/Report/MinutesTotal.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @version Release: 2.1.2 - * @license http://creativecommons.org/licenses/MIT/MIT - * @link http://github.com/zencoder/zencoder-php - */ - -class Services_Zencoder_Report_MinutesTotal extends Services_Zencoder_Object -{ -} diff --git a/Services/Zencoder/Report/VodStatistic.php b/Services/Zencoder/Report/VodStatistic.php deleted file mode 100644 index d38c922..0000000 --- a/Services/Zencoder/Report/VodStatistic.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @version Release: 2.1.2 - * @license http://creativecommons.org/licenses/MIT/MIT - * @link http://github.com/zencoder/zencoder-php - */ - -class Services_Zencoder_Report_VodStatistic extends Services_Zencoder_Object -{ -} diff --git a/Services/Zencoder/Report/VodTotal.php b/Services/Zencoder/Report/VodTotal.php deleted file mode 100644 index 64fbdb6..0000000 --- a/Services/Zencoder/Report/VodTotal.php +++ /dev/null @@ -1,15 +0,0 @@ - - * @version Release: 2.1.2 - * @license http://creativecommons.org/licenses/MIT/MIT - * @link http://github.com/zencoder/zencoder-php - */ - -class Services_Zencoder_Report_VodTotal extends Services_Zencoder_Object -{ -} diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index 2019980..dd692d1 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -12,47 +12,22 @@ */ class Services_Zencoder_Reports extends Services_Zencoder_Base { - /** - * A list of valid 'methods' to be trapped in __call() - * - * @link https://app.zencoder.com/docs/api/reports/ - * @var array - */ - protected $methods = array('vod', 'live', 'minutes', 'all'); - - /** - * Return all reports for VOD + /** + * Get details about different types of reports * * @link https://app.zencoder.com/docs/api/reports * - * @param string $method The method name indicates the type of report we want to get - * @param array $args A list of arguments for the overriden methods. Each methods takes 2 arguements. - * The first being an associative array of query string parameters and the second - * an associative array of option overrides - * - * @throws Services_Zencoder_Exception + * @param string $report_type The type of report to get. The following are currently supported over the api + * - 'all' : Returns all reports, both VOD and LIVE + * - 'vod' : Returns VOD reports + * - 'live': Return LIVE reports + * @param array $params An associated array of optional query parameters per requested report type + * @param array $opts Optional overrides * * @return Services_Zencoder_Report The object representation of the resource */ - public function __call($method, $args) { - if (!in_array($method, $this->methods)) { - throw new Services_Zencoder_Exception("Unsupported method call '$method' for Services_Zencoder_Reports"); - } - - // initialize query string parameters and optional overrides - $params = $opts = array(); - - // set query string parameters - if (isset($args[0]) && is_array($args[0])) { - $params = $args[0]; - } - - // set optional overrides - if (isset($args[1]) && is_array($args[1])) { - $opts = $args[1]; - } - - return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$method", $params, $opts), $method); - } + public function details($report_type, $params = array(), $opts = array()) { + return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$report_type", $params, $opts)); + } } From bd90317c075025d979a20d6466ef3221d839eafc Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Wed, 8 Jul 2015 16:13:29 +0200 Subject: [PATCH 21/24] autoformat --- Services/Zencoder/Report.php | 57 ++++++++++++++++++----------------- Services/Zencoder/Reports.php | 28 ++++++++--------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php index dac7977..3d3eee4 100644 --- a/Services/Zencoder/Report.php +++ b/Services/Zencoder/Report.php @@ -12,39 +12,40 @@ */ class Services_Zencoder_Report extends Services_Zencoder_Object { - /** - * Statistics of a report - * - * @var object - */ - public $statistics; + /** + * Statistics of a report + * + * @var object + */ + public $statistics; - /** - * Totals of a of report - * - * @var object - */ - public $total; + /** + * Totals of a of report + * + * @var object + */ + public $total; - /** - * A copy of the raw API response for debug purposes - * - * @var mixed - */ - protected $raw_response; + /** + * A copy of the raw API response for debug purposes + * + * @var mixed + */ + protected $raw_response; - /** - * Create a new Services_Zencoder_Report object. + /** + * Create a new Services_Zencoder_Report object. * For attributes of the various kinds of reports, see * @link https://app.zencoder.com/docs/api/reports/vod * @link https://app.zencoder.com/docs/api/reports/live * @link https://app.zencoder.com/docs/api/reports/all - * - * @param mixed $params API response - * @param string $type The type of statistic we are fetching - */ - public function __construct($params) { - $this->raw_response = $params; - parent::__construct($params); - } + * + * @param mixed $params API response + * @param string $type The type of statistic we are fetching + */ + public function __construct($params) { + $this->raw_response = $params; + parent::__construct($params); + } + } diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index dd692d1..4a68934 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -10,22 +10,22 @@ * @license http://creativecommons.org/licenses/MIT/MIT * @link http://github.com/zencoder/zencoder-php */ -class Services_Zencoder_Reports extends Services_Zencoder_Base -{ +class Services_Zencoder_Reports extends Services_Zencoder_Base { + /** - * Get details about different types of reports - * - * @link https://app.zencoder.com/docs/api/reports - * - * @param string $report_type The type of report to get. The following are currently supported over the api - * - 'all' : Returns all reports, both VOD and LIVE - * - 'vod' : Returns VOD reports - * - 'live': Return LIVE reports - * @param array $params An associated array of optional query parameters per requested report type + * Get details about different types of reports + * + * @link https://app.zencoder.com/docs/api/reports + * + * @param string $report_type The type of report to get. The following are currently supported over the api + * - 'all' : Returns all reports, both VOD and LIVE + * - 'vod' : Returns VOD reports + * - 'live': Return LIVE reports + * @param array $params An associated array of optional query parameters per requested report type * @param array $opts Optional overrides - * - * @return Services_Zencoder_Report The object representation of the resource - */ + * + * @return Services_Zencoder_Report The object representation of the resource + */ public function details($report_type, $params = array(), $opts = array()) { return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$report_type", $params, $opts)); } From 0654a2849a397e3869a4a641327dad9a82d7ed63 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Wed, 8 Jul 2015 21:45:29 +0200 Subject: [PATCH 22/24] update Readme --- README.md | 57 ++++++----------------------------- Services/Zencoder/Reports.php | 2 +- 2 files changed, 11 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index a3325d2..77fc72c 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,7 @@ $zencoder->jobs->progress($job_id); $zencoder->inputs->details($input_id); $zencoder->outputs->details($output_id); $zencoder->notifications->parseIncoming(); -$zencoder->reports->vod($array); -$zencoder->reports->live($array); -$zencoder->reports->all($array); +$zencoder->reports->details($report_type, $optional_params); ``` Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception @@ -250,7 +248,7 @@ See [reports api doc](https://app.zencoder.com/docs/api/reports) for required/op Create a script to get usage for VOD #### Example - '2014-02-01', - 'to' => '2014-02-28', - ) - $reports = $zencoder->reports->vod($params); - // for live reports you just call the 'live' method i.e $reports = $zencoder->reports->live($params) ($params is optional) - + $params = array( + 'from' => '2014-02-01', + 'to' => '2014-02-28', + ) + // 'all' can be replaced by 'vod' or 'live' acccording to entry points in docs + $reports = $zencoder->reports->details('all', $params); + // Each reports object should have a 'statistics' and 'total' base element if ($reports->statistics) { foreach ($reports->statistics as $statistic) { print_r($statistic); @@ -275,42 +273,7 @@ Create a script to get usage for VOD echo "no statistics found"; } - ?> - -### Get usage for VOD & Live -Get reports containing a breakdown of VOD and live-streaming usage. - -**see return structure at:** - - -#### Example - '2014-02-01', - 'to' => '2014-02-28', - ) - $reports = $zencoder->reports->all($params); - - // $reports->statistics if not empty will be an array with keys 'vod' and 'live' (same for $reports->total) - - if (!empty($reports->statistics['vod'])) { - foreach ($reports->statistics['vod'] as $statistic) { - print_r($statistic); - } - print_r($reports->total['vod']); - } else { - echo "no vod statistics found"; - } - - ?> +``` VERSIONS diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index 4a68934..d2ba22b 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -26,7 +26,7 @@ class Services_Zencoder_Reports extends Services_Zencoder_Base { * * @return Services_Zencoder_Report The object representation of the resource */ - public function details($report_type, $params = array(), $opts = array()) { + public function details($report_type = 'all', $params = array(), $opts = array()) { return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$report_type", $params, $opts)); } From 28b1cfd41893d61a9a7eb93a58ace9a04422cb1a Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Wed, 8 Jul 2015 21:50:48 +0200 Subject: [PATCH 23/24] autoformat --- README.md | 20 ++++++----- Services/Zencoder/Report.php | 64 +++++++++++++++++------------------ Services/Zencoder/Reports.php | 34 +++++++++---------- 3 files changed, 60 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 77fc72c..e157243 100644 --- a/README.md +++ b/README.md @@ -261,17 +261,19 @@ Create a script to get usage for VOD 'from' => '2014-02-01', 'to' => '2014-02-28', ) + // 'all' can be replaced by 'vod' or 'live' acccording to entry points in docs - $reports = $zencoder->reports->details('all', $params); - // Each reports object should have a 'statistics' and 'total' base element - if ($reports->statistics) { - foreach ($reports->statistics as $statistic) { - print_r($statistic); - } - print_r($reports->total); - } else { - echo "no statistics found"; + $report = $zencoder->reports->details('all', $params); + + // Each reports object should have a 'statistics' and 'total' base element + if ($report->statistics) { + foreach ($report->statistics as $statistic) { + print_r($statistic); } + print_r($report->total); + } else { + echo "no statistics found"; + } ``` diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php index 3d3eee4..abc16df 100644 --- a/Services/Zencoder/Report.php +++ b/Services/Zencoder/Report.php @@ -12,40 +12,40 @@ */ class Services_Zencoder_Report extends Services_Zencoder_Object { - /** - * Statistics of a report - * - * @var object - */ - public $statistics; + /** + * Statistics of a report + * + * @var object + */ + public $statistics; - /** - * Totals of a of report - * - * @var object - */ - public $total; + /** + * Totals of a of report + * + * @var object + */ + public $total; - /** - * A copy of the raw API response for debug purposes - * - * @var mixed - */ - protected $raw_response; + /** + * A copy of the raw API response for debug purposes + * + * @var mixed + */ + protected $raw_response; - /** - * Create a new Services_Zencoder_Report object. - * For attributes of the various kinds of reports, see - * @link https://app.zencoder.com/docs/api/reports/vod - * @link https://app.zencoder.com/docs/api/reports/live - * @link https://app.zencoder.com/docs/api/reports/all - * - * @param mixed $params API response - * @param string $type The type of statistic we are fetching - */ - public function __construct($params) { - $this->raw_response = $params; - parent::__construct($params); - } + /** + * Create a new Services_Zencoder_Report object. + * For attributes of the various kinds of reports, see + * @link https://app.zencoder.com/docs/api/reports/vod + * @link https://app.zencoder.com/docs/api/reports/live + * @link https://app.zencoder.com/docs/api/reports/all + * + * @param mixed $params API response + * @param string $type The type of statistic we are fetching + */ + public function __construct($params) { + $this->raw_response = $params; + parent::__construct($params); + } } diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php index d2ba22b..2d4d6fd 100644 --- a/Services/Zencoder/Reports.php +++ b/Services/Zencoder/Reports.php @@ -12,22 +12,22 @@ */ class Services_Zencoder_Reports extends Services_Zencoder_Base { - /** - * Get details about different types of reports - * - * @link https://app.zencoder.com/docs/api/reports - * - * @param string $report_type The type of report to get. The following are currently supported over the api - * - 'all' : Returns all reports, both VOD and LIVE - * - 'vod' : Returns VOD reports - * - 'live': Return LIVE reports - * @param array $params An associated array of optional query parameters per requested report type - * @param array $opts Optional overrides - * - * @return Services_Zencoder_Report The object representation of the resource - */ - public function details($report_type = 'all', $params = array(), $opts = array()) { - return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$report_type", $params, $opts)); - } + /** + * Get details about different types of reports + * + * @link https://app.zencoder.com/docs/api/reports + * + * @param string $report_type The type of report to get. The following are currently supported over the api + * - 'all' : Returns all reports, both VOD and LIVE + * - 'vod' : Returns VOD reports + * - 'live': Return LIVE reports + * @param array $params An associated array of optional query parameters per requested report type + * @param array $opts Optional overrides + * + * @return Services_Zencoder_Report The object representation of the resource + */ + public function details($report_type = 'all', $params = array(), $opts = array()) { + return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$report_type", $params, $opts)); + } } From 86c4a2f6a99c0d23f0236ae5e083a6d930cc0797 Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Wed, 8 Jul 2015 21:57:49 +0200 Subject: [PATCH 24/24] format doc code --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e157243..a622c4b 100644 --- a/README.md +++ b/README.md @@ -244,8 +244,8 @@ REPORTS The ZencoderReports class is used to get reports over the zencoder api. See [reports api doc](https://app.zencoder.com/docs/api/reports) for required/optional parameters. -### Get usage for VOD -Create a script to get usage for VOD +### Get usage for ALL reports +Create a script to get reports for a specified date range #### Example ```php @@ -258,8 +258,8 @@ Create a script to get usage for VOD // Get reports $params = array( - 'from' => '2014-02-01', - 'to' => '2014-02-28', + 'from' => '2014-02-01', + 'to' => '2014-02-28', ) // 'all' can be replaced by 'vod' or 'live' acccording to entry points in docs @@ -267,12 +267,12 @@ Create a script to get usage for VOD // Each reports object should have a 'statistics' and 'total' base element if ($report->statistics) { - foreach ($report->statistics as $statistic) { - print_r($statistic); - } - print_r($report->total); + foreach ($report->statistics as $statistic) { + print_r($statistic); + } + print_r($report->total); } else { - echo "no statistics found"; + echo "no statistics found"; } ```