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 3857ef2

Browse filesBrowse files
author
Alex Schworer
committed
Enable base_url in Zencoder constructor.
1 parent bf1597e commit 3857ef2
Copy full SHA for 3857ef2

File tree

2 files changed

+25
-5
lines changed
Filter options

2 files changed

+25
-5
lines changed

‎test/test_zencoder.py

Copy file name to clipboardExpand all lines: test/test_zencoder.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import os
33
from zencoder import Zencoder
4+
import zencoder
45

56
class TestZencoder(unittest.TestCase):
67
def setUp(self):
@@ -34,6 +35,16 @@ def test_set_api_edge_version(self):
3435
zc = Zencoder(api_version='edge')
3536
self.assertEquals(zc.base_url, 'https://app.zencoder.com/api/')
3637

38+
def test_set_base_url(self):
39+
os.environ['ZENCODER_API_KEY'] = 'abcd123'
40+
zc = Zencoder(base_url='https://localhost:800/foo/')
41+
self.assertEquals(zc.base_url, 'https://localhost:800/foo/')
42+
43+
def test_set_base_url_and_version_fails(self):
44+
os.environ['ZENCODER_API_KEY'] = 'abcd123'
45+
with self.assertRaises(zencoder.core.ZencoderError):
46+
zc = Zencoder(base_url='https://localhost:800/foo/', api_version='v3')
47+
3748
def test_set_timeout(self):
3849
api_key = 'testapikey'
3950
zc = Zencoder(api_key=api_key, timeout=999)

‎zencoder/core.py

Copy file name to clipboardExpand all lines: zencoder/core.py
+14-5Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,26 @@ class Zencoder(object):
158158
def __init__(self,
159159
api_key=None,
160160
api_version=None,
161+
base_url=None,
161162
timeout=None,
162163
test=False,
163164
proxies=None,
164165
cert=None,
165166
verify=True):
166-
if not api_version:
167-
api_version = 'v2'
168167

169-
self.base_url = 'https://app.zencoder.com/api/'
170-
if not api_version == 'edge':
171-
self.base_url = self.base_url + '%s/' % api_version
168+
if base_url and api_version:
169+
raise ZencoderError('Cannot set both `base_url` and `api_version`.')
170+
171+
if base_url:
172+
self.base_url = base_url
173+
else:
174+
self.base_url = 'https://app.zencoder.com/api/'
175+
176+
if not api_version:
177+
api_version = 'v2'
178+
179+
if api_version != 'edge':
180+
self.base_url = '{0}{1}/'.format(self.base_url, api_version)
172181

173182
if not api_key:
174183
try:

0 commit comments

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