Skip to content

Add Inputs support #19

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 4 commits into from
May 22, 2013
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions test/fixtures/input_details.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"audio_sample_rate": 44100,
"frame_rate": 30,
"job_id": 45497494,
"channels": "2",
"audio_bitrate_in_kbps": 50,
"height": 720,
"audio_codec": "aac",
"duration_in_ms": 5067,
"url": "http://s3.amazonaws.com/zencodertesting/test.mov",
"file_size_in_bytes": 922620,
"width": 1280,
"format": "mpeg4",
"state": "finished",
"total_bitrate_in_kbps": 1452,
"video_bitrate_in_kbps": 1402,
"id": 45475483,
"video_codec": "h264",
"privacy": false
}
6 changes: 6 additions & 0 deletions test/fixtures/input_progress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"state": "processing",
"current_event": "Downloading",
"current_event_progress": "32.34567345",
"progress": "45.2353255"
}
31 changes: 31 additions & 0 deletions test/test_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
from zencoder import Zencoder

from mock import patch

from test_util import TEST_API_KEY, load_response
from zencoder import Zencoder

class TestInputs(unittest.TestCase):
def setUp(self):
self.zen = Zencoder(api_key=TEST_API_KEY)

@patch("requests.Session.get")
def test_input_details(self, get):
get.return_value = load_response(200, 'fixtures/input_details.json')

resp = self.zen.input.details(15432)
self.assertEquals(resp.code, 200)
self.assertTrue(resp.body['id'] > 0)

@patch("requests.Session.get")
def test_input_progress(self, get):
get.return_value = load_response(200, 'fixtures/input_progress.json')

resp = self.zen.input.progress(14325)
self.assertEquals(resp.code, 200)
self.assertEquals(resp.body['state'], 'processing')

if __name__ == "__main__":
unittest.main()

22 changes: 22 additions & 0 deletions zencoder/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __init__(self, api_key=None, api_version=None, timeout=None, test=False):
self.job = Job(*args, **kwargs)
self.account = Account(*args, **kwargs)
self.output = Output(*args, **kwargs)
self.input = Input(*args, **kwargs)
self.report = None
if api_version == 'v2':
self.report = Report(*args, **kwargs)
Expand Down Expand Up @@ -230,6 +231,27 @@ def details(self, output_id):
"""
return self.get(self.base_url + '/%s' % str(output_id))

class Input(HTTPBackend):
""" Returns information regarding inputs """
def __init__(self, *args, **kwargs):
"""
Contains all API methods relating to Inputs.
"""
kwargs['resource_name'] = 'inputs'
super(Input, self).__init__(*args, **kwargs)

def progress(self, input_id):
"""
Gets the given input id's progress.
"""
return self.get(self.base_url + '/%s/progress' % str(input_id))

def details(self, input_id):
"""
Gets the given input id's details
"""
return self.get(self.base_url + '/%s' % str(input))

class Job(HTTPBackend):
""" Contains all API methods relating to transcoding Jobs. """
def __init__(self, *args, **kwargs):
Expand Down