Skip to content

Commit 47b0600

Browse files
author
Alex Schworer
committed
Merge branch 'master' of https://github.com/mcos/zencoder-py into mcos-master
2 parents e071bf1 + 1566c6c commit 47b0600

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

zencoder/core.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import httplib2
33
from urllib import urlencode
4+
from datetime import datetime
45

56
LIB_VERSION = '0.5.2'
67

@@ -208,6 +209,9 @@ def __init__(self, api_key=None, api_version=None, as_xml=False, timeout=None, t
208209
self.job = Job(*args, **kwargs)
209210
self.account = Account(*args, **kwargs)
210211
self.output = Output(*args, **kwargs)
212+
self.report = None
213+
if api_version == 'v2':
214+
self.report = Report(*args, **kwargs)
211215

212216
class Response(object):
213217
"""
@@ -360,3 +364,34 @@ def delete(self, job_id):
360364
"""
361365
return self.cancel(job_id)
362366

367+
class Report(HTTPBackend):
368+
def __init__(self, *args, **kwargs):
369+
"""
370+
Contains all API methods relating to Reports.
371+
"""
372+
kwargs['resource_name'] = 'reports'
373+
super(Report, self).__init__(*args, **kwargs)
374+
375+
def minutes(self, start_date=None, end_date=None, grouping=None):
376+
"""
377+
Gets a detailed Report of encoded minutes and billable minutes
378+
for a date range
379+
@param start_date: Start date of report (If not submitted,
380+
API defaults to 30 days ago)
381+
@param end_date: End date of report (If not submitted, API defaults to
382+
yesterday)
383+
@param grouping: Minute usage for only one report grouping
384+
"""
385+
data = {'api_key': self.api_key}
386+
date_format = '%Y-%m-%d'
387+
if start_date:
388+
data['from'] = datetime.strftime(start_date, date_format)
389+
390+
if end_date:
391+
data['to'] = datetime.strftime(end_date, date_format)
392+
393+
if grouping:
394+
data['grouping'] = grouping
395+
396+
url = self.base_url + '/minutes'
397+
return self.get(url, data=data)

0 commit comments

Comments
 (0)