Skip to content

Zencoder Reports Wrapper #15

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

Merged
merged 5 commits into from
Apr 5, 2013
Merged
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions zencoder/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import httplib2
from urllib import urlencode
from datetime import datetime

# Note: I've seen this pattern for dealing with json in different versions of
# python in a lot of modules -- if there's a better way, I'd love to use it.
Expand Down Expand Up @@ -202,6 +203,9 @@ def __init__(self, api_key=None, api_version=None, as_xml=False, timeout=None, t
self.job = Job(*args, **kwargs)
self.account = Account(*args, **kwargs)
self.output = Output(*args, **kwargs)
self.report = None
if api_version == 'v2':
self.report = Report(*args, **kwargs)

class Response(object):
"""
Expand Down Expand Up @@ -366,3 +370,34 @@ def delete(self, job_id):
"""
return self.cancel(job_id)

class Report(HTTPBackend):
def __init__(self, *args, **kwargs):
"""
Contains all API methods relating to Reports.
"""
kwargs['resource_name'] = 'reports'
super(Report, self).__init__(*args, **kwargs)

def minutes(self, start_date=None, end_date=None, grouping=None):
"""
Gets a detailed Report of encoded minutes and billable minutes
for a date range
@param start_date: Start date of report (If not submitted,
API defaults to 30 days ago)
@param end_date: End date of report (If not submitted, API defaults to
yesterday)
@param grouping: Minute usage for only one report grouping
"""
data = {'api_key': self.api_key}
date_format = '%Y-%m-%d'
if start_date:
data['from'] = datetime.strftime(start_date, date_format)

if end_date:
data['to'] = datetime.strftime(end_date, date_format)

if grouping:
data['grouping'] = grouping

url = self.base_url + '/minutes'
return self.get(url, data=data)