Skip to content

Commit 70c7865

Browse files
committed
reworked heroku support
1 parent 86219d2 commit 70c7865

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎stream/__init__.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import re
1+
import re, os
22

33
__author__ = 'Thierry Schellenbach'
44
__copyright__ = 'Copyright 2012, Thierry Schellenbach'
55
__credits__ = ['Thierry Schellenbach, mellowmorning.com, @tschellenbach']
66
__license__ = 'BSD'
7-
__version__ = '0.2.2'
7+
__version__ = '0.2.3'
88
__maintainer__ = 'Thierry Schellenbach'
99
__email__ = 'thierryschellenbach@gmail.com'
1010
__status__ = 'Production'
1111

1212

13-
def connect(api_key, api_secret=None, site_id=None):
13+
def connect(api_key=None, api_secret=None, site_id=None):
1414
'''
1515
Returns a Client object
1616
@@ -19,11 +19,11 @@ def connect(api_key, api_secret=None, site_id=None):
1919
:param site_id: the site id (used for listening to feed changes)
2020
'''
2121
from stream.client import StreamClient
22-
22+
stream_url = os.environ.get('STREAM_URL')
2323
# support for the heroku STREAM_URL syntax
24-
if api_key.startswith('https'):
24+
if stream_url and not api_key:
2525
pattern = re.compile('https\:\/\/(\w+)\:(\w+).*site=(\d+)', re.IGNORECASE)
26-
result = pattern.match(api_key)
26+
result = pattern.match(stream_url)
2727
if result and len(result.groups())==3:
2828
api_key, api_secret, site_id = result.groups()
2929
else:

‎stream/tests.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from stream.exceptions import ApiKeyException, InputException,\
55
CustomFieldException
66
import random
7-
7+
import os
88

99
def connect_debug():
1010
return stream.connect(
@@ -31,10 +31,19 @@ def setUp(self):
3131

3232
def test_heroku(self):
3333
url = 'https://thierry:pass@getstream.io/?site=1'
34-
client = stream.connect(url)
34+
os.environ['STREAM_URL'] = url
35+
client = stream.connect()
3536
self.assertEqual(client.api_key, 'thierry')
3637
self.assertEqual(client.api_secret, 'pass')
3738
self.assertEqual(client.site_id, '1')
39+
40+
def test_heroku_overwrite(self):
41+
url = 'https://thierry:pass@getstream.io/?site=1'
42+
os.environ['STREAM_URL'] = url
43+
client = stream.connect('a', 'b', 'c')
44+
self.assertEqual(client.api_key, 'a')
45+
self.assertEqual(client.api_secret, 'b')
46+
self.assertEqual(client.site_id, 'c')
3847

3948
def test_add_activity(self):
4049
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}

0 commit comments

Comments
 (0)