|
1 | 1 | import re |
2 | 2 | import os |
3 | 3 |
|
4 | | -__author__ = 'Thierry Schellenbach' |
5 | | -__copyright__ = 'Copyright 2014, Stream.io, Inc' |
6 | | -__credits__ = ['Thierry Schellenbach, mellowmorning.com, @tschellenbach'] |
7 | | -__license__ = 'BSD-3-Clause' |
8 | | -__version__ = '2.12.0' |
9 | | -__maintainer__ = 'Thierry Schellenbach' |
10 | | -__email__ = 'support@getstream.io' |
11 | | -__status__ = 'Production' |
| 4 | +__author__ = "Thierry Schellenbach" |
| 5 | +__copyright__ = "Copyright 2014, Stream.io, Inc" |
| 6 | +__credits__ = ["Thierry Schellenbach, mellowmorning.com, @tschellenbach"] |
| 7 | +__license__ = "BSD-3-Clause" |
| 8 | +__version__ = "2.12.0" |
| 9 | +__maintainer__ = "Thierry Schellenbach" |
| 10 | +__email__ = "support@getstream.io" |
| 11 | +__status__ = "Production" |
12 | 12 |
|
13 | 13 |
|
14 | | -def connect(api_key=None, api_secret=None, app_id=None, version='v1.0', |
15 | | - timeout=3.0, location=None, base_url=None): |
16 | | - ''' |
| 14 | +def connect( |
| 15 | + api_key=None, |
| 16 | + api_secret=None, |
| 17 | + app_id=None, |
| 18 | + version="v1.0", |
| 19 | + timeout=3.0, |
| 20 | + location=None, |
| 21 | + base_url=None, |
| 22 | +): |
| 23 | + """ |
17 | 24 | Returns a Client object |
18 | 25 |
|
19 | 26 | :param api_key: your api key or heroku url |
20 | 27 | :param api_secret: the api secret |
21 | 28 | :param app_id: the app id (used for listening to feed changes) |
22 | | - ''' |
| 29 | + """ |
23 | 30 | from stream.client import StreamClient |
24 | | - stream_url = os.environ.get('STREAM_URL') |
| 31 | + |
| 32 | + stream_url = os.environ.get("STREAM_URL") |
25 | 33 | # support for the heroku STREAM_URL syntax |
26 | 34 | if stream_url and not api_key: |
27 | 35 | pattern = re.compile( |
28 | | - 'https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)', re.IGNORECASE) |
| 36 | + "https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)", re.IGNORECASE |
| 37 | + ) |
29 | 38 | result = pattern.match(stream_url) |
30 | 39 | if result and len(result.groups()) == 4: |
31 | 40 | api_key, api_secret, location, app_id = result.groups() |
32 | | - location = None if location in ('getstream', 'stream-io-api') else location |
| 41 | + location = None if location in ("getstream", "stream-io-api") else location |
33 | 42 | else: |
34 | | - raise ValueError('Invalid api key or heroku url') |
| 43 | + raise ValueError("Invalid api key or heroku url") |
35 | 44 |
|
36 | | - return StreamClient(api_key, api_secret, app_id, version, timeout, |
37 | | - location=location, base_url=base_url) |
| 45 | + return StreamClient( |
| 46 | + api_key, |
| 47 | + api_secret, |
| 48 | + app_id, |
| 49 | + version, |
| 50 | + timeout, |
| 51 | + location=location, |
| 52 | + base_url=base_url, |
| 53 | + ) |
0 commit comments