Skip to content

Commit ce99937

Browse files
committed
heroku region support
1 parent dacf7e4 commit ce99937

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎stream/__init__.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__copyright__ = 'Copyright 2014, Thierry Schellenbach'
66
__credits__ = ['Thierry Schellenbach, mellowmorning.com, @tschellenbach']
77
__license__ = 'BSD'
8-
__version__ = '2.1.0'
8+
__version__ = '2.1.2'
99
__maintainer__ = 'Thierry Schellenbach'
1010
__email__ = 'thierryschellenbach@gmail.com'
1111
__status__ = 'Production'
@@ -24,10 +24,11 @@ def connect(api_key=None, api_secret=None, app_id=None, version='v1.0', timeout=
2424
# support for the heroku STREAM_URL syntax
2525
if stream_url and not api_key:
2626
pattern = re.compile(
27-
'https\:\/\/(\w+)\:(\w+).*app_id=(\d+)', re.IGNORECASE)
27+
'https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)', re.IGNORECASE)
2828
result = pattern.match(stream_url)
29-
if result and len(result.groups()) == 3:
30-
api_key, api_secret, app_id = result.groups()
29+
if result and len(result.groups()) == 4:
30+
api_key, api_secret, location, app_id = result.groups()
31+
location = None if location == 'getstream' else location
3132
else:
3233
raise ValueError('Invalid api key or heroku url')
3334

‎stream/tests.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,27 @@ def test_heroku(self):
5555
self.assertEqual(client.api_secret, 'pass')
5656
self.assertEqual(client.app_id, '1')
5757

58-
def test_heroku_real(self):
58+
def test_heroku_no_location(self):
5959
url = 'https://bvt88g4kvc63:twc5ywfste5bm2ngqkzs7ukxk3pn96yweghjrxcmcrarnt3j4dqj3tucbhym5wfd@getstream.io/?app_id=669'
6060
os.environ['STREAM_URL'] = url
6161
client = stream.connect()
6262
self.assertEqual(client.api_key, 'bvt88g4kvc63')
6363
self.assertEqual(
6464
client.api_secret, 'twc5ywfste5bm2ngqkzs7ukxk3pn96yweghjrxcmcrarnt3j4dqj3tucbhym5wfd')
6565
self.assertEqual(client.app_id, '669')
66+
self.assertEqual(
67+
client.base_url, 'https://api.getstream.io/api/')
68+
69+
def test_heroku_location(self):
70+
url = 'https://ahj2ndz7gsan:gthc2t9gh7pzq52f6cky8w4r4up9dr6rju9w3fjgmkv6cdvvav2ufe5fv7e2r9qy@us-east.getstream.io/?app_id=1'
71+
os.environ['STREAM_URL'] = url
72+
client = stream.connect()
73+
self.assertEqual(client.api_key, 'ahj2ndz7gsan')
74+
self.assertEqual(
75+
client.api_secret, 'gthc2t9gh7pzq52f6cky8w4r4up9dr6rju9w3fjgmkv6cdvvav2ufe5fv7e2r9qy')
76+
self.assertEqual(
77+
client.base_url, 'https://us-east-api.getstream.io/api/')
78+
self.assertEqual(client.app_id, '1')
6679

6780
def test_heroku_overwrite(self):
6881
url = 'https://thierry:pass@getstream.io/?app_id=1'

0 commit comments

Comments
 (0)