-
Notifications
You must be signed in to change notification settings - Fork 45
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
Reports api #17
Open
cyriltata
wants to merge
27
commits into
zencoder:master
Choose a base branch
from
cyriltata:reports-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Reports api #17
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f91060d
add access to reports api
7396e99
add reports object to zencoder api
c41ee1b
typo fixes
e433b13
auto-format
6798ce4
update README with reports api
dfe27dc
use doc space format
237615a
update README
efdd4df
Merge pull request #18 from zencoder/remove_ca_cert_bundle
290eb23
Merge pull request #19 from zencoder/remove_ca_cert_bundle
4607c61
Update README.md for formatting
e03988c
Make it so that you can set curl opts for CA paths and files
7673c4b
Bump version to 2.2.1 and add docs
b3046f2
Fixing a bug where api_key was set as api_version in the http connect…
f50a045
Documenting the changes in 2.2.2
e2604c4
Fixed the versions listed in the user agent and throughout the code
3fab4c9
add access to reports api
589c7c5
add reports object to zencoder api
c028c53
typo fixes
bde0dd2
auto-format
c09bf2c
update README with reports api
caee9fb
fix merge conflict
cyriltata 9463c66
fix merge error
cyriltata 7b74562
remove casting to different types of reports
cyriltata bd90317
autoformat
cyriltata 0654a28
update Readme
cyriltata 28b1cfd
autoformat
cyriltata 86c4a2f
format doc code
cyriltata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like support for live reports is in this request - can you add a line for that here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added