Skip to content

Commit

Permalink
Enable base_url in Zencoder constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schworer committed Jul 3, 2013
1 parent bf1597e commit 3857ef2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
11 changes: 11 additions & 0 deletions test/test_zencoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import os
from zencoder import Zencoder
import zencoder

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

def test_set_base_url(self):
os.environ['ZENCODER_API_KEY'] = 'abcd123'
zc = Zencoder(base_url='https://localhost:800/foo/')
self.assertEquals(zc.base_url, 'https://localhost:800/foo/')

def test_set_base_url_and_version_fails(self):
os.environ['ZENCODER_API_KEY'] = 'abcd123'
with self.assertRaises(zencoder.core.ZencoderError):
zc = Zencoder(base_url='https://localhost:800/foo/', api_version='v3')

def test_set_timeout(self):
api_key = 'testapikey'
zc = Zencoder(api_key=api_key, timeout=999)
Expand Down
19 changes: 14 additions & 5 deletions zencoder/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,26 @@ class Zencoder(object):
def __init__(self,
api_key=None,
api_version=None,
base_url=None,
timeout=None,
test=False,
proxies=None,
cert=None,
verify=True):
if not api_version:
api_version = 'v2'

self.base_url = 'https://app.zencoder.com/api/'
if not api_version == 'edge':
self.base_url = self.base_url + '%s/' % api_version
if base_url and api_version:
raise ZencoderError('Cannot set both `base_url` and `api_version`.')

if base_url:
self.base_url = base_url
else:
self.base_url = 'https://app.zencoder.com/api/'

if not api_version:
api_version = 'v2'

if api_version != 'edge':
self.base_url = '{0}{1}/'.format(self.base_url, api_version)

if not api_key:
try:
Expand Down

0 comments on commit 3857ef2

Please sign in to comment.