Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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
Loading
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
auto-format
  • Loading branch information
Cyril Tata authored and Cyril Tata committed Mar 11, 2014
commit e433b13a08d090ee564898d509116763a5cad15f
175 changes: 87 additions & 88 deletions 175 Services/Zencoder/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
88 changes: 44 additions & 44 deletions 88 Services/Zencoder/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.