diff --git a/test/fixtures/input_details.json b/test/fixtures/input_details.json new file mode 100644 index 0000000..c99d966 --- /dev/null +++ b/test/fixtures/input_details.json @@ -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 +} \ No newline at end of file diff --git a/test/fixtures/input_progress.json b/test/fixtures/input_progress.json new file mode 100644 index 0000000..ccd7e26 --- /dev/null +++ b/test/fixtures/input_progress.json @@ -0,0 +1,6 @@ +{ + "state": "processing", + "current_event": "Downloading", + "current_event_progress": "32.34567345", + "progress": "45.2353255" +} \ No newline at end of file diff --git a/test/test_inputs.py b/test/test_inputs.py new file mode 100644 index 0000000..1ad4d48 --- /dev/null +++ b/test/test_inputs.py @@ -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() + diff --git a/zencoder/core.py b/zencoder/core.py index e34f158..05b911d 100644 --- a/zencoder/core.py +++ b/zencoder/core.py @@ -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) @@ -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):