Skip to content

Commit 52ff131

Browse files
Cyril Tataglensc
authored andcommitted
Add access to reports API
Signed-off-by: Elan Ruusamäe <[email protected]>
1 parent ae8ddf9 commit 52ff131

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
test.php
22
build_docs.sh
33
.DS_Store
4-
4+
/nbproject/

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ $zencoder->jobs->progress($job_id);
8484
$zencoder->inputs->details($input_id);
8585
$zencoder->outputs->details($output_id);
8686
$zencoder->notifications->parseIncoming();
87+
$zencoder->reports->details($report_type, $optional_params);
8788
```
8889

8990
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.
249250

250251
Your [notifications page](https://app.zencoder.com/notifications) will come in handy.
251252

253+
REPORTS
254+
----------------------
255+
The ZencoderReports class is used to get reports over the zencoder api.
256+
See [reports api doc](https://app.zencoder.com/docs/api/reports) for required/optional parameters.
257+
258+
### Get usage for ALL reports
259+
Create a script to get reports for a specified date range
260+
261+
#### Example
262+
```php
263+
264+
// Make sure this points to a copy of Zencoder.php on the same server as this script.
265+
require_once('Services/Zencoder.php');
266+
267+
// Initialize the Services_Zencoder class
268+
$zencoder = new Services_Zencoder('93h630j1dsyshjef620qlkavnmzui3');
269+
270+
// Get reports
271+
$params = array(
272+
'from' => '2014-02-01',
273+
'to' => '2014-02-28',
274+
)
275+
276+
// 'all' can be replaced by 'vod' or 'live' acccording to entry points in docs
277+
$report = $zencoder->reports->details('all', $params);
278+
279+
// Each reports object should have a 'statistics' and 'total' base element
280+
if ($report->statistics) {
281+
foreach ($report->statistics as $statistic) {
282+
print_r($statistic);
283+
}
284+
print_r($report->total);
285+
} else {
286+
echo "no statistics found";
287+
}
288+
289+
```
290+
291+
252292
VERSIONS
253293
---------
254294

Services/Zencoder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ class Services_Zencoder extends Services_Zencoder_Base
8888
* @var Services_Zencoder_Outputs
8989
*/
9090
public $outputs;
91+
/**
92+
* Provides access to the Zencoder Reports API
93+
*
94+
* Valid functions: vod, live, minutes, all
95+
*
96+
* @var Services_Zencoder_Reports
97+
*/
98+
public $reports;
9199

92100
/**
93101
* Initialize the Services_Zencoder class and sub-classes.
@@ -135,6 +143,7 @@ public function __construct(
135143
$this->jobs = new Services_Zencoder_Jobs($this);
136144
$this->notifications = new Services_Zencoder_Notifications($this);
137145
$this->outputs = new Services_Zencoder_Outputs($this);
146+
$this->reports = new Services_Zencoder_Reports($this);
138147
}
139148

140149
/**

Services/Zencoder/Report.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* Zencoder API client interface.
5+
*
6+
* @category Services
7+
* @package Services_Zencoder
8+
* @author Cyril Tata <[email protected]>
9+
* @version Release: 2.1.2
10+
* @license http://creativecommons.org/licenses/MIT/MIT
11+
* @link http://github.com/zencoder/zencoder-php
12+
*/
13+
class Services_Zencoder_Report extends Services_Zencoder_Object
14+
{
15+
/**
16+
* Statistics of a report
17+
*
18+
* @var object
19+
*/
20+
public $statistics;
21+
22+
/**
23+
* Totals of a of report
24+
*
25+
* @var object
26+
*/
27+
public $total;
28+
29+
/**
30+
* A copy of the raw API response for debug purposes
31+
*
32+
* @var mixed
33+
*/
34+
protected $raw_response;
35+
36+
/**
37+
* Create a new Services_Zencoder_Report object.
38+
* For attributes of the various kinds of reports, see
39+
* @link https://app.zencoder.com/docs/api/reports/vod
40+
* @link https://app.zencoder.com/docs/api/reports/live
41+
* @link https://app.zencoder.com/docs/api/reports/all
42+
*
43+
* @param mixed $params API response
44+
* @param string $type The type of statistic we are fetching
45+
*/
46+
public function __construct($params)
47+
{
48+
$this->raw_response = $params;
49+
parent::__construct($params);
50+
}
51+
}

Services/Zencoder/Reports.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* Zencoder API client interface.
5+
*
6+
* @category Services
7+
* @package Services_Zencoder
8+
* @author Cyril Tata <[email protected]>
9+
* @version Release: 2.1.2
10+
* @license http://creativecommons.org/licenses/MIT/MIT
11+
* @link http://github.com/zencoder/zencoder-php
12+
*/
13+
class Services_Zencoder_Reports extends Services_Zencoder_Base
14+
{
15+
/**
16+
* Get details about different types of reports
17+
*
18+
* @link https://app.zencoder.com/docs/api/reports
19+
*
20+
* @param string $report_type The type of report to get. The following are currently supported over the api
21+
* - 'all' : Returns all reports, both VOD and LIVE
22+
* - 'vod' : Returns VOD reports
23+
* - 'live': Return LIVE reports
24+
* @param array $params An associated array of optional query parameters per requested report type
25+
* @param array $opts Optional overrides
26+
*
27+
* @return Services_Zencoder_Report The object representation of the resource
28+
*/
29+
public function details($report_type = 'all', $params = array(), $opts = array())
30+
{
31+
return new Services_Zencoder_Report($this->proxy->retrieveData("reports/$report_type", $params, $opts));
32+
}
33+
}

0 commit comments

Comments
 (0)