@@ -36,12 +36,12 @@ class HTTPBackend(object):
36
36
37
37
@FIXME: Build in support for supplying arbitrary backends
38
38
"""
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 ):
40
40
"""
41
41
Creates an HTTPBackend object, which abstracts out some of the
42
42
library specific HTTP stuff.
43
43
"""
44
- self .base_url = 'https://app.zencoder.com/api/'
44
+ self .base_url = base_url
45
45
if resource_name :
46
46
self .base_url = self .base_url + resource_name
47
47
@@ -135,17 +135,24 @@ def process(self, http_response, content):
135
135
136
136
class Zencoder (object ):
137
137
""" 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 ):
139
139
"""
140
140
Initializes Zencoder. You must have a valid API_KEY.
141
141
142
142
You can pass in the api_key as an argument, or set
143
143
'ZENCODER_API_KEY' as an environment variable, and it will use
144
144
that, if api_key is unspecified.
145
145
146
+ Set api_version='edge' to get the Zencoder development API. (defaults to 'v2')
146
147
Set as_xml=True to get back xml data instead of the default json.
147
148
"""
149
+ if not api_version :
150
+ api_version = 'v2'
151
+
148
152
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
+
149
156
if not api_key :
150
157
try :
151
158
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):
156
163
157
164
self .test = test
158
165
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 )
162
169
163
170
class Response (object ):
164
171
"""
@@ -173,11 +180,11 @@ def __init__(self, code, body, raw_body, raw_response):
173
180
174
181
class Account (HTTPBackend ):
175
182
""" 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 ):
177
184
"""
178
185
Initializes an Account object
179
186
"""
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 )
181
188
182
189
def create (self , email , tos = True , options = None ):
183
190
"""
@@ -216,11 +223,11 @@ def live(self):
216
223
217
224
class Output (HTTPBackend ):
218
225
""" 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 ):
220
227
"""
221
228
Contains all API methods relating to Outputs.
222
229
"""
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 )
224
231
225
232
def progress (self , output_id ):
226
233
"""
@@ -234,11 +241,11 @@ class Job(HTTPBackend):
234
241
"""
235
242
Contains all API methods relating to transcoding Jobs.
236
243
"""
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 ):
238
245
"""
239
246
Initialize a job object
240
247
"""
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 )
242
249
243
250
def create (self , input , outputs = None , options = None ):
244
251
"""
0 commit comments