Skip to content

Commit c744abf

Browse files
Akop KesheshyanAkop Kesheshyan
authored andcommitted
auto correction of user passed domain
1 parent df9bc58 commit c744abf

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

bitrix24/bitrix24.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
import requests
1313
from time import sleep
14+
from urllib.parse import urlparse
1415
from .exceptions import BitrixError
1516

1617

@@ -27,9 +28,15 @@ class Bitrix24(object):
2728
"""
2829

2930
def __init__(self, domain, timeout=60):
30-
self.domain = domain
31+
self.domain = self._prepare_domain(domain)
3132
self.timeout = timeout
3233

34+
def _prepare_domain(string):
35+
"""Normalize user passed domain to a valid one."""
36+
o = urlparse(string)
37+
user_id, code = o.path.split('/')[2:4]
38+
return "{0}://{1}/rest/{2}/{3}".format(o.scheme, o.netloc, user_id, code)
39+
3340
def _prepare_params(self, params):
3441
"""Transforms list of params to a valid bitrix array."""
3542

0 commit comments

Comments
 (0)