Skip to content

Commit 91fd3ec

Browse files
committed
Merge pull request #19 from schworer/inputs-endpoint
Add Inputs support
2 parents dbda8e9 + 0d868c3 commit 91fd3ec

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

test/fixtures/input_details.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"audio_sample_rate": 44100,
3+
"frame_rate": 30,
4+
"job_id": 45497494,
5+
"channels": "2",
6+
"audio_bitrate_in_kbps": 50,
7+
"height": 720,
8+
"audio_codec": "aac",
9+
"duration_in_ms": 5067,
10+
"url": "http://s3.amazonaws.com/zencodertesting/test.mov",
11+
"file_size_in_bytes": 922620,
12+
"width": 1280,
13+
"format": "mpeg4",
14+
"state": "finished",
15+
"total_bitrate_in_kbps": 1452,
16+
"video_bitrate_in_kbps": 1402,
17+
"id": 45475483,
18+
"video_codec": "h264",
19+
"privacy": false
20+
}

test/fixtures/input_progress.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"state": "processing",
3+
"current_event": "Downloading",
4+
"current_event_progress": "32.34567345",
5+
"progress": "45.2353255"
6+
}

test/test_inputs.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
from zencoder import Zencoder
3+
4+
from mock import patch
5+
6+
from test_util import TEST_API_KEY, load_response
7+
from zencoder import Zencoder
8+
9+
class TestInputs(unittest.TestCase):
10+
def setUp(self):
11+
self.zen = Zencoder(api_key=TEST_API_KEY)
12+
13+
@patch("requests.Session.get")
14+
def test_input_details(self, get):
15+
get.return_value = load_response(200, 'fixtures/input_details.json')
16+
17+
resp = self.zen.input.details(15432)
18+
self.assertEquals(resp.code, 200)
19+
self.assertTrue(resp.body['id'] > 0)
20+
21+
@patch("requests.Session.get")
22+
def test_input_progress(self, get):
23+
get.return_value = load_response(200, 'fixtures/input_progress.json')
24+
25+
resp = self.zen.input.progress(14325)
26+
self.assertEquals(resp.code, 200)
27+
self.assertEquals(resp.body['state'], 'processing')
28+
29+
if __name__ == "__main__":
30+
unittest.main()
31+

zencoder/core.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def __init__(self, api_key=None, api_version=None, timeout=None, test=False):
157157
self.job = Job(*args, **kwargs)
158158
self.account = Account(*args, **kwargs)
159159
self.output = Output(*args, **kwargs)
160+
self.input = Input(*args, **kwargs)
160161
self.report = None
161162
if api_version == 'v2':
162163
self.report = Report(*args, **kwargs)
@@ -230,6 +231,27 @@ def details(self, output_id):
230231
"""
231232
return self.get(self.base_url + '/%s' % str(output_id))
232233

234+
class Input(HTTPBackend):
235+
""" Returns information regarding inputs """
236+
def __init__(self, *args, **kwargs):
237+
"""
238+
Contains all API methods relating to Inputs.
239+
"""
240+
kwargs['resource_name'] = 'inputs'
241+
super(Input, self).__init__(*args, **kwargs)
242+
243+
def progress(self, input_id):
244+
"""
245+
Gets the given input id's progress.
246+
"""
247+
return self.get(self.base_url + '/%s/progress' % str(input_id))
248+
249+
def details(self, input_id):
250+
"""
251+
Gets the given input id's details
252+
"""
253+
return self.get(self.base_url + '/%s' % str(input))
254+
233255
class Job(HTTPBackend):
234256
""" Contains all API methods relating to transcoding Jobs. """
235257
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)