|
2 | 2 | import re |
3 | 3 | import sys |
4 | 4 | import json |
| 5 | +import toml |
5 | 6 | import base64 |
| 7 | +import pathlib |
6 | 8 | import pkg_resources |
7 | 9 | import multiprocessing |
8 | 10 | from loguru import logger |
|
15 | 17 | from requests.adapters import HTTPAdapter |
16 | 18 | from concurrent.futures import ThreadPoolExecutor |
17 | 19 |
|
18 | | -if 'unittest' in sys.modules.keys(): |
19 | 20 |
|
20 | | - import toml |
21 | | - import pathlib |
22 | | - |
23 | | - pyproject_text = pathlib.Path('pyproject.toml').read_text() |
24 | | - pyproject_data = toml.loads(pyproject_text) |
| 21 | +pyproject_text = pathlib.Path('pyproject.toml').read_text() |
| 22 | +pyproject_data = toml.loads(pyproject_text) |
25 | 23 |
|
| 24 | +if 'poetry' in pyproject_data['tool']: |
26 | 25 | __version__ = pyproject_data['tool']['poetry']['version'] |
27 | | - |
28 | 26 | else: |
29 | | - |
30 | 27 | __version__ = pkg_resources.get_distribution('botanalytics').version |
31 | 28 |
|
| 29 | + |
32 | 30 | load_dotenv() |
33 | 31 |
|
34 | 32 | ip_middle_octet = u"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))" |
@@ -169,7 +167,7 @@ def __init__(self, debug=None, api_key=None, base_url=None, channel=None, |
169 | 167 |
|
170 | 168 | request_retry_limit = (default_request_retry_limit if os.getenv('BA_REQUEST_RETRY_LIMIT') |
171 | 169 | is None else int(os.getenv('BA_REQUEST_RETRY_LIMIT'))) \ |
172 | | - if 'request_retry_limit' not in kwargs else kwargs['request_retry_limit'] |
| 170 | + if 'request_retry_limit' not in kwargs else int(kwargs['request_retry_limit']) |
173 | 171 |
|
174 | 172 | request_timeout = (default_request_timeout if os.getenv('BA_REQUEST_TIMEOUT') |
175 | 173 | is None else int(os.getenv('BA_REQUEST_TIMEOUT'))) \ |
@@ -274,7 +272,7 @@ def send_messages(self, messages=None): |
274 | 272 |
|
275 | 273 | headers['X-Botanalytics-Client-Version'] = __version__ |
276 | 274 |
|
277 | | - self.http.post('/messages', |
| 275 | + self.http.post('messages', |
278 | 276 | data=request_json, |
279 | 277 | headers=headers, |
280 | 278 | allow_redirects=False, |
@@ -324,11 +322,12 @@ def response_hook(self, response, *args, **kwargs): |
324 | 322 |
|
325 | 323 | try: |
326 | 324 |
|
| 325 | + |
327 | 326 | data = response.json() |
328 | 327 |
|
329 | 328 | # Log request ID if available |
330 | 329 | if 'request_id' in data: |
331 | | - logger.debug('Message(s) successfully sent with the request ID \'%s\'.' % data.request_id) |
| 330 | + logger.debug('Message(s) successfully sent with the request ID \'%s\'.' % data['request_id']) |
332 | 331 |
|
333 | 332 | except: |
334 | 333 |
|
|
0 commit comments