Skip to content

Reports api #17

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add access to reports api
  • Loading branch information
Cyril Tata authored and cyriltata committed Jul 8, 2015
commit 3fab4c9c9f0b8a13a15d82c009bcf6ebba50f0f2
114 changes: 114 additions & 0 deletions Services/Zencoder/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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);
}

}
15 changes: 15 additions & 0 deletions Services/Zencoder/Report/LiveStatistic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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
{
}
15 changes: 15 additions & 0 deletions Services/Zencoder/Report/LiveTotal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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
{
}
15 changes: 15 additions & 0 deletions Services/Zencoder/Report/MinutesStatistic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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
{
}
15 changes: 15 additions & 0 deletions Services/Zencoder/Report/MinutesTotal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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
{
}
15 changes: 15 additions & 0 deletions Services/Zencoder/Report/VodStatistic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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
{
}
15 changes: 15 additions & 0 deletions Services/Zencoder/Report/VodTotal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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
{
}
58 changes: 58 additions & 0 deletions Services/Zencoder/Reports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* Zencoder API client interface.
*
* @category Services
* @package Services_Zencoder
* @author Cyril Tata <[email protected]>
* @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);
}

}