Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 39b9934

Browse filesBrowse files
committed
add support for specifying Zencoder API version
This allows users to set the `api_version` kwarg when creating the Zencoder object. It defaults to 'v2'. Set it to 'edge' to get the Zencoder dev API.
1 parent 544b36d commit 39b9934
Copy full SHA for 39b9934

File tree

1 file changed

+19
-12
lines changed
Filter options

1 file changed

+19
-12
lines changed

‎zencoder/core.py

Copy file name to clipboardExpand all lines: zencoder/core.py
+19-12Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ class HTTPBackend(object):
3636
3737
@FIXME: Build in support for supplying arbitrary backends
3838
"""
39-
def __init__(self, api_key, as_xml=False, resource_name=None, timeout=None, test=False):
39+
def __init__(self, base_url, api_key, as_xml=False, resource_name=None, timeout=None, test=False):
4040
"""
4141
Creates an HTTPBackend object, which abstracts out some of the
4242
library specific HTTP stuff.
4343
"""
44-
self.base_url = 'https://app.zencoder.com/api/'
44+
self.base_url = base_url
4545
if resource_name:
4646
self.base_url = self.base_url + resource_name
4747

@@ -135,17 +135,24 @@ def process(self, http_response, content):
135135

136136
class Zencoder(object):
137137
""" This is the entry point to the Zencoder API """
138-
def __init__(self, api_key=None, as_xml=False, timeout=None, test=False):
138+
def __init__(self, api_key=None, api_version=None, as_xml=False, timeout=None, test=False):
139139
"""
140140
Initializes Zencoder. You must have a valid API_KEY.
141141
142142
You can pass in the api_key as an argument, or set
143143
'ZENCODER_API_KEY' as an environment variable, and it will use
144144
that, if api_key is unspecified.
145145
146+
Set api_version='edge' to get the Zencoder development API. (defaults to 'v2')
146147
Set as_xml=True to get back xml data instead of the default json.
147148
"""
149+
if not api_version:
150+
api_version = 'v2'
151+
148152
self.base_url = 'https://app.zencoder.com/api/'
153+
if not api_version == 'edge':
154+
self.base_url = self.base_url + '%s/' % api_version
155+
149156
if not api_key:
150157
try:
151158
self.api_key = os.environ['ZENCODER_API_KEY']
@@ -156,9 +163,9 @@ def __init__(self, api_key=None, as_xml=False, timeout=None, test=False):
156163

157164
self.test = test
158165
self.as_xml = as_xml
159-
self.job = Job(self.api_key, self.as_xml, timeout=timeout, test=self.test)
160-
self.account = Account(self.api_key, self.as_xml, timeout=timeout)
161-
self.output = Output(self.api_key, self.as_xml, timeout=timeout)
166+
self.job = Job(self.base_url, self.api_key, self.as_xml, timeout=timeout, test=self.test)
167+
self.account = Account(self.base_url, self.api_key, self.as_xml, timeout=timeout)
168+
self.output = Output(self.base_url, self.api_key, self.as_xml, timeout=timeout)
162169

163170
class Response(object):
164171
"""
@@ -173,11 +180,11 @@ def __init__(self, code, body, raw_body, raw_response):
173180

174181
class Account(HTTPBackend):
175182
""" Account object """
176-
def __init__(self, api_key=None, as_xml=False, timeout=None):
183+
def __init__(self, base_url, api_key=None, as_xml=False, timeout=None):
177184
"""
178185
Initializes an Account object
179186
"""
180-
super(Account, self).__init__(api_key, as_xml, 'account', timeout=timeout)
187+
super(Account, self).__init__(base_url, api_key, as_xml, 'account', timeout=timeout)
181188

182189
def create(self, email, tos=True, options=None):
183190
"""
@@ -216,11 +223,11 @@ def live(self):
216223

217224
class Output(HTTPBackend):
218225
""" Gets information regarding outputs """
219-
def __init__(self, api_key, as_xml=False, timeout=None):
226+
def __init__(self, base_url, api_key, as_xml=False, timeout=None):
220227
"""
221228
Contains all API methods relating to Outputs.
222229
"""
223-
super(Output, self).__init__(api_key, as_xml, 'outputs', timeout=timeout)
230+
super(Output, self).__init__(base_url, api_key, as_xml, 'outputs', timeout=timeout)
224231

225232
def progress(self, output_id):
226233
"""
@@ -234,11 +241,11 @@ class Job(HTTPBackend):
234241
"""
235242
Contains all API methods relating to transcoding Jobs.
236243
"""
237-
def __init__(self, api_key, as_xml=False, timeout=None, test=False):
244+
def __init__(self, base_url, api_key, as_xml=False, timeout=None, test=False):
238245
"""
239246
Initialize a job object
240247
"""
241-
super(Job, self).__init__(api_key, as_xml, 'jobs', timeout=timeout, test=test)
248+
super(Job, self).__init__(base_url, api_key, as_xml, 'jobs', timeout=timeout, test=test)
242249

243250
def create(self, input, outputs=None, options=None):
244251
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.