From 52ff131735b383c165ad005392257119ab14309a Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 11 Mar 2014 10:43:27 +0200 Subject: [PATCH] Add access to reports API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Elan Ruusamäe --- .gitignore | 2 +- README.md | 40 +++++++++++++++++++++++++++ Services/Zencoder.php | 9 +++++++ Services/Zencoder/Report.php | 51 +++++++++++++++++++++++++++++++++++ Services/Zencoder/Reports.php | 33 +++++++++++++++++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 Services/Zencoder/Report.php create mode 100644 Services/Zencoder/Reports.php diff --git a/.gitignore b/.gitignore index f7c5815..042245b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ test.php build_docs.sh .DS_Store - +/nbproject/ diff --git a/README.md b/README.md index eaba01f..700a748 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ $zencoder->jobs->progress($job_id); $zencoder->inputs->details($input_id); $zencoder->outputs->details($output_id); $zencoder->notifications->parseIncoming(); +$zencoder->reports->details($report_type, $optional_params); ``` Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception @@ -249,6 +250,45 @@ 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 ALL reports +Create a script to get reports for a specified date range + +#### Example +```php + + // Make sure this points to a copy of Zencoder.php on the same server as this script. + require_once('Services/Zencoder.php'); + + // Initialize the Services_Zencoder class + $zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3'); + + // Get reports + $params = array( + 'from' => '2014-02-01', + 'to' => '2014-02-28', + ) + + // 'all' can be replaced by 'vod' or 'live' acccording to entry points in docs + $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"; + } + +``` + + VERSIONS --------- diff --git a/Services/Zencoder.php b/Services/Zencoder.php index 6e8447c..7fcf368 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); } /** diff --git a/Services/Zencoder/Report.php b/Services/Zencoder/Report.php new file mode 100644 index 0000000..5bc5af8 --- /dev/null +++ b/Services/Zencoder/Report.php @@ -0,0 +1,51 @@ + + * @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 +{ + /** + * Statistics of a report + * + * @var object + */ + public $statistics; + + /** + * Totals of a of report + * + * @var object + */ + public $total; + + /** + * 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); + } +} diff --git a/Services/Zencoder/Reports.php b/Services/Zencoder/Reports.php new file mode 100644 index 0000000..95b5696 --- /dev/null +++ b/Services/Zencoder/Reports.php @@ -0,0 +1,33 @@ + + * @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 +{ + /** + * 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)); + } +}