|
1 | 1 | importos
|
2 | 2 | importhttplib2
|
3 | 3 | fromurllibimporturlencode
|
| 4 | +fromdatetimeimportdatetime |
4 | 5 |
|
5 | 6 | LIB_VERSION='0.5.2'
|
6 | 7 |
|
@@ -64,7 +65,7 @@ def headers(self):
|
64 | 65 |
|
65 | 66 | headers= {
|
66 | 67 | 'Content-Type':'application/{0}'.format(content_type),
|
67 |
| -'Accepts':'application/{0}'.format(content_type), |
| 68 | +'Accept':'application/{0}'.format(content_type), |
68 | 69 | 'Zencoder-Api-Key':self.api_key,
|
69 | 70 | 'User-Agent':'zencoder-py v{0}'.format(LIB_VERSION)
|
70 | 71 | }
|
@@ -208,6 +209,9 @@ def __init__(self, api_key=None, api_version=None, as_xml=False, timeout=None, t
|
208 | 209 | self.job=Job(*args,**kwargs)
|
209 | 210 | self.account=Account(*args,**kwargs)
|
210 | 211 | self.output=Output(*args,**kwargs)
|
| 212 | +self.report=None |
| 213 | +ifapi_version=='v2': |
| 214 | +self.report=Report(*args,**kwargs) |
211 | 215 |
|
212 | 216 | classResponse(object):
|
213 | 217 | """
|
@@ -360,3 +364,43 @@ def delete(self, job_id):
|
360 | 364 | """
|
361 | 365 | returnself.cancel(job_id)
|
362 | 366 |
|
| 367 | +classReport(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 | +defminutes(self,start_date=None,end_date=None,grouping=None): |
| 376 | +""" |
| 377 | + Gets a detailed Report of encoded minutes and billable minutes for a |
| 378 | + date range. |
| 379 | +
|
| 380 | + **Warning**: `start_date` and `end_date` must be `datetime.date` objects. |
| 381 | +
|
| 382 | + Example: |
| 383 | + import datetime |
| 384 | + start = datetime.date(2012, 12, 31) |
| 385 | + end = datetime.today() |
| 386 | + data = z.report.minutes(start, end) |
| 387 | +
|
| 388 | + @param start_date: Start date of report (If not submitted, |
| 389 | + API defaults to 30 days ago) |
| 390 | + @param end_date: End date of report (If not submitted, API defaults to |
| 391 | + yesterday) |
| 392 | + @param grouping: Minute usage for only one report grouping |
| 393 | + """ |
| 394 | +data= {'api_key':self.api_key} |
| 395 | +date_format='%Y-%m-%d' |
| 396 | +ifstart_date: |
| 397 | +data['from']=datetime.strftime(start_date,date_format) |
| 398 | + |
| 399 | +ifend_date: |
| 400 | +data['to']=datetime.strftime(end_date,date_format) |
| 401 | + |
| 402 | +ifgrouping: |
| 403 | +data['grouping']=grouping |
| 404 | + |
| 405 | +url=self.base_url+'/minutes' |
| 406 | +returnself.get(url,data=data) |